We've use mapstruct 1.20.final for approx 1.5 years with various Gradle versions - latest gradle 4.10.2. We want to switch to Gradle 5.4.1, which works with everything except mapstruct. Our working setup was not clean. Hence decided to start over. Old working setup was a hybrid form of the example on Github and the now obsolete setup.
Started again with http://mapstruct.org/news/2013-07-08-using-mapstruct-with-gradle as a base. Have this strong feeling this is NOT compatible with Gradle 5. Release notes Gradle 5 states: Gradle will no longer automatically apply annotation processors that are on the compile classpath — use CompileOptions.annotationProcessorPath instead. Tried to do it as described in https://blog.gradle.org/incremental-compiler-avoidance#about-annotation-processors. This works for 4.10.2. With Gradle 5 this results in the following error: Execution failed for task ':eu.educator.rest:compileJava'. Cannot specify -processorpath or --processor-path via CompileOptions.compilerArgs. Use the CompileOptions.annotationProcessorPath property instead.
我们有一个多项目设置。在项目“ rest”中,经过清理的build.gradle如下所示:
plugins {
    id 'net.ltgt.apt' version '0.21'
}
configurations {
        apt
}
dependencies {
    apt libraries.mapstruct_processor
    compileOnly libraries.mapstruct_processor
}
compileJava {
    options.annotationProcessorPath = configurations.apt
}
在过去1.5天内尝试了多种设置。无法正常工作。因此,如果任何人都可以使用Mapstruct与Gradle 5一起工作,我真的会很感激build.gradle,提示和指针的正常工作。
PS。如何用Gradle 5兼容版本替换以下内容。
tasks.withType(JavaCompile) {
    options.compilerArgs = [
            '-Amapstruct.suppressGeneratorTimestamp=true'
    ]
}
从最新的Gradle版本开始(我说>> 4.8),您可以按以下方式简化构建脚本;您不再需要apt插件,只需使用annotationProcessorGradle配置:
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" 
}
注意:默认情况下,Gradle将生成源到目录:build/generated/sources/annotationProcessor/java/main
但这是可配置的,例如:
compileJava { 
   // ...
   options.setAnnotationProcessorGeneratedSourcesDirectory( file("$projectDir/src/generated/java"))
| 归档时间: | 
 | 
| 查看次数: | 806 次 | 
| 最近记录: |