Skip to content

Commit 5b082a2

Browse files
ctruedenclaude
andcommitted
Discover annotation processors in modular projects
When compiling a module, maven-compiler-plugin puts the module's requirements on the module path, where javac does not search for annotation processors. As a result, processors such as the SciJava plugin indexer silently stopped running, unless each project listed them explicitly in annotationProcessorPaths. The new jpms-annotation-processing profile, activated by the presence of src/main/java/module-info.java, also appends all dependencies to javac's class path, restoring the non-modular processor discovery. Projects that declare their own annotationProcessorPaths are unaffected, since javac then uses only those processors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 0c55d22 commit 5b082a2

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

‎pom.xml‎

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,6 +2088,79 @@
20882088
</properties>
20892089
</profile>
20902090

2091+
<!--
2092+
The jpms-annotation-processing profile keeps annotation processors (e.g.
2093+
the SciJava plugin indexer) working for modular projects. It turns on
2094+
automatically when a src/main/java/module-info.java file is present.
2095+
2096+
When no processor path is given, javac discovers annotation processors on
2097+
the class path. But when compiling a module, maven-compiler-plugin puts
2098+
the module's requirements on the module path instead, so processors in
2099+
those dependencies are never found. This profile appends all dependencies
2100+
to javac's class path too, restoring the non-modular discovery behavior.
2101+
Code in the module still cannot see anything it does not require.
2102+
2103+
As before, if a project declares its own annotationProcessorPaths, javac
2104+
uses only those processors and does not search the class path.
2105+
-->
2106+
<profile>
2107+
<id>jpms-annotation-processing</id>
2108+
<activation>
2109+
<file>
2110+
<exists>${basedir}/src/main/java/module-info.java</exists>
2111+
</file>
2112+
</activation>
2113+
<build>
2114+
<plugins>
2115+
<plugin>
2116+
<artifactId>maven-dependency-plugin</artifactId>
2117+
<executions>
2118+
<execution>
2119+
<id>jpms-processor-classpath</id>
2120+
<phase>generate-sources</phase>
2121+
<goals>
2122+
<goal>build-classpath</goal>
2123+
</goals>
2124+
<configuration>
2125+
<includeScope>compile</includeScope>
2126+
<outputProperty>scijava.jpms.compile.classpath</outputProperty>
2127+
</configuration>
2128+
</execution>
2129+
<execution>
2130+
<id>jpms-processor-test-classpath</id>
2131+
<phase>generate-test-sources</phase>
2132+
<goals>
2133+
<goal>build-classpath</goal>
2134+
</goals>
2135+
<configuration>
2136+
<includeScope>test</includeScope>
2137+
<outputProperty>scijava.jpms.test.classpath</outputProperty>
2138+
</configuration>
2139+
</execution>
2140+
</executions>
2141+
</plugin>
2142+
<plugin>
2143+
<artifactId>maven-compiler-plugin</artifactId>
2144+
<configuration>
2145+
<!--
2146+
NB: This -classpath comes after the one maven-compiler-plugin
2147+
generates, so javac uses it instead; hence it must also include
2148+
the output directories. The compilerArguments map is used rather
2149+
than the compilerArgs list because maps merge by key, whereas a
2150+
project's own compilerArgs would replace these list entries.
2151+
-->
2152+
<compilerArguments>
2153+
<classpath>${project.build.outputDirectory}${path.separator}${scijava.jpms.compile.classpath}</classpath>
2154+
</compilerArguments>
2155+
<testCompilerArguments>
2156+
<classpath>${project.build.testOutputDirectory}${path.separator}${project.build.outputDirectory}${path.separator}${scijava.jpms.test.classpath}</classpath>
2157+
</testCompilerArguments>
2158+
</configuration>
2159+
</plugin>
2160+
</plugins>
2161+
</build>
2162+
</profile>
2163+
20912164
<!--
20922165
The following profiles set the scijava.platform system properties to
20932166
match the detected architecture. The main intended use case is for

0 commit comments

Comments
 (0)