Can I include the mvn deploy:deploy-file in the pom or settings.xml instead of cli goal

好久不见. 提交于 2019-12-04 16:09:37

问题


I need to deploy a custom jar to Artifactory along with the jar generated from my Java project. Currently the only method I can find is through command line goal using:

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>

Is there a way of including this in the pom file? As a plugin or something?


回答1:


Sure. Just define an execution of the maven-deploy-plugin:deploy-file goal bound to the deploy phase, configured with your values. When deploying your project, this execution will be invoked and the JAR will be deployed.

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

Note that you will probably need to add a repositoryId also. This is the server id to map on the <id> under the <server> section of the settings.xml.




回答2:


You can upload custom maven settings.xml to TeamCity, where you must specify distributionManagement and server as stated on this documentation page. After this, if you change your maven build step to use uploaded settings, deployment will be done by simply adding deploy gial to set of executed goals in this step.




回答3:


The Working with Maven section in the Artifactory manual covers this topic in detail, specifically the part about deploying artifacts.
In addition you can watch the screencast about setting Artifactory as a Maven repository.

To deploy build artifacts through Artifactory you must add a distributionManagement element to your project pom file with the URL of a target local repository to which you want to deploy your artifacts. In addition you will need to configure the Artifactory server credentials in your settings.xml file.
Artifactory can help with generating both the distributionManagement snippet and the settings.xml (see more info in the links I provided above).




回答4:


I personally don't think declaring it in POM is a good approach. For example, if you have a multi-module Maven project consisting of children POMs inheriting from parent POM/super POM and the custom jar to upload is contained in only 1 of the child module, then you will have to explicitly declare the configuration in parent POM (since mvn deploy is normally used to execute the superpom) and declare every other child POM to skip the execution of the configuration, which clutters the POM structure.

A better approach would be to write a script, and link it to your run configurations of deploy goal since the deploy:deploy-file goal is at the end of the build lifecycle.



来源:https://stackoverflow.com/questions/35158890/can-i-include-the-mvn-deploydeploy-file-in-the-pom-or-settings-xml-instead-of-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!