TL;DR(解释如下)
plugins
中的配置
project.build
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.0.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-to-lombok-build</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>generate-delomboked-sources-jar</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<jar destfile="${project.build.directory}/${project.build.finalName}-sources.jar"
basedir="${project.build.directory}/delombok"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-source-jar</id>
<goals>
<goal>install-file</goal>
</goals>
<phase>install</phase>
<configuration>
<file>${project.build.directory}/${project.build.finalName}-sources.jar</file>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
<classifier>sources</classifier>
<generatePom>true</generatePom>
<pomFile>${project.basedir}/pom.xml</pomFile>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
lombok-maven-plugin
将使您能够删除源代码(
${project.basedir}/src/main/java
)并将其放在目标目录中(
${project.build.directory}/delombok
). 通常这会将代码放在
${project.build.directory}/generated-sources/delombok
文件夹,但由于Intellij会自动考虑此附加源代码,因此在开发库时会出现重复的代码错误,要停止此操作,只需指定一个非默认目标目录(在本例中,仅在
generated-sources
maven-resources-plugin
${project.basedir}/src/main/resources
目录。如果您的项目中有任何其他非标准的资源目录,您应该在此插件的“资源”部分中配置它们。
maven-antrun-plugin
使用而不是maven源插件,因为您不能在后面的中指定自定义源目录。jar任务指向我们自定义的“生成的源”,并生成名为sources jar的标准源。
maven-install-plugin
install-file
使用goal是因为不能使用
install
目标。我们可以通过使用
安装文件
sources
.
我希望这有助于其他人谁是斗争的街道像我是这个问题。