maven-compiler-plugin icon indicating copy to clipboard operation
maven-compiler-plugin copied to clipboard

[MCOMPILER-461] Compile fails when class references a class generated by an annotation processor and module-info.java is present

Open jira-importer opened this issue 4 years ago • 4 comments

Ralph Goers opened MCOMPILER-461 and commented

While trying to convert Log4j-core to a JPMS module I have run into an issue where I have a class that references a class that is generated by Log4j's annotation processor and that class gets an error saying the referenced class cannot be found. However, after the compile fails I can see that the file was generated.

To reproduce: git clone https://github.com/apache/logging-log4j2.git cd logging-log4j2 git checkout module-compile-fails mvn clean install

The compile will fail in log4j-core. Some appear to be errors in javac for which I have opened an issue with openjdk. But if I do "mvn -X clean install" and copy the compile command line and prepend it with javac when it runs I no longer see

[ERROR] /Users/rgoers/projects/apache/logging/log4j/logging-log4j2/log4j-core/src/main/java/org/apache/logging/log4j/core/osgi/Activator.java:[29,44] error: cannot find symbol symbol: class Log4jPlugins location: package org.apache.logging.log4j.core.plugins

which indicates that Maven is somehow causing that.


Affects: 3.8.1

Attachments:

1 votes, 2 watchers

jira-importer avatar Apr 17 '21 22:04 jira-importer

Matt Sicker commented

These error messages don't even help explain what failed, where, why, or really any reason why it failed besides telling me to go fuck myself. What is up with this issue?

jira-importer avatar Jul 11 '21 23:07 jira-importer

Matt Sicker commented

In my scenario, I added a second annotation processor, and based on some inexplicable changes (absolutely nothing in the diff hints at anything useful), I'm getting the old compiler error you discovered here despite all the maven compiler configurations present in master right now. See attached [^wtf] where seemingly innocuous changes are causing a completely unrelated and entirely untouched file to cause the given compile error. Modifying the Activator class to stop referencing the generated class still causes the log4j-core module to fail with a fairly useless stacktrace:

org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project log4j-core: Compilation failure
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:215)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
 at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
 at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
 at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
 at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
 at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
 at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
 at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
 at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
 at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
 at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
 at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke (Method.java:567)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
 at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
 at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)
 Caused by: org.apache.maven.plugin.compiler.CompilationFailureException: Compilation failure
 at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute (AbstractCompilerMojo.java:1224)
 at org.apache.maven.plugin.compiler.CompilerMojo.execute (CompilerMojo.java:187)
 at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo (DefaultBuildPluginManager.java:137)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:210)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:156)
 at org.apache.maven.lifecycle.internal.MojoExecutor.execute (MojoExecutor.java:148)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:117)
 at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject (LifecycleModuleBuilder.java:81)
 at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build (SingleThreadedBuilder.java:56)
 at org.apache.maven.lifecycle.internal.LifecycleStarter.execute (LifecycleStarter.java:128)
 at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:305)
 at org.apache.maven.DefaultMaven.doExecute (DefaultMaven.java:192)
 at org.apache.maven.DefaultMaven.execute (DefaultMaven.java:105)
 at org.apache.maven.cli.MavenCli.execute (MavenCli.java:957)
 at org.apache.maven.cli.MavenCli.doMain (MavenCli.java:289)
 at org.apache.maven.cli.MavenCli.main (MavenCli.java:193)
 at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
 at jdk.internal.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:78)
 at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
 at java.lang.reflect.Method.invoke (Method.java:567)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced (Launcher.java:282)
 at org.codehaus.plexus.classworlds.launcher.Launcher.launch (Launcher.java:225)
 at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode (Launcher.java:406)
 at org.codehaus.plexus.classworlds.launcher.Launcher.main (Launcher.java:347)

jira-importer avatar Jul 11 '21 23:07 jira-importer

Matt Sicker commented

Oh that above useless error appears to be when a compile error is encountered in fork=true mode, the error message doesn't appear to propagate correctly.

jira-importer avatar Jul 24 '21 19:07 jira-importer

Matt Sicker commented

Double-problem caused the lack of error reporting: using forceJavacCompilerUse=true in the configuration prevented errors in an annotation processor from being surfaced. Switching that back to false surfaced a more useful error message. rgoers this might help with your branch as well?

jira-importer avatar Jul 24 '21 23:07 jira-importer