-
-
Notifications
You must be signed in to change notification settings - Fork 947
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
MapStruct errors out when trying to process classes that reference generated code #769
Comments
Hum, MapStruct is only interested in types annotated with |
@gunnarmorling I wouldn't be surprised if this was the same issue as https://groups.google.com/forum/#!topic/mapstruct-users/minP3fHfrU8 I'll get started on a minimum project demonstrating the bug. |
Yes, this sounds very related.
Thanks for creating a mininum reproducer! I hope we can distill an FAQ of
sort from this.
|
@gunnarmorling I've managed to replicate the issue in a minimal project: https://github.com/wouterhund/mapstruck-error-demo Performing a I'm using build-helper-maven-plugin to add an extra sources directory, which does not seem to be picked up by maven-processor-plugin or mapstruct. I'm using build-helper-maven-plugin in my real project, which causes the same problem, but it also happens when just using cxf or jooq code generation. |
Ok, cool, thanks a lot. I'll take a look tomorrow.
|
I happened upon the addCompileSourceRoots configuration option of the maven-processor-plugin which seems to fix this issue, as long as MapStruct is ordered last in the plugins directive. However I wasn't able to find this option in the documentation of maven-processor-plugin. |
Enabling addCompileSourceRoots seems to expose a compiler bug when running incremental compilations (in JDK8U66 at least, with
I'm back to running mapstruct in the compile phase without addCompileSourceRoots |
What you're seeing is not a bug in the JDK, but one in the maven-compiler-plugin. Update that one to 3.5.1 and you should be good. |
That last bit helped a lot, thanks. But when I switched to using the maven-compiler-plugin 3.5.1 with maven-processor-plugin 3.1.0 using addCompileSourceRoots I still got the same exception, which occurs during the Still using maven-compiler-plugin 3.5.1 I switched to using annotationProcessorPaths which seems to work smoothly, dropping the need for maven-processor-plugin. This does mean the generation happens during the compile phase instead of the generate-sources phase, but I can live with that. |
Is this reproduce-able in the demo project you linked above? I don't get it there, also when adding "addCompileSourceRoots". Does it only happen if you don't do a "clean" by any chance? |
Ah yes, seeing it now, when running "mvn install" after "mvn clean install". |
Yes, it only happens when doing an incremental compilation. So |
@agudian, I'm getting this error from the maven-processor-plugin, not the compiler plug-in. I think it's caused by the fact that MapStruct tries to create mapper implementations a second time. After some googling it appears to be a common issue with annotation processors and incremental compilation. It's not quite clear to me how to avoid it at this point (apart from running "mvn clean compile"). |
So one - admittedly hacky - approach is to delete the directory with generated sources yourself, e.g. using the maven-antrun-plugin:
Adding this prior to the maven-processor-plugin configuration makes "mvn compile" work. I suppose, actually maven-processor-plugin should do this deletion itself. |
Is there a reason to prefer maven-processor-plugin over annotationProcessorPaths with a recent maven-compiler-plugin? As a note, seems you can also pass arguments to mapstruct with for example
|
That incremental issue with annotation processors was fixed in maven-compiler-p 3.5.1, but it can't do anything about the same kind of issue in the processor plugin. |
Yes, the main reason for me preferring the maven-processor-plugin in the past was isolation of the processor path. As you say, that's doable with the compiler plug-in itself now. Another smaller advantage is being able to generate mappers (only) via mvn generate-sources instead of doing a full compile, but that's not so critical. Plus, one can achieve the same with the processor plug-in by adding another execution with "proc:only" to the generate-sources phase. I think we just can change the documentation and show usage of the compiler plug-in with "annotationProcessorPaths". @agudian, do you know whether the M2E plug-in already picks up configuration from "annotationProcessorPaths"? I.e. is experience for Eclipse users as good as with the separate plug-in? |
@gunnarmorling I happen to know that it does. I'm using Eclipse and with Window->Preferences->Maven->Annotation Processors enabled everything works extremely smoothly. |
Right, it came with the latest update to m2e-apt. Btw, if you add the following to the
|
Oh, that is awesome. Thanks again.
|
Sent PR #786 for updating the docs. |
Doc update is merged. Thanks, Gunnar! |
Did the original issue ever get fixed? And if so how? |
I am having the same issue at the command line. |
Did you configure your pom like in our documentation? |
Yes,
I may be having a different issue. When mapstuct runs it fails with class not found errors on Groovy classes. So mapstruct is running before any of the Groovy classes exist in the target directory so it can not find them.
Frank
<http://www.west.com/>
… On Feb 20, 2017, at 1:19 PM, Filip Hrisafov ***@***.***> wrote:
Did you configure your pom like in our documentation <http://mapstruct.org/documentation/stable/reference/html/#_apache_maven>?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub <#769 (comment)>, or mute the thread <https://github.com/notifications/unsubscribe-auth/ADVarBO-ixNjQPtE0yRkNrJmIsUidKp5ks5refVIgaJpZM4Hoo-n>.
|
Frank, could you open a new issue, attaching a small example project which
demonstrates the problem? Are you generating your Groovy classes somehow?
|
I'm generating code based on a wsdl file, and with jOOQ. I'd also like to use MapStruct. This works fine when I'm running generate-sources on my project after it has already compiled the other generated code, but when running
mvn clean generate-sources
MapStruct appears to be scanning all of my Java files and errors out because a few files are referencing, at this point, non-existent classes. This happens even if the MapStruct plugin is positioned after the other generation plugins.Here's the relevant section of my pom:
And here is some of the debug output:
(I have replaced sensitive names with
something
)Is it perhaps possible to restrict the packages that MapStruct scans?
The text was updated successfully, but these errors were encountered: