Get/check depedency from remote repository

The Maven Dependency Plugin has a get goal that allows you to check a dependency against a repo. This could be quite useful.

With a repoUrl argument.

As code below shows the argument is ignored by the plugin. It will just try to fetch the dependency from repo in my settings file.

Is there a way to check for a dependency in a remote repository?

jenkins@devops:~$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get \
>     -DrepoUrl=http://repository.springsource.com/maven/bundles/external/ \
>     -Dartifact=javax.servlet:javax.servlet:2.4.0
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:get (default-cli) @ standalone-pom ---
Downloading: https://devops.ok:8443/nexus/content/groups/public/javax/servlet/javax.servlet/2.4.0/javax.servlet-2.4.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.221 s
[INFO] Finished at: 2015-12-02T16:33:50+00:00
[INFO] Final Memory: 11M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get (default-cli) on project standalone-pom: Couldn't download artifact: Failure to find javax.servlet:javax.servlet:jar:2.4.0 in https://devops.ok:8443/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced
[ERROR] 
[ERROR] Try downloading the file manually from the project website.
[ERROR] 
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=javax.servlet -DartifactId=javax.servlet -Dversion=2.4.0 -Dpackaging=jar -Dfile=/path/to/file
[ERROR] 
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=javax.servlet -DartifactId=javax.servlet -Dversion=2.4.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR] 
[ERROR] 
[ERROR] javax.servlet:javax.servlet:jar:2.4.0
[ERROR] 
[ERROR] from the specified remote repositories:
[ERROR] nexus (https://devops.ok:8443/nexus/content/groups/public/, releases=true, snapshots=true),
[ERROR] nexus (https://devops.ok:8443/nexus/content/groups/public/, releases=true, snapshots=true)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
jenkins@devops:~$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DrepoUrl=http://repository.springsource.com/maven/bundles/external/ -Dartifact=javax.servlet:javax.servlet:2.4.0
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:get (default-cli) @ standalone-pom ---
Downloading: https://devops.ok:8443/nexus/content/groups/public/javax/servlet/javax.servlet/2.4.0/javax.servlet-2.4.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.245 s
[INFO] Finished at: 2015-12-02T16:38:33+00:00
[INFO] Final Memory: 11M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get (default-cli) on project standalone-pom: Couldn't download artifact: Failure to find javax.servlet:javax.servlet:jar:2.4.0 in https://devops.ok:8443/nexus/content/groups/public/ was cached in the local repository, resolution will not be reattempted until the update interval of nexus has elapsed or updates are forced
[ERROR] 
[ERROR] Try downloading the file manually from the project website.
[ERROR] 
[ERROR] Then, install it using the command:
[ERROR] mvn install:install-file -DgroupId=javax.servlet -DartifactId=javax.servlet -Dversion=2.4.0 -Dpackaging=jar -Dfile=/path/to/file
[ERROR] 
[ERROR] Alternatively, if you host your own repository you can deploy the file there:
[ERROR] mvn deploy:deploy-file -DgroupId=javax.servlet -DartifactId=javax.servlet -Dversion=2.4.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
[ERROR] 
[ERROR] 
[ERROR] javax.servlet:javax.servlet:jar:2.4.0
[ERROR] 
[ERROR] from the specified remote repositories:
[ERROR] nexus (https://devops.ok:8443/nexus/content/groups/public/, releases=true, snapshots=true),
[ERROR] nexus (https://devops.ok:8443/nexus/content/groups/public/, releases=true, snapshots=true)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
jenkins@devops:~$ 

Update

remoteRepositories does not work. remoteRepositories in combination with repoUrl tries to do more but also fails

jenkins@devops:~$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DremoteRepositories=http://repository.springsource.com/maven/bundles/external -Dartifact=javax.servlet:javax.servlet:2.4.0 -DrepoUrl=http://repository.springsource.com/maven/bundles/external/
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:get (default-cli) @ standalone-pom ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.811 s
[INFO] Finished at: 2015-12-02T16:51:10+00:00
[INFO] Final Memory: 7M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get (default-cli) on project standalone-pom: A type incompatibility occured while executing org.apache.maven.plugins:maven-dependency-plugin:2.1:get: java.lang.String cannot be cast to org.apache.maven.artifact.repository.ArtifactRepository
[ERROR] -----------------------------------------------------
[ERROR] realm =    plugin>org.apache.maven.plugins:maven-dependency-plugin:2.1
[ERROR] strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
[ERROR] urls[0] = file:/var/lib/jenkins/.m2/repository/org/apache/maven/plugins/maven-dependency-plugin/2.1/maven-dependency-plugin-2.1.jar



jenkins@devops:~$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.1:get -DremoteRepositories=http://repository.springsource.com/maven/bundles/external -Dartifact=javax.servlet:javax.servlet:2.4.0
[INFO] Scanning for projects...
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:get (default-cli) @ standalone-pom ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.860 s
[INFO] Finished at: 2015-12-02T16:55:50+00:00
[INFO] Final Memory: 7M/152M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get (default-cli) on project standalone-pom: The parameters 'repositoryUrl' for goal org.apache.maven.plugins:maven-dependency-plugin:2.1:get are missing or invalid -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginParameterException
jenkins@devops:~$ 

Answers


You are using a very old version of the maven-dependency-plugin. Last version is 2.10 (and not 2.1, which is from 2009).

It is probably best to update to the latest version. Then, the property repositoryUrl (or user property repoUrl) is deprecated. You should use remoteRepositories instead:

$ mvn org.apache.maven.plugins:maven-dependency-plugin:2.10:get \
     -DremoteRepositories=http://repository.springsource.com/maven/bundles/external \
     -Dartifact=javax.servlet:javax.servlet:2.4.0

Note however that if your settings.xml configures a mirror with <mirrorOf>*</mirrorOf>, it is expected that all requests for artifacts go through it so remoteRepositories will be ignored.


Need Your Help

How to avoid HTTP error 429 (Too Many Requests) python

python http mechanize http-status-code-429

I am trying to use Python to login to a website and gather information from several webpages and I get the following error:

Interfaces with hibernate annotations

java hibernate jpa annotations gilead

i am wondering how i would be able to annotate an interface