eclipse-jdtls / eclipse-jdt-core-incubator

Eclipse Public License 2.0
8 stars 1 forks source link

maven-compiler-plugin arguments missing when compiling projects with Javac #792

Closed testforstephen closed 1 month ago

testforstephen commented 1 month ago
!ENTRY org.eclipse.jdt.core 4 0 2024-09-04 14:25:15.616
!MESSAGE compilation failed
!STACK 0
com.sun.tools.javac.processing.AnnotationProcessingError: java.lang.IllegalArgumentException: 'tlibVersion' is missing
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1033)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.discoverAndRunProcs(JavacProcessingEnvironment.java:937)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$Round.run(JavacProcessingEnvironment.java:1265)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.doProcessing(JavacProcessingEnvironment.java:1378)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.processAnnotations(JavaCompiler.java:1271)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:947)
    at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:897)
    at org.eclipse.jdt.internal.javac.JavacCompiler.compile(JavacCompiler.java:162)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:414)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.compile(BatchImageBuilder.java:211)
    at org.eclipse.jdt.internal.core.builder.AbstractImageBuilder.compile(AbstractImageBuilder.java:345)
    at org.eclipse.jdt.internal.core.builder.BatchImageBuilder.build(BatchImageBuilder.java:79)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.buildAll(JavaBuilder.java:286)
    at org.eclipse.jdt.internal.core.builder.JavaBuilder.build(JavaBuilder.java:192)
    at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:1077)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:296)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:352)
    at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:441)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:47)
    at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:444)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:555)
    at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:503)
    at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:585)
    at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:207)
    at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:300)
    at org.eclipse.core.internal.jobs.Worker.run(Worker.java:63)
Caused by: java.lang.IllegalArgumentException: 'tlibVersion' is missing
    at org.apache.struts.annotations.taglib.apt.TagAnnotationProcessor.checkOptions(TagAnnotationProcessor.java:223)
    at org.apache.struts.annotations.taglib.apt.TagAnnotationProcessor.process(TagAnnotationProcessor.java:74)
    at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.callProcessor(JavacProcessingEnvironment.java:1021)
    ... 26 more

The sample project is https://github.com/apache/struts.git. The javac bits failed to compile it due to some annotation processing args missing.

In the original pom.xml, it specifies the arguments as follows:

<plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <compilerArgs>
                                <arg>-Auri=/struts-tags</arg>
                                <arg>-AtlibVersion=${tlib.version}</arg>
                                <arg>-AjspVersion=2.0</arg>
                                <arg>-AshortName=s</arg>
                                <arg>-AdisplayName=Struts Tags</arg>
                                <arg>-AoutFile=${basedir}/target/classes/META-INF/struts-tags.tld</arg>
                                <arg>-Adescription="To make it easier to access dynamic data;
                                    the Apache Struts framework includes a library of custom tags.
                                    The tags interact with the framework's validation and
                                    internationalization features;
                                    to ensure that input is correct and output is localized.
                                    The Struts Tags can be used with JSP FreeMarker or Velocity."</arg>
                                <arg>-AoutTemplatesDir=${basedir}/src/site/resources/tags</arg>
                            </compilerArgs>
                        </configuration>
                        <executions>
                            <execution>
                                <phase>compile</phase>
                                <goals>
                                    <goal>compile</goal>
                                </goals>
                            </execution>
                        </executions>
                    </plugin>

And when m2e imports the projects, it converts these arguments as annotation processing into the setting org.eclipse.jdt.apt.core.prefs.

eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations
org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations
org.eclipse.jdt.apt.processorOptions/description="To make it easier to access dynamic data;\n                                    the Apache Struts framework includes a library of custom tags.\n                                    The tags interact with the framework's validation and\n                                    internationalization features;\n                                    to ensure that input is correct and output is localized.\n                                    The Struts Tags can be used with JSP FreeMarker or Velocity."
org.eclipse.jdt.apt.processorOptions/displayName=Struts Tags
org.eclipse.jdt.apt.processorOptions/jspVersion=2.0
org.eclipse.jdt.apt.processorOptions/outFile=...\\struts\\core/target/classes/META-INF/struts-tags.tld
org.eclipse.jdt.apt.processorOptions/outTemplatesDir=...\\struts\\core/src/site/resources/tags
org.eclipse.jdt.apt.processorOptions/shortName=s
org.eclipse.jdt.apt.processorOptions/tlibVersion=6.0
org.eclipse.jdt.apt.processorOptions/uri=/struts-tags

Lastly, when javac compiler compile the projects, it does not pick such ap arguments.

mickaelistria commented 1 month ago

JavacUtils.configureOptions() is definitely missing instructions to read project's org.eclipse.jdt.apt.processorOptions and turn those into -Akey=value pairs.

testforstephen commented 1 month ago

Since these processor options are persisted by apt.core plugin, and Javac plugin does not have dependency on apt plugin, we need to modify the upstream ImageBuilder interface (like what we have done to support alternative compiler) to get them. For example, make the ImageBuilder to prepare processor options from the APT participant and transfer them to the downside Compiler.

mickaelistria commented 1 month ago

Since these processor options are persisted by apt.core plugin, and Javac plugin does not have dependency on apt plugin

Note that in principle, it would be fine to have the javac plugin requiring apt one, but I don't think it's technically possible, dependency already exist the other way round. Those options seem to be plain preferences/options, it should be possible to just access project preferences directly through using new ProjectScope(project).getNode(....).