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:
- 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.
- 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.