'maven : deploy artifact file name
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?
Solution 1:[1]
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 ...)
Solution 2:[2]
Simple answer to that is: No.
The problem behind it is if you would change the naming schema it will not be possible to find artifacts in a repository. That's the reason having a fixed naming schema.
Solution 3:[3]
Using curl command line it seems to be possible to feed Nexus with whatever you want.
curl -u<deploymentUser>:<deploymentPassword> --upload-file <someLocalFile> -v http://<nexusServerDNSName>/nexus/content/repositories/<repoPath>/<fileName>
- deploymentUser and deploymentPassword should be taken from ~/.m2/settings.xml.
- someLocalFile is the file you want to deploy (absolute path)
- fileName is an arbitrary name you want to see in the remote repository (you must not follow any naming convension here)
For me it perfectly worked. What is great is that it works without pom.xml.
Update: this answer might be useful for the one who searches how to bypass Maven concept and deploy an arbitrary named file to Nexus. If the question is how to do it using namely Maven, then I would agree with the answer "Not possible".
Solution 4:[4]
mvn deploy:deploy-file -DartifactId=AAA -Dversion=VVV -Dpackaging=jar
The command above will place the file in the following structure.
AAA
-VVV
--AAA_VVV.jar
If you just want to make the name of the created file different between consecutive pushes to the artifactory, you can use -Dpackaging parameter. ie. Set the value to the current timestamp
mvn deploy:deploy-file -DartifactId=AAA -Dversion=VVV -Dpackaging=2017_01_31_01_37.jar
AAA
-VVV
--AAA_VVV.jar
--AAA_VVV2017_01_31_01_37.jar
Solution 5:[5]
I have found a very simple way to solve this problem
mvn versions:set "-DnewVersion=$buildNumber"
this command will change the whole project's pom.xml file's "version" tag. I am using it in a release pipeline in a virtual environment. It won't change our code but can achieve the goal.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Stefan Falk |
Solution 2 | khmarbaise |
Solution 3 | |
Solution 4 | Kagan Coskun |
Solution 5 | penny chan |