[ 
https://issues.apache.org/jira/browse/MCOMPILER-589?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Eric Hubert updated MCOMPILER-589:
----------------------------------
    Description: 
After upgrading the used maven-compiler-plugin from 3.11.0 to 3.13.0 the class 
compilation fails, because generated resources are no longer present in the 
generated-sources folder.

The project is setup in a way that during the generate-sources phase a plugin 
generates java sources which are stored in the configured generated-sources 
folder. Within the same phase these are added to the source using the 
build-helper-maven-plugin's add-source goal.

When debugging the maven execution one can verify how the files are generated 
and placed in the correct folder. Once the maven-compiler-plugin > 3.11.0 is 
executed, the generated sources are deleted before the actual source code is 
compiled finally resulting in a compilation error. The issue can be reproduced 
with 3.12.1 and 3.12.0 and does not happen with 3.11.0.

I did not yet find the time to debug the plugin, but briefly checked the 
release notes and found the ticket MCOMPILER-333 which might be the cause.

Update: I now disabled incremental compilation by adding
{code}
-Dmaven.compiler.useIncrementalCompilation=false
{code}
on the command line to the Maven execution and all compiles fine and the 
generated-sources are used as expected. I think this way I put more evidence 
towards the changeset of MCOMPILER-333 to be the cause (therefore linking the 
ticket).

I now also had a glance at the source code and have to admit that I do not 
really understand the reasoning of this change introducing an unconditional 
deletion of all files under generated-sources for incremental compilation 
(which active by default). The generated source are usually generated for a 
reason and must be processed during compilation. I'd expect this to break many 
use cases. What do I overlook here?
{code}
            // MCOMPILER-333: Cleanup the generated source files created by 
annotation processing
            // to avoid issues with `javac` compiler when the source code is 
rebuild.
            if (getGeneratedSourcesDirectory() != null) {
                try (Stream<Path> walk =
                        Files.walk(getGeneratedSourcesDirectory().toPath())) {
                    
walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
                    // MCOMPILER-567: The directory must already exist because 
javac does not create it.
                    
Files.createDirectories(getGeneratedSourcesDirectory().toPath());
                } catch (IOException ex) {
                    getLog().warn("I/O error deleting the annotation processing 
generated files: " + ex.getMessage());
                }
            }
{code}

  was:
After upgrading the used maven-compiler-plugin from 3.11.0 to 3.13.0 the class 
compilation fails, because generated resources are no longer present in the 
generated-sources folder.

The project is setup in a way that during the generate-sources phase a plugin 
generates java sources which are stored in the configured generated-sources 
folder. Within the same phase these are added to the source using the 
build-helper-maven-plugin's add-source goal.

When debugging the maven execution one can verify how the files are generated 
and placed in the correct folder. Once the maven-compiler-plugin > 3.11.0 is 
executed, the generated sources are deleted before the actual source code is 
compiled finally resulting in a compilation error. The issue can be reproduced 
with 3.12.1 and 3.12.0 and does not happen with 3.11.0.

I did not yet find the time to debug the plugin, but briefly checked the 
release notes and found the ticket MCOMPILER-333 which might be the cause.

Update: I now disabled incremental compilation by adding
{code}
-Dmaven.compiler.useIncrementalCompilation=false
{code}
on the command line to the Maven execution and all compiles fine and the 
generated-sources are used as expected. I think this way I put more evidence 
towards the changeset of MCOMPILER-333 to be the cause (therefore linking the 
ticket).


> Compilation fails due to removed generated-sources after upgrade from 3.11.0 
> to 3.12.0+
> ---------------------------------------------------------------------------------------
>
>                 Key: MCOMPILER-589
>                 URL: https://issues.apache.org/jira/browse/MCOMPILER-589
>             Project: Maven Compiler Plugin
>          Issue Type: Bug
>    Affects Versions: 3.12.0, 3.12.1, 3.13.0
>            Reporter: Eric Hubert
>            Priority: Major
>
> After upgrading the used maven-compiler-plugin from 3.11.0 to 3.13.0 the 
> class compilation fails, because generated resources are no longer present in 
> the generated-sources folder.
> The project is setup in a way that during the generate-sources phase a plugin 
> generates java sources which are stored in the configured generated-sources 
> folder. Within the same phase these are added to the source using the 
> build-helper-maven-plugin's add-source goal.
> When debugging the maven execution one can verify how the files are generated 
> and placed in the correct folder. Once the maven-compiler-plugin > 3.11.0 is 
> executed, the generated sources are deleted before the actual source code is 
> compiled finally resulting in a compilation error. The issue can be 
> reproduced with 3.12.1 and 3.12.0 and does not happen with 3.11.0.
> I did not yet find the time to debug the plugin, but briefly checked the 
> release notes and found the ticket MCOMPILER-333 which might be the cause.
> Update: I now disabled incremental compilation by adding
> {code}
> -Dmaven.compiler.useIncrementalCompilation=false
> {code}
> on the command line to the Maven execution and all compiles fine and the 
> generated-sources are used as expected. I think this way I put more evidence 
> towards the changeset of MCOMPILER-333 to be the cause (therefore linking the 
> ticket).
> I now also had a glance at the source code and have to admit that I do not 
> really understand the reasoning of this change introducing an unconditional 
> deletion of all files under generated-sources for incremental compilation 
> (which active by default). The generated source are usually generated for a 
> reason and must be processed during compilation. I'd expect this to break 
> many use cases. What do I overlook here?
> {code}
>             // MCOMPILER-333: Cleanup the generated source files created by 
> annotation processing
>             // to avoid issues with `javac` compiler when the source code is 
> rebuild.
>             if (getGeneratedSourcesDirectory() != null) {
>                 try (Stream<Path> walk =
>                         Files.walk(getGeneratedSourcesDirectory().toPath())) {
>                     
> walk.sorted(Comparator.reverseOrder()).map(Path::toFile).forEach(File::delete);
>                     // MCOMPILER-567: The directory must already exist 
> because javac does not create it.
>                     
> Files.createDirectories(getGeneratedSourcesDirectory().toPath());
>                 } catch (IOException ex) {
>                     getLog().warn("I/O error deleting the annotation 
> processing generated files: " + ex.getMessage());
>                 }
>             }
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to