2015-12-02 71 views
1

Maven依赖项插件有一个get目标,允许您检查依赖于回购的依赖项。这可能非常有用。从远程存储库获取/检查依赖项

With a repoUrl argument。

由于下面的代码显示该参数被插件忽略。它只会尝试从我的设置文件中获取从回购的依赖关系。

有没有办法检查远程存储库中的依赖关系?

[email protected]:~$ 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 
[email protected]:~$ 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 
[email protected]:~$ 

更新

remoteRepositories不起作用。 remoteRepositoriesrepoUrl组合尝试做多,但

[email protected]:~$ 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 



[email protected]:~$ 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 
[email protected]:~$ 

回答

0

您使用的是很旧版本的maven-dependency-plugin也失败。最后的版本是2.10(而不是2.1,这是从2009年起)。

这可能是最好的更新到最新版本。然后,不推荐使用repositoryUrl(或用户属性repoUrl)。您应该使用remoteRepositories代替:

$ 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 

不过请注意,如果你的settings.xml配置与<mirrorOf>*</mirrorOf>一个mirror,预计神器所有请求都通过它,以便remoteRepositories将被忽略。