我想实现以下我在 gradle 中使用 maven 所做的事情:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<executions>
<!-- 1. Exclude Default Compiler -->
<execution>
<id>default-compile</id>
<phase>none</phase>
</execution>
<!-- 2. Compile without Mappers. -->
<execution>
<id>Compile without Mappers</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<excludes>
<exclude>**/**/mapper/**/*</exclude>
</excludes>
</configuration>
</execution>
<execution>
<!-- 3. Compile Mappers -->
<id>Compile Mappers</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<includes>
<include>**/**/mapper/**/*</include>
<include>${project.build.directory}/classes/**/*</include>
</includes>
<annotationProcessors>
<processor>org.mapstruct.ap.MappingProcessor</processor>
</annotationProcessors>
</configuration>
</execution>
</executions>
</plugin>
我正在做的是禁用默认编译,编译除我的 Mapstruct 映射器之外的所有源文件,然后编译 Mapstruct 映射器,包括之前编译的源。我是 gradle 新手,不知道如何实现类似的目标。到目前为止,我尝试过的是:
task compileWithoutMapperClasses(type: JavaCompile) {
options.incremental = true
// Compile without Mappers
sourceSets.main.java.exclude '**/**/mapper/**/*'
}
task compileMapperClasses(type: JavaCompile) {
sourceSets.main.java.include '**/**/mapper/**/*'
sourceSets.main.java.include 'build/classes/**/*'
options.define(
compilerArgs: [
"-nowarn",
"-proc:only",
"-encoding", "UTF-8",
"-processor", "org.mapstruct.ap.MappingProcessor",
]
);
}
compileMapperClasses.dependsOn compileWithoutMapperClasses
compileJava.dependsOn compileWithoutMapperClasses
结果实际上是什么都没有编译。我想这样做的原因是我想在我的项目中使用 lombok 和 mapstruct。