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

Avoid generated-sources clash with MapStruct in codegen #11312

Closed
wants to merge 1 commit into from
Closed

Avoid generated-sources clash with MapStruct in codegen #11312

wants to merge 1 commit into from

Conversation

famod
Copy link
Member

@famod famod commented Aug 10, 2020

Fixes #11253

This avoids recreation attempts of annotation processors like MapStruct that are writing to ${project.build.directory}/generated-sources/annotations by default.
See also: http://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#generatedSourcesDirectory

The additon of ${project.build.directory}/generated-sources by CodeGenMojo seems to make MapStruct (or any other processor) see its own output a second time. This change is preventing this by introducing a disjunct subdirectory.

@boring-cyborg boring-cyborg bot added area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/maven labels Aug 10, 2020
@famod
Copy link
Member Author

famod commented Aug 10, 2020

FTR, there is an alternate approach: #11311

Copy link
Contributor

@gastaldi gastaldi left a comment

Choose a reason for hiding this comment

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

LGTM

@famod
Copy link
Member Author

famod commented Aug 10, 2020

@michalszynkiewicz it would be great if you could have a look at this.

Btw, this PR does not change the unconditional execution of the prepare goal by the dev goal.
I suggest to rethink that. Dev mode might be fast to start in small projects, but it definitely takes its time in larger, multi-module projects which is why any overhead should be avoided, IMHO.

@famod
Copy link
Member Author

famod commented Aug 10, 2020

formatter-maven-plugin seems a bit overzealous at times...

@famod famod added this to the 1.7.1.Final milestone Aug 10, 2020
@gastaldi
Copy link
Contributor

gastaldi commented Aug 10, 2020

Not directly related, but it seems that MapStruct should also generate sources in a disjunct subdirectory, avoiding using the generated-sources directory directly

@famod
Copy link
Member Author

famod commented Aug 10, 2020

@gastaldi It is implicitly using generated-sources/annotations (the default) which should be ok for annotation processors.

Copy link
Member

@gsmet gsmet left a comment

Choose a reason for hiding this comment

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

Let's wait for @aloubyansky and @michalszynkiewicz 's approvals before merging this one.

@gsmet
Copy link
Member

gsmet commented Aug 11, 2020

@famod please don't set older versions. I do it when backporting. Until then it must target master and have the triage/backport? label.

@gsmet gsmet modified the milestones: 1.7.1.Final, 1.8.0 - master Aug 11, 2020
@famod
Copy link
Member Author

famod commented Aug 11, 2020

@gsmet Ok, will do. I actually had a look at the new COMMITTERS.md and was still a bit unsure after that.

@michalszynkiewicz
Copy link
Member

I think the proper fix may be to remove the following line instead, checking it

sourceRegistrar.accept(generatedSourcesDir);

@michalszynkiewicz
Copy link
Member

PR for ^ #11328

@famod
Copy link
Member Author

famod commented Aug 11, 2020

FTR, I left a comment at #11328. Summary: A dedicated subdirectory still seems like the cleanest solution, IHMO.

@famod
Copy link
Member Author

famod commented Aug 11, 2020

With #11328 now merged, this PR has become optional. If we want to make extra sure to avoid clashes it can be merged, otherwise it should be closed.

@michalszynkiewicz
Copy link
Member

On one hand, we are even more separate with changing generated-sources to sth else here, on the other, subdirectories of generated-sources seem to be the standard location for generated sources ;)

@michalszynkiewicz
Copy link
Member

@aloubyansky WDYT?

@aloubyansky
Copy link
Member

I think it makes sense. If you execute package, both test and app sources are generated, right? if they are in the same location, will all of them end up being packaged?

@michalszynkiewicz
Copy link
Member

What we have now in master puts the "normal" generated sources in the tartget/generated-sources dir and the test ones in target/generated-test-sources

The test mojo adds stuff as test compile source root: https://github.com/quarkusio/quarkus/blob/master/devtools/maven/src/main/java/io/quarkus/maven/CodeGenTestMojo.java#L18

While the normal one adds it as a compile source root: https://github.com/quarkusio/quarkus/blob/master/devtools/maven/src/main/java/io/quarkus/maven/CodeGenMojo.java#L62

I don't think the test classes would sneak into user's app.

This PR shouldn't change this behavior

@aloubyansky
Copy link
Member

Then it's your call @michalszynkiewicz

@michalszynkiewicz
Copy link
Member

@famod I will close this PR, we can resurrect it if we have problems in the future.
Thanks a lot for your work on it, it sped up finding the unnecessary sources registration fixed in #11253

@famod
Copy link
Member Author

famod commented Aug 12, 2020

Glad I could help!

@famod famod deleted the issue-11253-codegen-vs-mapstruct branch August 12, 2020 21:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/devtools Issues/PR related to maven, gradle, platform and cli tooling/plugins area/maven
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression in 1.7: Dev mode auto-compile fails in MapStruct with "Attempt to recreate a file for type ..."
5 participants