-
Notifications
You must be signed in to change notification settings - Fork 72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Plugin doesn't detect recompiled files #15
Comments
I currently work around this by setting the |
We now enforce the AspectJ plugin to run no matter what to work around bugs in the plugin in combination with bugs in the compiler plugin. mojohaus/aspectj-maven-plugin#15 https://issues.apache.org/jira/browse/MCOMPILER-205 https://issues.apache.org/jira/browse/MCOMPILER-209
We now enforce the AspectJ plugin to run no matter what to work around bugs in the plugin in combination with bugs in the compiler plugin. mojohaus/aspectj-maven-plugin#15 https://issues.apache.org/jira/browse/MCOMPILER-205 https://issues.apache.org/jira/browse/MCOMPILER-209
I tried to set forceAjcCompile property to true,but it still doesn't work,do you have any other way to solve the problem |
@odrotbohm sorry for the late answer. Does it still apply? aspectj-maven-plugin/src/main/java/org/codehaus/mojo/aspectj/AbstractAjcCompiler.java Lines 764 to 792 in a544b65
That is odd: if (!forceAjcCompile && !isBuildNeeded()) {
getLog().info("No modifications found skipping aspectJ compile");
return;
} |
We now enforce the AspectJ plugin to run no matter what to work around bugs in the plugin in combination with bugs in the compiler plugin. mojohaus/aspectj-maven-plugin#15 https://issues.apache.org/jira/browse/MCOMPILER-205 https://issues.apache.org/jira/browse/MCOMPILER-209
Seeing the same issue with maven-aspectj-plugin 1.14.0 and maven-compiler-plugin 3.11.0.
Maven re-compiles the classes that need to be weaved but weaving does not happen. The |
I cannot confirm that this happens. Neither does Maven Compiler always recompile all source files, nor do aspects not get applied after a recompile, at least not in a simple single-module test project:
A minimal reproducer project would be helpful. BTW, is there anything keeping you from simply deactivating Maven Compiler completely in the modules using AspectJ Maven? AJC is based on ECJ and therefore a full replacement for Javac. Then you would not have this problem in the first place. I am talking about adding something like this: <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<executions>
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<execution>
<id>default-testCompile</id>
<phase>none</phase>
</execution>
</executions>
<configuration>
<source>11</source>
<target>11</target>
</configuration>
</plugin> Of course, if there really was a problem is AJ Maven, this would just be a workaround and we should still investigate the original problem, but for that a reproducer is necessary. |
I think you need two projects:
If you change the 1st project, the 2nd project will be recompiled too because one of its dependencies changed. You'll see such a message for the second project: [EDIT] I am seeing the issue with Maven 3.8.3. |
Sorry @filnet, but when I use a separate project and
Only if instead of So, if this does not even work in Maven Compiler, how is AspectJ Maven expected to react on the dependency change? If it is so easy to reproduce, where is the MCVE? I do not want to keep guessing and using trial & error to reproduce it, before I can even think about analysing and fixing it. |
@kriegaex, I made a small project that reproduces the issue : https://github.com/filnet/maven-aspectj-plugin-issue Steps to reproduce:
You should see that This is the output I get for
|
Yeah, now we are getting there. So the problem is not two projects but rather one multi-module project where module B depends on module A and there are undetected changes in A when building B. Unfortunately, this is not so much a bug, but rather a total lack of functionality in AJ Maven. The plugin simply does not check at all if there have been changes in any dependency class file directories or JARs in the same project. |
I added a quick fix to See also PR filnet/maven-aspectj-plugin-issue#1. The reason why I choose to maintain the AspectJ.dev plugin fork rather than contribute to this one are partly historical in nature and partly because it enables me as the core AspectJ maintainer to add changes without having to debate with Mojohaus maintainers and release versions keeping up with latest AspectJ development. To the Mojohaus team: Feel free to cherry-pick the fix from my fork dev-aspectj/aspectj-maven-plugin@7b8706a or devise a better solution. 🙂 I am not particularly happy with the change, but presently I do not have more time to make it more beautiful. The things I do not like about the code also apply to other parts of the plugin, which I have not refactored in order to keep it more compatible with the Mojohaus version regarding cherry-picks in either direction. |
More exactly, in AbstractAjcCompiler::hasClassPathClassesChanged. Relates to mojohaus/aspectj-maven-plugin#15.
@filnet, would you mind to test with my fix from 3 months ago and report back if it solves the problem for you? I just stumbled across this piece of code again in another context and remembered that back then I got no feedback. @odrotbohm, you as the person who raised the issue are welcome to test, too. |
@odrotbohm, I analysed your problem (which is different from @filnet's example) in my comment on MCOMPILER-194. It really is a Maven Compiler (MC) problem, not an AspectJ Maven (AJM) one, IMO. Even if I deactivate AJM in your project, MC will still falsely recompile everything.
In your project, that seems to be the case, but like I said before, MC does not always do that. Your project uses all kinds of special things that might influence why MC thinks something has changed, e.g. I noticed
AJM looks at changed source files and (since my fix in the snapshot version a few months ago) dependencies. It is not AJM's job to try to find out what MC did by indirectly checking class file timestamps or agree with MC's opinion about whether a recompile is necessary or not. Both MC and AJM look as source files and dependencies independently of each other. What other smart(?) things MC tries to do on top of that, I have no idea ATM. Like I said in Jira, simply make sure that MC and AJM do not fight each other, trying to compile the same source files. If you really want to run both plugins and not e.g. use AJM as a full replacement for MC and deactivate MC's executions, you need to make sure that the sets of classes the two plugins compile are disjoint (i.e. their intersecting set is empty). |
I merged your test project PR and got this error when compiling:
Changed the repository URL to
I am still on Java 8. |
@filnet: FAQ: Why does the plugin not run on my JDK version? Either upgrade your JDK or downgrade your AspectJ version according to the FAQ in my fork's read-me scroll up one paragraph for how to do that im Maven. |
I downgraded AspectJ and the fix seems to work. After modifying project1, project2 is compiled as expected.
|
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 mojohaus/aspectj-maven-plugin#15.
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 mojohaus/aspectj-maven-plugin#15.
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 mojohaus/aspectj-maven-plugin#15. See #3282
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 mojohaus/aspectj-maven-plugin#15. See #3282
While analysing and fixing mojohaus/aspectj-maven-plugin#15, it was helpful to know the value of each of the 4 conditions determining the method's return value.
FYI, AspectJ.dev AspectJ Maven Plugin 1.14 containing the fix for this problem has been released and is available on Maven Central. |
The Maven compiler plugin currently always recompiles sources, even if there have been any changes at all (see these tickets for details). That recompilation however is not recognized by the AspectJ Maven plugin and it just skips AspectJ compilation on subsequent runs.
To reproduce:
See the last line. The plugin skips the compilation step although the compiler plugin has recompiled the code and we end up with classes that haven't got any aspects applied.
The text was updated successfully, but these errors were encountered: