4

I want to download a Jar that is on a closed (authentified) Nexus. I want to do this via Maven, to be technology agnostic (it can work with Nexus or Artifcatory for example).

I found this intersting plugin: https://maven.apache.org/plugins/maven-dependency-plugin/get-mojo.html, this works with an artifact that is on the central repository, or any "open" repository.

My command is:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get -Dartifact=com.test.job:job-template:1.0.0:jar:jar-with-dependencies -Ddest=/tmp/test.jar -DremoteRepositories=http://nexus.test.local/nexus/content/repositories/test-releases/

I get an error: "Not authorized , ReasonPhrase:Unauthorized". Of course, I have to be authentified to get this artifact. How can I give my credentials to this command? My Maven settings.xml already contains the credentials for this local repository, but the command does not read these credentials (seems logical).

Thanks!

toni07
  • 356
  • 7
  • 20

1 Answers1

4

Define server tag in your ~/.m2/settings.xml

...
  <servers>
    <server>
      <id>serverId</id>
      <username>login</username>
      <password>password</password>
    </server>
  </servers>
...

serverId is important you must use the same label in remoteRepositories properties, so you shoud run:

mvn org.apache.maven.plugins:maven-dependency-plugin:2.4:get ... \
-DremoteRepositories=serverId::::http://nexus.test.local/...

Of course you can use any label as you wish for server/id

Slawomir Jaranowski
  • 7,381
  • 3
  • 25
  • 33
  • Thanks, it worked! I just have read the doc more carefully, it is written: "remoteRepositories: Repositories in the format id::[layout]::url or just url". My bad, thank you! – toni07 Mar 29 '17 at 13:56