1

We have a private repository at work so once a while we need to download artifacts from the central repository and upload them.

Someone wrote a program a while ago for that which didn't always work perfectly: it would download all dependencies for each artifact separately, it would first scan the dependency tree and only then download them, it wouldn't download sources and javadocs, was slow, etc.

Recently I have come across this useful maven plugin called dependency and its goal get.

So now to download some artifact, let's say for instance com.sparkjava.spark-core:2.5.4, I would type on my terminal:

mvn dependency:get -Dartifact=com.sparkjava:spark-core:2.5.4
mvn dependency:get -Dartifact=com.sparkjava:spark-core:2.5.4:sources
mvn dependency:get -Dartifact=com.sparkjava:spark-core:2.5.4:javadoc

Which would download the artifact along with all its dependencies to the directory ~/.m2/repository which I can later transfer to our private repository.

This method works good but has 2 problems:

  1. I have to run the command 3 times when each time the classifier is different and I would like to get all classifiers at once.
  2. It always downloads the artifacts into ~/.m2/repository, which can sometime contain other artifacts I'm not intrested in having on the private repository. I need be able to choose another directory destination.

What can I do about these issues? About the first one I can work it around with an alias (which will still run the same command 3 times) but I have no idea what to do about the second issue and it's not mentioned on the plugin's documentation either.

1 Answers1

0

To solve (2), you can update the settings.xml with a tag

<localRepository>C:\Users\my\custom\existing\directory</localRepository>

and make sure when you are building the project, the same settings.xml looked into which can be done using

mvn clean install -gs <pathToDirectory>

Note - Please modify the path accordingly.


To solve (1), adding the following to settings.xml should work as well -

<profiles>
    <profile>
        <id>downloadSources</id>
        <properties>
            <downloadSources>true</downloadSources>
            <downloadJavadocs>true</downloadJavadocs>
        </properties>
    </profile>
</profiles>

<activeProfiles>
    <activeProfile>downloadSources</activeProfile>
</activeProfiles>

Source - Maven – Always download sources and javadocs


Other maven command that could help here is -

resolve command with classifier :

mvn dependency:resolve -Dclassifier=javadoc #downloads all the documentation
Community
  • 1
  • 1
Naman
  • 27,789
  • 26
  • 218
  • 353
  • Thanks! I'm looking for a one command solution without involving settings.xml. I tried runnign mvn dependency:get -Dmaven.repo.local=dest -DdownloadSources=true -DdownloadJavadocs=true -Dartifact=com.sparkjava:spark-core:2.5.4 which worked for changing the destination but it did not download sources and javadocs. From googling they seem to be eclipse's plugin properties: http://maven.apache.org/components/maven-eclipse-plugin/examples/attach-library-sources.html –  Jan 25 '17 at 21:41