我正在尝试部署一个带有分类器的Maven工件。由于我需要源代码和JAR(我从GWT使用它),所以我想获得artifact-version-classifier.jar
和artifact-version-classifier-sources.jar
。但是,它在编译后的JAR上工作得很好,但是在源文件上就失败了(输出源文件的JAR有一个错误的名称)。
这是我到目前为止的配置:
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>prod</classifier>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>${project.build.finalName}-prod</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<classifier>prod</classifier>
</configuration>
</plugin>
这是mvn deploy
的输出:
Uploading: http://juicebox:8080/archiva/repository/snapshots//ar/com/nubing/afip-connector/1.0-SNAPSHOT/afip-connector-1.0-SNAPSHOT-prod.jar
237K uploaded (afip-connector-1.0-SNAPSHOT-prod.jar)
但是这个名字错了:
Uploading: http://juicebox:8080/archiva/repository/snapshots//ar/com/nubing/afip-connector/1.0-SNAPSHOT/afip-connector-1.0-SNAPSHOT-sources.jar
228K uploaded (afip-connector-1.0-SNAPSHOT-sources.jar)
遗憾的是,源插件不支持使用任意分类器附加源JAR。当附加源工件时,分类器是硬编码的(与源插件的2.1.2版本一样)。
您可以通过让源插件生成JAR但不附加,并使用构建助手插件的附加工件目标附加它来解决这个问题。
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-source-jar</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}-prod-sources.jar</file>
<type>jar</type>
<classifier>prod-sources</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
使用了与prunge相同的解决方法。但这已经没有必要了。这是一个报告的Bug,在2012年6月的2.2版本中修复:只需设置属性<classifier>
。
更多的更新答案,使用源代码和javadoc
<maven.javadoc.version>3.0.1</maven.javadoc.version>
<maven.source.version>3.0.1</maven.source.version>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>${maven.source.version}</version>
<configuration>
<classifier>jre10-sources</classifier>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>${maven.javadoc.version}</version>
<configuration>
<classifier>jre10-javadoc</classifier>
</configuration>
</plugin>