Artifactory or Nexus deploy Jar and Pom - maven

I've got a compiled Jar file and a Pom file. Now I want to deploy both of these to Artifactory or Nexus (I've got both).
I want to do it with either mvn:deploy or curl (REST API)
could someone tell me how I do this?

My answers are about Artifactory, of course.
For using mvn deploy you need to configure your pom file to include distributionManagement tag. You can copy-paste the whole tag from Artifactory UI (click on the repository you want to deploy to, on the right side you'll see the distributionMnagement tag for copying).
With REST API you can just issue two PUT requests (one for pom, other for jar). Start with the pom.

If you got a jar file already as well as a pom, you would want to use the deploy-file goal of the Maven deploy plugin. mvn deploy will build the project but that wont work if you already got the jar and pom file and no source code.
Of course you can also upload the files via the web user interface of Nexus or use the REST api. You can find some REST api examples with curl on github.

Related

Maven not finding dependency with only jar file

I have a jar in artifactory without pom. when I try to download it from maven/gradle, it is not being found with an error "Could not find com.kroger.galactus:koop-order:unspecified". My question is, is it possible to download artifact from artifactory which only has jar file and no pom file?
edited:
since it is not possible to download without pom file.
I have a third party jar file which I need to upload to artifactory. I used curl -X PUT -u u:p -T Maven-Upload-1.1.jar "https:///artifactory/repo/Maven-Upload-1.1.jar", which uploaded jar file.
Is there other way to upload it so it can create pom file in artifactory?
If there is no POM, you need to create one. You can e.g. do this through the artifactory REST api, possibly through the UI as well.
As Fabian mentioned earlier, this can be fixed by generating the POM for the library. This can be achieved by using this Generate POM REST API.

Maven deploy plugin keep the file name when uploading

I am using maven deploy plugin to upload a file inside bamboo deployment stage. I am uploading the file without pom file. When I upload the file to Nexus, the file name is changing completely. Its appending with project name, version number and build number. I want to keep the filename as it is. Any one know how to do this?
mvn deploy:deploy-file
-Dfile=${bamboo.artifacts.path.artifactFile}
-Dpackaging=cba
-url=https://nexus.internal.organisation.com/content/repositories/snapshots/
-DrepositoryId=snapshots
-DgroupId=com.organisation.art
-DartifactId=myproject
-Dversion=0.0.1-SNAPSHOT
A maven managed repository, such as that provided by Nexus et al, is set up in a way that is intended for deployed products to be returned to a maven build process that has them declared as dependencies.
It is not intended to be a generic file server.
If you have Nexus 3.0 or newer then you have access to so called "raw" repositories that you can set up any way you like.
However you would not use mvn deploy:deploy-file to add files to it. Instead you would follow the instructions in Uploading Files to Hosted Raw Repositories.

Maven WAR Plugin / Jenkins repository connector: Omitting transitive dependencies?

Situation
I have a multi-module Maven project. In it, I have several JAR artefacts, it then gets assembled as a WAR file. Thus, the WAR artefact depends on all kinds of JAR artefacts (it also has a WAR overlay), most of them with scope "compile".
Build and deployment to a repository are fine. But when I try to retrieve the WAR artefact, I have issues. previously, I used a simple wget to retrieve it from the Nexus API, but I wanted to try the Jenkins Repository Connector - not the least reason being that it actually shows a list of available versions.
I configure a repository in
Manage Jenkins -> Configure System -> Artifact Resolver
with the URL for our repo:
http://$NEXUS/nexus/content/repositories/releases/
then in the job, i add a parameter:
Maven Repository Artifact
and use the repository configured above, then i add
Artifact Resolver
as a build step and set it up.
Problem
I am not even sure on which side this should be solved: When I run the job to try to get the WAR file from the nexus, it also starts trying to retrieve all kinds of transitive dependencies (some of which are unaccessible to this user) and fails. What I need is just the WAR file. No transitive dependencies (since they're already packaged in the WAR).
The Repository Connector plugin doesn't seem to have a switch for this, and the Maven side it's probably perfectly OK to include those dependencies in the output POM.
Question
What can I do to either stop the repository connector from retrieving transitive dependencies or retrieve the WAR artefact in a different way? Also interesting for me (but a bit broad as a question) would be general ideas about doing this kind of workflow. E.g., does anyone use other ways of deploying the WAR into their Nexus?
i submitted a patch to the repository connector plugin.
my fork:
https://github.com/rmalchow/repository-connector-plugin
working on getting it to be merged:
https://github.com/jenkinsci/repository-connector-plugin/pull/10

maven - how to deploy non-jar files

In my project I have many modules.
One of the modules requires a jar file to be deployed to the repository which it does fine.
The others involve every other kind of file: zip, kar etc.
I can see the zip get uploaded if I look for it via the terminal but if I browse Archiva it is not there.
The kar file, for example, does not need to be built but it's being worked on and is currently manually uploaded to the repository (Archiva). This is not desirable.
Each module has a POM and each POM uploads empty jar files to Archiva when it is built (with Jenkins). How can I avoid that? And can I copy files to Archiva without them having to be built into a jar file?
You can also give a try to "maven-deploy-plugin"
Invoke a maven target in jenkins with this plugin and provide the suitable parameters.
You would also need the repository to be added in you settings.xml if your repository requires login credentials and then use the ID, you mentioned in settings.xml, in the maven target.
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy-file
-Durl=<artifact-repo URL>
-Dfile=<name of the file>
-DgroupId=<Group Id>
-DartifactId=<Artifact Id>
-Dversion=<VERSION>
-Dpackaging=<packaging Type>
-DrepositoryId=<ID as mentioned in settings.xml>
Hope this may be of some help.

Access Maven build properties in Jenkins post-build script to retrieve deployed artifact

I've got a Maven project that Jenkins builds and deploys to a remote repository. I then need to copy the deployed .war to an external location. I've been trying to do this with a post-build shell script but I don't see any way to get the build information from maven (for example, the URL of the deployed artifact). Is there a way to get it, or a way to do this that's more integrated into maven? I can calculate the deployment path using Jenkins build parameters but it seems like a hack.
Thanks,
Steve
After a maven build you should always find the build artifact at
target/<artifactId>-<version>.<packaging>
You can access this path within the maven pom.xml by using the maven properties (see pom reference)
${project.build.directory}/${project.artifactId}-${project.version}.${project.packaging}
To copy the artifact to another location after the build you can use several approaches described e.g. in this thread.

Resources