Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

copy artifact from local maven repository

Tags:

maven

nexus

I don't understand why this is so difficult:

In a script, I need to copy an artifact from nexus to a certain directory. Using the Nexus REST API I would have to specify the repository which I don't want to have to know about. So I tried getting the artifact with maven-dependency-plugin's get goal instead, which works well. (In that case I get it from a group on our nexus which includes both, releases and snapshots.)

However, I now have the artifact in my local repo and the same plugin's "copy" goal does not seem to be able to get that artifact out of there. Is it really necessary to descend into the .m2 folder and grab that jar with the unix cp command? Anybody ever copied artifacts from their local repos to other dirs before?

Alternatively, if someone can tell me how to get an artifact via the Nexus API without specifying the repo, that would work, too.

like image 225
Cpt. Senkfuss Avatar asked Jul 04 '13 14:07

Cpt. Senkfuss


2 Answers

Seems like the problem was the _maven.repositories file in conjunction with the particular maven setup at my company.

We don't put the info about the local repo in our settings.xml. It's all in the parent pom that all our projects use. But if you want to do some pure mvn-CLI magic you don't have the parent-pom so you have to provide the URL to the local repo yourself. This is possible with the dependecy:get goal, which is why I was able to download my artifact from our Nexus into my local repo.

When using copy, however, you can't specify a URL. But why would I want to? I just downloaded that artifact into my local repo, right?

That's where the _maven.repositories file comes into play. Even with the -o switch, maven3 consults that file, which specifies the original repo that the artifact came from. (thanks to the guys in this thread for posting their findings!). If it can't reach the repo, it will claim that your file isn't there. (Btw., this is not helpful imho. It should say something about the original repo not being reachable and that the file therefore won't be copied.)

This was the reason why copy didn't work for me.

Simply renaming that file does the trick.

I will have to investigate a cleaner solution to this, though.

To make things even more complicated, I couldn't use dependency:copy or dependency:copy-dependecies. For some reasons they require a pom, which I don't have in my usecase. What does work is org.apache.maven.plugins:maven-dependency-plugin:2.8:copy which I believe is supposed to be the same thing, but that's another story.

Thanks for your answers!

like image 145
Cpt. Senkfuss Avatar answered Sep 27 '22 20:09

Cpt. Senkfuss


Just tried this, and it worked for me:

mvn dependency:copy-dependencies -DincludeArtifactIds=jcharts -DincludeGroupIds=jcharts -DoutputDirectory=/tmp/

This copied the artifact jcharts:jcharts to /tmp/ It was in my local (and remote) repo when this was executed.

like image 27
Keith Avatar answered Sep 27 '22 19:09

Keith