Skip to content
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

Respect CompilerConfiguration.sourceFiles in EclipseJavaCompiler #233

Merged
merged 1 commit into from
Jul 15, 2022

Conversation

famod
Copy link
Contributor

@famod famod commented Jul 14, 2022

Just like JavacCompiler does, to avoid "FilerException: Source file already created" during annotation processing when running mvn without clean after changing code.

Fixes #232


The crucial thing here is that the compiler will run the annotation processors anyway, so it makes no sense to explicitly specify sources generated from the previous run.


Without the change to EclipseJavaCompiler the new IT would fail with:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.10.1:compile (default-compile) on project simple-javac: Compilation failure
[ERROR] /home/famod/proj/plexus-compiler/plexus-compiler-its/target/it/eclipse-compiler-mapstruct/src/main/java/CarMapper.java:[25,18] Internal error in the mapping processor: java.lang.RuntimeException: javax.annotation.processing.FilerException: Source file already exists : CarMapperImpl   at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.createSourceFile(MapperRenderingProcessor.java:59)      at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.writeToSourceFile(MapperRenderingProcessor.java:39)     at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.process(MapperRenderingProcessor.java:29)       at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.process(MapperRenderingProcessor.java:24)       at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:350)        at org.mapstruct.ap.MappingProcessor.processMapperTypeElement(MappingProcessor.java:330)         at org.mapstruct.ap.MappingProcessor.processMapperElements(MappingProcessor.java:279)   at org.mapstruct.ap.MappingProcessor.process(MappingProcessor.java:174)         at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.handleProcessor(RoundDispatcher.java:142)     at org.eclipse.jdt.internal.compiler.apt.dispatch.RoundDispatcher.round(RoundDispatcher.java:124)       at org.eclipse.jdt.internal.compiler.apt.dispatch.BaseAnnotationProcessorManager.processAnnotations(BaseAnnotationProcessorManager.java:172)    at org.eclipse.jdt.internal.compiler.Compiler.processAnnotations(Compiler.java:953)     at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:450)        at org.eclipse.jdt.internal.compiler.Compiler.compile(Compiler.java:426)        at org.eclipse.jdt.internal.compiler.batch.Main.performCompilation(Main.java:4776)      at org.eclipse.jdt.internal.compiler.tool.EclipseCompilerImpl.call(EclipseCompilerImpl.java:100)        at org.eclipse.jdt.internal.compiler.tool.EclipseCompiler$1.call(EclipseCompiler.java:196)      at org.codehaus.plexus.compiler.eclipse.EclipseJavaCompiler.performCompile(EclipseJavaCompiler.java:374)        at org.apache.maven.plugin.compiler.AbstractCompilerMojo.execute(AbstractCompilerMojo.java:1209)        at org.apache.maven.plugin.compiler.CompilerMojo.execute(CompilerMojo.java:198)         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:972)     at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:293)      at org.apache.maven.cli.MavenCli.main(MavenCli.java:196)        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)       at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)     at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)     at java.base/java.lang.reflect.Method.invoke(Method.java:568)   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: javax.annotation.processing.FilerException: Source file already exists : CarMapperImpl         at org.eclipse.jdt.internal.compiler.apt.dispatch.BatchFilerImpl.createSourceFile(BatchFilerImpl.java:149)      at org.mapstruct.ap.internal.processor.MapperRenderingProcessor.createSourceFile(MapperRenderingProcessor.java:56)      ... 41 more

(sorry for the garbled output but that's the way it's printed out by compiler-plugin)

addExtraSources( extraDir, allSources );
}
}
List<String> allSources = Arrays.asList( getSourceFiles( config ) );
Copy link
Contributor Author

@famod famod Jul 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are back to a list; I basically rolled back #230 because it doesn't make sense anymore.

Just like JavacCompiler does, to avoid "FilerException: Source file already created" during annotation processing when running mvn without clean after changing code.
@olamy olamy merged commit f0efd60 into codehaus-plexus:master Jul 15, 2022
@famod famod deleted the ecj-sourceFiles branch July 15, 2022 20:07
@olamy olamy added the bug label Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants