Maven部署+源分类器

时间:2011-12-14 03:46:36

标签: maven maven-source-plugin

我正在尝试使用分类器部署Maven工件。由于我需要源和JAR(我在GWT中使用它),我想得到artifact-version-classifier.jarartifact-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)

3 个答案:

答案 0 :(得分:7)

遗憾的是,源插件不支持使用任意分类器附加源JAR。当源工件为attached时,分类器为hardcoded(从源插件的2.1.2版开始)。

您可以通过获取源插件来生成JAR但不附加来解决此问题,并将其附加到build helper pluginattach artifact目标。

<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>

答案 1 :(得分:4)

使用与prunge相同的解决方法。但那不再是必要的了。这是2012年6月在2.2版中修复的reported Bug:只需设置属性<classifier>即可。测试2.2.1。

答案 2 :(得分:0)

使用源代码和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>