免责声明:我已经解决了这个问题,并且正在记录解决方案,让全世界都知道。
如何*-sources.jar在 maven 中创建和安装包含“delomboked”的源代码?
默认情况下,maven-source-plugin 创建源 jar 而不对源文件进行 delomboking,这会导致依赖库二进制文件的项目抱怨源文件不匹配。
cod*_*het 10
将以下插件配置添加到您的 pom.xml 元素中的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>
Run Code Online (Sandbox Code Playgroud)
lombok-maven-plugin将使您能够对源代码 ( ${project.basedir}/src/main/java)进行 delombok并将其放置在目标目录 ( ${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-source-plugin ,因为您无法在后面指定自定义源目录。jar 任务指向我们自定义的“生成源”并生成标准命名的源 jar。
maven-install-plugin install-file使用目标是因为您不能使用install目标附加罐子。我们可以通过使用install-file分类器为的目标手动安装文件来破解解决方案sources。
我希望这可以帮助那些像我一样在奋斗街上遇到这个问题的人。
以下解决方案基于上面提供的解决方案,但通过使用 build-helper 插件附加生成的 delomboked 源 jar 而不是使用安装文件来改进它。这样做的好处是正常的 maven 安装和部署阶段正确处理生成的文件,就像使用源插件一样。
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.12.0</version>
<executions>
<execution>
<id>delombok-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
<encoding>UTF-8</encoding>
</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.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>attach-delomboked-sources-jar</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}-sources.jar</file>
<type>jar</type>
<classifier>sources</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
940 次 |
| 最近记录: |