Recently I had to download dependencies from a Maven plugin (Mojo). But I encountered difficulties and want to tell you my conclusion. Here is what I tried:
Shrinkwrap resolver is a JBoss OSS library. For unknown reasons it was sometimes not downloading the latest artifacts from the repository but relied on the outdated ones in the local repo instead. I surely misconfigured something but could not find what…
Apache Archiva REST API
In theory, a simple call to the webservice should have returned my artifact. But (again) for unknown reasons, it would sometimes fail and return a zero byte file.
For exemple, this call fails:
but this one succeeds:
And I am sure the 2.1.0 version exists and is the latest…
mvn org.apache.maven.plugins:maven-dependency-plugin:3.1.1:get -Dartifact=com.company-sdk-boxes:default-boxes-bcd-doc:2.1.0:zip
=> OK but in previous version (2.X) we used to have parameter “dest” which is now deprecated. So we cannot point the download to a specific directory: it resolves to the local repo only.
mvn dependency:copy -Dartifact=com.company.sdk-boxes:default-boxes-bcd-doc:2.1.0:zip -DoutputDirectory=. -DuseBaseVersion=true
This is the way I should have tried first ! I don’t know why but I thought the dependency:copy would need a pom to download dependencies. In fact this is not true, you can use it on the command line.
And as you can use it on the command line, you can also use it from inside another Mojo (Maven plugin) by using the Mojo executor. Only caveat is that you do not get a handle on the file just downloaded but you know it’s filename in advance. It is of the form -.jar if you make sure to use the -DuseBaseVersion=true parameter to avoid the timestamp replacing the “-SNAPSHOT” suffix.