Maven部署+源分类器 [英] Maven deploy + source classifiers

查看:158
本文介绍了Maven部署+源分类器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用分类器部署Maven工件.由于我同时需要源代码和JAR(我从GWT使用它),因此我想获取artifact-version-classifier.jarartifact-version-classifier-sources.jar.但是,它在已编译的JAR上可以正常工作,但在源上无法使用(输出源JAR名称错误).

I'm trying to deploy a Maven artifact with a classifier. Since I need both the sources and the JAR (I'm using it from GWT), I would like to get artifact-version-classifier.jar and artifact-version-classifier-sources.jar. However, it works fine with the compiled JAR, but fails with the sources (the output sources JAR has a wrong name).

这是我到目前为止的配置:

This is the configuration that I have so far:

<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与任意分类符一起附加.当源工件为

Sadly, attaching a source JAR with an arbitrary classifier is not supported by the source plugin. When the source artifact is attached, the classifier is hardcoded (as of version 2.1.2 of source plugin).

您可以通过获取源插件来生成JAR而不进行附加来解决此问题,并使用

You can work around the issue by getting the source plugin to generate the JAR but not attach, and attach it with the build helper plugin's attach artifact goal.

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

这篇关于Maven部署+源分类器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆