Courtesy of M.Ricciuti who answered my initial ‘Migrating from Gradle 4 to 5. How to get mapstruct 1.20.final working with it’ question.
Could NOT get it to work with the apt plugin but got it working with Gradle’s annotationProcessor.
I would like to have a Gradle ‘generateMappers’ task to generate the mapstruct source files AND display a message when the sources are generated and preferable one which tells me that nothing is generated because it wasn’t needed.
In the old situation we had a generateMappers task which used mapstruct to generate source files AND display a message when the files were created. Now its basically empty.
task generateMappers (type: JavaCompile, dependsOn: compileJava) {
doFirst {
println "\tGenerating mapper classes"
}
doLast {
println "\tMapping classes generated"
}
}
Gradlew -i generateMappers reveals the following.
> Task :eu.myfirm.rest:generateMappers NO-SOURCE
Skipping task ':eu.myfirm.rest:generateMappers' as it has no source files and no previous output files.
:eu.myfirm.rest:generateMappers (Thread[Execution worker for ':' Thread 4,5,main]) completed. Took 0.0 secs.[enter link description here][1]
NOTE: > Task :eu.myfirm.rest:compileJava FROM-CACHE does trigger correctly ONLY when the sources are not there.
By changing the task into ‘task generateMappers {…}’ I ALWAY get a message - even when no new files are generated because nothing has changed in the mappers. Gradlew --info reveals
> Task :eu.myfirm.rest:generateMappers
Custom actions are attached to task ':eu.myfirm.rest:generateMappers'.
Caching disabled for task ':eu.myfirm.rest:generateMappers' because:
Caching has not been enabled for the task
Task ':eu.myfirm.rest:generateMappers' is not up-to-date because:
Task has not declared any outputs despite executing actions.
Generating mapper classes
Mapping classes generated
Its wrong because caching is disabled and I know this is only cosmetic because whether the sources are there or not I will always get this message.
I’ve this feeling I’m on the WRONG track and I somehow have to hook into the annotationProcessor to get the required two messages BUT I also would like to have a seperate ‘generateMappers’ task to call. Any further hints/pointers is greatly appreciated.