简体   繁体   English

如何更改MapStruct生成的* .java文件的位置?

[英]How to change a location of *.java files generated by MapStruct?

I'm using a MapStruct with default configuration. 我正在使用具有默认配置的MapStruct。 Everything works as expected except build implementation (*.java) files location. 除了构建实现(* .java)文件位置之外,一切都按预期工作。 After application build, they are located at build/classes/java... packages with *.class files. 在构建应用程序之后,它们位于build / classes / java ...包含* .class文件的包中。 How to configure MapStruct to avoid such stuff? 如何配置MapStruct以避免这样的东西?

I was searching for a similar problem on MapStruct site, but I hadn`t found anything. 我在MapStruct网站上搜索类似的问题,但我没有找到任何东西。

//build.gradle
dependencies {
    implementation("org.mapstruct:mapstruct-jdk8:1.2.0.Final")
    annotationProcessor("org.mapstruct:mapstruct-processor:1.2.0.Final")
}

You can configure target directory for generated source files using the annotation processor configuration , for example if you want these files in "/src/generated/java" : 您可以使用注释处理器配置为生成的源文件配置目标目录,例如,如果您希望这些文件位于“/ src / generated / java”中:

compileJava {
    options.annotationProcessorPath = configurations.annotationProcessor
    options.setAnnotationProcessorGeneratedSourcesDirectory(file("$projectDir/src/generated/java"))

}

Note you should not commit these generated files under SCM, so don't forget to update your ".gitignore" file (if you use Git) to exclude /src/generated/ folder) 注意,你不应该在SCM下提交这些生成的文件,所以不要忘记更新你的“.gitignore”文件(如果你使用Git)来排除/src/generated/文件夹)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM