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

Add example for mapstruct with Gradle 5 #66

Open
ghost opened this issue May 16, 2019 · 3 comments
Open

Add example for mapstruct with Gradle 5 #66

ghost opened this issue May 16, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented May 16, 2019

The example for Gradle 5 does NOT seem to work with Gradle 5. From the release notes: Release notes Gradle 5 states: Gradle will no longer automatically apply annotation processors that are on the compile classpath — use CompileOptions.annotationProcessorPath instead.
Specifically the "options.compilerArgs = [
'-Amapstruct.suppressGeneratorTimestamp=true" part.

See also my post on StackOverflow: https://stackoverflow.com/questions/56170222/migrating-from-gradle-4-to-5-how-to-get-mapstruct-1-20-final-working-with-it

@ghost
Copy link
Author

ghost commented May 20, 2019

Courtesy of M.Ricciuti on Stack Overflow who supplied me with a very good answer. It works like a charm. Setting the options and where to create the source files was a very nice bonus. Something I was hoping to see in the original Gradle examples as well.

Since latest Gradle version ( >= 4.8 I would say) you can simplify your build script as follows ; you don't need apt plugin anymore, just use annotationProcessor Gradle configuration :

ext{
    mapstructVersion = "1.2.0.Final"
}
dependencies{
    // ...
    // --- Mapstruct ---------------------------------
    compileOnly("org.mapstruct:mapstruct-jdk8:${mapstructVersion}")
    annotationProcessor "org.mapstruct:mapstruct-processor:${mapstructVersion}"
}
compileJava {
    options.annotationProcessorPath = configurations.annotationProcessor

    // if you need to configure mapstruct component model
    options.compilerArgs << "-Amapstruct.defaultComponentModel=spring" 
}

Note: by default, Gradle will generate sources into directory :build/generated/sources/annotationProcessor/java/main

But this is configurable, for example:

compileJava { 
   // ...
   options.setAnnotationProcessorGeneratedSourcesDirectory( file("$projectDir/src/generated/java"))
}

@chris922
Copy link
Member

Hey @bessels , thanks for reporting this issue and providing a possible solution!

Do you like to update the gradle example and provide a PR?

@filiphr
Copy link
Member

filiphr commented May 27, 2019

I think that this is covered by PR #54

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants