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

user171943 picture user171943 · Feb 2, 2016 · Viewed 33.6k times · Source

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?

Answer

Tunaki picture Tunaki · Feb 2, 2016

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.