From d11fde0b373676b4b9d6cc7e5143f4f29b4131b0 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Thu, 21 Dec 2023 08:32:27 +0700 Subject: [PATCH 1/3] Compile-time weaving requires aspectjrt, not aspectjweaver Aspect-enhanced classes need aspectjrt on the class path. If it is not, the AspectJ Compiler usually complains, either warning or even failing the build, also via AspectJ Maven. The aspectjweaver, however, is for load-time weaving. It is a superset of aspectjrt, but bigger than necessary. Also, the weaver was only test-scoped, but also during normal runtime aspectjrt is necessary. Without it, it can only work by the lucky chance that Spring already depends on aspectjweaver, which is not good dependency management. Each Maven module should be self-consistent. Aspectjrt was a plugin dependency for AJ Maven, which is also superfluous, because aspectjtools already is a superset of aspectjweaver, i.e. it also contains aspectjrt. Hence, aspectjtools is all AJ Maven needs, but the compiled application is who really needs aspectjrt. --- spring-data-jpa/pom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index ea9590bf8e..b39293042a 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -81,9 +81,8 @@ org.aspectj - aspectjweaver + aspectjrt ${aspectj} - test @@ -362,11 +361,6 @@ aspectj-maven-plugin 1.14.0 - - org.aspectj - aspectjrt - ${aspectj} - org.aspectj aspectjtools From 988b3b2cb61f2a8146cf4906ba5337977a07a69e Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Thu, 21 Dec 2023 08:40:39 +0700 Subject: [PATCH 2/3] Get rid of 'forceAjcCompile' workaround and special includes by separation of concerns: Let - Maven Compiler do annotation processing without compilation and - AspectJ Maven compilation of all Java sources and aspects without annotation processing. Actually, we could let AJ Maven do all the work, but it would be difficult to configure everything correctly in JDK 9+, because AJ Maven is incomplete regarding automatically putting everything on the right module paths. so, this separation of concerns saves tedious configuration work. Relates to https://github.com/mojohaus/aspectj-maven-plugin/issues/15. --- spring-data-jpa/pom.xml | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index b39293042a..6889823431 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -356,6 +356,13 @@ + + maven-compiler-plugin + + only + + + org.codehaus.mojo aspectj-maven-plugin @@ -369,32 +376,37 @@ + aspectj-compile compile process-classes + + + + + aspectj-test-compile + + test-compile + + process-test-classes + + + + none + + true true - - true + true org.springframework spring-aspects - - **/domain/support/AuditingEntityListener.java - ${source.level} ${source.level} ${source.level} From d12a20bbe4096a45f468f3c7d941f4cbff5e7c34 Mon Sep 17 00:00:00 2001 From: Alexander Kriegisch Date: Thu, 21 Dec 2023 17:05:39 +0700 Subject: [PATCH 3/3] Make 2 plugins no-ops, if no ANTLR4 action is necessary This is a workaround for the fact that ANTLR4 Maven Plugin always generates source files, even if its input files have not changed, which in turn leads to changed source files and then to unnecessary compilation of same. A similar workaround makes sure that in the same situation Maven Replacer Plugin does not find any files to replace text in, because that would also alter the timestamps of the target files. Maven Build Helper Plugin is used to compare ANTLR4 input and output directories, determining if the latter are up-to-date. If so, the two plugins mentioned above will be fed a dummy directory name, otherwise a real one. Along the way, Maven Replacer was upgraded from 1.4.1 to its last release 1.5.3, before it was retired on Google Code. The upgrade also led to renaming the plugin, probably because the word "plugin" is already in its group ID. But it is, in fact, the same plugin. The upgrade also fixes a bug, enabling the plugin to understand absolute directories, i.e. now we can use ''${project.build.directory}' instead of 'target' as a base directory. Relates to https://github.com/mojohaus/aspectj-maven-plugin/issues/15. --- spring-data-jpa/pom.xml | 57 +++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/spring-data-jpa/pom.xml b/spring-data-jpa/pom.xml index 6889823431..c70089c502 100644 --- a/spring-data-jpa/pom.xml +++ b/spring-data-jpa/pom.xml @@ -317,6 +317,39 @@ + + org.codehaus.mojo + build-helper-maven-plugin + + + + set-antlr4-directory + + uptodate-property + + + validate + + antlr4.dir + antlr4-dummy + antlr4 + + ${project.basedir}/src/main/antlr4 + ${project.build.directory}/generated-sources/antlr4 + + glob + *.g4 + *.interp + + + + + + + org.antlr antlr4-maven-plugin @@ -329,6 +362,8 @@ generate-sources true + + ${project.basedir}/src/main/${antlr4.dir} @@ -336,24 +371,26 @@ com.google.code.maven-replacer-plugin - maven-replacer-plugin - 1.4.1 + replacer + 1.5.3 process-sources replace + + ${project.build.directory}/generated-sources + + + ${antlr4.dir}/**/*.java + + + public class=class,public interface=interface + + - - - target/generated-sources/antlr4/**/*.java - - - public class=class,public interface=interface - -