我可以在pom或settings.xml中包含mvn deploy:deploy-file而不是cli目标

use*_*943 17 teamcity artifactory maven

我需要向Artifactory部署一个自定义jar以及从我的Java项目生成的jar.目前我能找到的唯一方法是通过命令行目标使用:

mvn deploy:deploy-file -DgroupId=<group-id> \
  -DartifactId=<artifact-id> \
  -Dversion=<version> \
  -Dpackaging=<type-of-packaging> \
  -Dfile=<path-to-file> \
  -Durl=<url-of-the-repository-to-deploy>
Run Code Online (Sandbox Code Playgroud)

有没有办法将其包含在pom文件中?作为一个插件还是什么?

Tun*_*aki 15

当然.只需定义maven-deploy-plugin:deploy-file绑定到deploy阶段的目标的执行,并使用您的值进行配置.部署项目时,将调用此执行并部署JAR.

<plugin>
    <artifactId>maven-deploy-plugin</artifactId>
    <version>2.8.2</version>
    <executions>
        <execution>
            <id>deploy-file</id>
            <phase>deploy</phase>
            <goals>
                <goal>deploy-file</goal>
            </goals>
            <configuration>
                <file><!-- path-to-file --></file>
                <url><!-- url-of-the-repository-to-deploy --></url>
                <groupId><!-- group-id --></groupId>
                <artifactId><!-- artifact-id --></artifactId>
                <version><!-- version --></version>
                <packaging><!-- type-of-packaging --></packaging>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

请注意,您可能还需要添加一个repositoryId.这是要映射到<id><server>部分下的服务器ID settings.xml.

  • @ Jean-LouisJouannic不,因为它是在`<execution>`块中定义的,所以你需要执行特定的执行,这不会发生在`mvn deploy:deploy-file`(它创建一个默认的不同执行).如果你想从命令行执行特定的执行,你需要`mvn deploy:deploy-file @ deploy-file`,即`@`配置执行的id,并确保你至少使用Maven 3.3.1([另见](http://stackoverflow.com/q/2192660/1743880)). (4认同)