从远程存储库获取/检查依赖性

时间:2015-12-02 16:44:23

标签: java maven

Maven Dependency Plugin有一个repoUrl目标,允许您检查对repo的依赖。这可能非常有用。

使用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:~$ 参数。

如下面的代码所示,插件会忽略该参数。它只会尝试从我的设置文件中的repo中获取依赖项。

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

remoteRepositories

更新

remoteRepositories不起作用。 repoUrljenkins@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:~$ 组合尝试执行更多操作但也失败

{{1}}

1 个答案:

答案 0 :(得分:1)

您使用的是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将被忽略。