How to deploy artifact with maven when i only got the final .jar?
i have a jenkins build-pipeline in which the first job calls mvn clean package to compile and build my java project. The artifact is copied afterwards to a bunch of test-jobs which ensure the quality of my build. The last job in the chain should deploy the artifact to my nexus repository.
My question is now, how to i deploy the file to nexus when i only have the final jar myproject-1.2.0-SNAPSHOT.jar with maven?
I tried
mvn deploy:deploy-file
but this plugin needs to get information about groupId, artifact id, version etc. Which i do not want to know in my deploy-job. Isn't the information stored in the jar itself in some maven files? I just want to say nexus, here is an artifact, take it.
A jar built with Maven contains this information in the META-INF/maven/
directory. There complete pom.xml
file is found under META-INF/maven/[groupId]/[artifactId]/pom.xml
.
So what you can do is write a small program that extracts this information and calls mvn deploy:deploy-file
with the right arguments.
Unfortunately, you have to know the groupId
and artifactId
to get the file, so you can't easily open and parse it. But of course you can get the name of the (only) directory in META-INF/maven
and the name of this directory's (only) subdirectory. It's kind of cumbersome, but it should work.
Note: There is also a pom.properties
file containing the most important information, which is probably easier to parse than the pom.xml
.
Use the pom.xml file you used to generate the jar file. Retain that file as part of artifact and when you need to deploy manually, you can use it
This seems all backwards to me. I would change the flow around to
mvn clean deploy
to get the library deployed to the repository manager (Nexus or so) or the local repository (less ideal in case you have multiple build nodes) 上一篇: Maven快照工件发布文件名