Open garretwilson opened 1 year ago
Actually it's even more complicated than that:
foo-aggregate
and bar-project
from the local repository in ~/.m2
and then open Eclipse, neither project runs annotation processing, and the bar-project
says it can't even find the annotation-processing dependency even though foo-aggregate
is open in the workspace`.mvn clean install
for foo-aggregate
to install the annotation processor to the local repository. But even then the annotation processing does not occur in either project, even after refreshing the projects in Eclipse using m2e.foo-aggregate
and refresh bar-project
, after which bar-project
will start using the annotation processor (apparently from the local Maven repository in ~/.m2
).Upstream JDT APT ignores annotation processors from workspace projects. It's a design decision we have no control over. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=259230 for context.
Please take it up to https://github.com/eclipse-jdt/eclipse.jdt.core/issues
@fbricon, just to clarify the current behavior, if I'm developing an annotation processor in foo-aggregate
in the workspace, and I want to test it in bar-project
, also in the workspace, can I simply close the foo-aggregate
project and then tell Eclipse to recompile bar-project
?
Or will I have to 1) close the foo-aggregate
project, 2) go to the command line and run mvn install
for foo-aggregate
, 3) come back and refresh bar-project
in Eclipse, and then finally 4) tell Eclipse to recompile bar-project
?
IIRC, you need to mvn install foo-aggregate from CLI, then close it in the workspace, bar-project should automatically pick up the jar in the Maven classpath container. If the JDT APT config was not updated automatically, just run Maven > Update Project
Summary: Projects imported into Eclipse using m2e that use an annotation processor, which is itself defined in other project open in the same workspace, do not invoke the annotation processor when compiling unless the project defining the annotation processor is first closed in the workspace.
I'm using a standard Eclipse EE 2023-09 installation. I have a Maven project that defines an annotation processor, which I have imported into Eclipse using m2e. The processor processes the
@Foo
annotation. The project looks like this:foo-aggregate
: Aggregate project.foo-processor
: Implements theFooProcessor
annotation processor.foo-processor-provider
: Includes theMETA-INF/services/javax.annotation.processing.Processor
files so that the annotation processor can be automatically detected. (If this were in the same project as the processor,javac
would issues aBad service configuration file …
error, because it would try to process the same project with the same processor when the processor has not yet been compiled.) Hasfoo-processor
as a dependency.test-project
: Simply adds the@Foo
processor to one of the classes, and indicatesfoo-processor-provider
as a dependency.The processor so far is pretty bare-bones:
Now if I run
mvn clean compile
onfoo-aggregate
, when maven compiles thetest-project
subproject I hear a beep and Maven prints:This is as I would expect.
In Eclipse, I have found that there is a Preferences > Maven > Annotation Processing > Select Annotation Processing Mode setting which by default is set to "Do not automatically configure/execute annotation processing from pom.xml". I have changed this to "Automatically configure JDT API …". So we should be all set.
However when I import the
foo-aggregate
project into Eclipse using m2e and compile thetest-project
subproject, I see no annotation processing output in the "Error Log" view tab; nor do I hear a beep.In fact someone noted this six years ago in an answer on Stack Overflow:
So it seems impossible to have a subproject that uses an annotation processing defined in the same multimodule aggregate project that defines the annotation processor in a separate subproject.
But it's worse than that—it's not confined to the same aggregate project. If I create a completely separate
bar-project
that uses the@Foo
annotation and listsfoo-processor-provider
as a dependency in the POM, the same bug appears. I importedbar-project
into the same workspace in Eclipse, and there are still no messages or beep when compilingbar-project
.So I closed the
foo-aggregate
project (making sure I had usedmvn install
from the command line so that the annotation processor would still appear in Maven's local repository), and sure enough—I get two lines of in the Error Log view tab, and I hear a beep! (Note that the lines in the Error Log appear in reverse order in the tab because that's how the tab lists messages.)Why must I close the project in which the annotation processor is defined in order to use it in another project in the same workspace in Eclipse? (This will significantly impede my ability to develop an annotation processor using Eclipse.)
I don't have enough information to even guess if they are related, but I note that this bug and #1501 have similar behavior in that the bug appears or disappears based upon whether a dependency is open in the workspace.