maven : deploy artifact file name

jayunit100 picture jayunit100 · Jun 10, 2013 · Viewed 21.1k times · Source

Hi : Im finding that maven deploys by default change the file name to match the version+artifact id. For example

Deploying a jar file, with artifact=A and version=V-0.1 will result in a jar file named AV-0.1.jar.

Is there a way to change the default name of the jar file in the deployment, so that it doesnt concatenate these feilds or to specify the final deployed jar name explicitly?

Answer

mglauche picture mglauche · May 30, 2014

Complex answer to that: Yes

It is a bit tricky and you need to be careful, as the pom won't get re-written. So only the maven remote repository (artifactory, or nexus) will put it into the correct folder structure.

If you overwrite the deploy-file goal in the maven deploy goal, you can overwrite the parameters: http://maven.apache.org/plugins/maven-deploy-plugin/deploy-file-mojo.html

One example which would always post version 4.5.1 to nexus would look like this:

        <plugin>
            <artifactId>maven-deploy-plugin</artifactId>
            <executions>
                <execution>
                    <goals>
                        <goal>deploy-file</goal>
                    </goals>
                    <phase>deploy</phase>
                    <configuration>
                        <repositoryId>nexus-site</repositoryId>
                        <url>http://nexus.some.where/nexus-2/content/repositories/releases</url>
                        <file>${build.directory}/${project.build.finalName}.${project.packaging}</file>
                        <generatePom>false</generatePom>
                        <pomFile>pom.xml</pomFile>
                        <version>4.5.1</version>
                    </configuration>
                </execution>
            </executions>
        </plugin>

(and before someone asks, one reason to do something like this is to make builds more CI friendly. in CI everything is just a build number, there is not really a "build a release", every checkin does yield a production-ready artifact. So by replacing 4.5.1 with ${BUILD_NUMBER} will leave you with many many releases in your artifact storage ...)