【问题标题】:Maven dependency on another Maven projectMaven 对另一个 Maven 项目的依赖
【发布时间】:2013-08-16 17:32:44
【问题描述】:

我目前在尝试将另一个 Maven 项目(特别是 Aerospike)的依赖项添加到我的项目中时遇到问题。我已经在 Aerospike 项目上做了一个mvn install,所以在我的存储库中(在 Linux 上:~/.m2/repository/com/aerospike/aerospike-client/3.0.6)我看到了 aerospike-client-3.0.6.jar .lastUpdated 文件。但是,当我添加依赖项时

<dependency>
    <groupId>com.aerospike</groupId>
    <artifactId>aerospike-client</artifactId>
    <version>3.0.6</version>
    <scope>compile</scope>
</dependency>

进入我的项目并执行mvn install,它返回此错误:

[INFO] ------------------------------------------------------------------------
[INFO] Building in-memory database poc 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[WARNING] The POM for com.aerospike:aerospike-client:jar:3.0.6 is missing, no dependency information available
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.601s
[INFO] Finished at: Fri Aug 16 11:49:43 EDT 2013
[INFO] Final Memory: 18M/954M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project: Could not resolve dependencies for project: Failure to find com.aerospike:aerospike-client:jar:3.0.6 in http://repository.jboss.org/nexus/content/groups/public was cached in the local repository, resolution will not be reattempted until the update interval of jboss-public-repository-group has elapsed or updates are forced -> [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/DependencyResolutionException

提前致谢!

【问题讨论】:

  • 请列出/树你在 ~/.m2/repository/com/aerospike/aerospike-client/3.0.6 中的内容。 (在 Windows 上是:C:\Users\\.m2\...)
  • 我已经用详细的存储库位置更新了这个问题。谢谢
  • "直到 jboss-public-repository-group 的更新间隔已经过去或强制更新后才会重新尝试解析" - 您是否尝试过强制更新?从命令行运行时只需添加 -U。
  • 林斯基,谢谢你的建议。我试过了,我得到了同样的错误。
  • 在这种情况下,我通常会从存储库中手动删除有问题的版本。但是,我在该 repo repository.jboss.org/nexus/content/groups/public 中看不到任何 com/aerospike/aerospike-client 文件夹。你是怎么得到这种依赖的?

标签: linux maven-2 pom.xml maven-dependency-plugin aerospike


【解决方案1】:

问题

控制台输出显示 Maven 正在 JBoss public repository 中搜索 com.aerospike:aerospike 工件,但该工件不存在。

Failure to find com.aerospike:aerospike-client:jar:3.0.6 in                                         
http://repository.jboss.org/nexus/content/groups/public

OP说他是本地安装的。

讨论

Maven 正在尝试从没有该工件的远程存储库下载本地安装的工件。 By default 依赖项首先在本地存储库中搜索。 AFAIK,唯一可以覆盖此行为的是settings.xml 中定义的artifact update policies

AFAIK,离线构建 (-o) 应该覆盖任何此类策略。 我试图通过从我的本地存储库中删除依赖项并故意声明不存在的依赖项来重现这种情况,并且 Maven 表现得像记录的那样(离线构建不会尝试下载)。不过我还没有玩过更新策略。

解决方案

跟进cmets,我在以下环境下验证了离线构建过程:

Apache Maven 3.1.0 
Java version: 1.7.0_25, vendor: Oracle Corporation
OS name: "linux", version: "3.2.0-23-generic", arch: "amd64", family: "unix"

简称离线构建过程:

  • 下载所有在线依赖项
  • 安装所有离线依赖项
  • 运行离线构建

所有命令都从项目根文件夹运行。

首先,注释掉你的 pom 中任何 remote 存储库中找不到的所有依赖项,例如:

<!--
 <dependency>
        <groupId>does</groupId>
        <artifactId>not</artifactId>
        <version>exist</version>
 </dependency>
-->

准备offline build by downloading all the dependencies:

mvn dependency:go-offline

如果你不注释掉缺失的依赖,这个目标就会失败。您可以通过观察 Maven 已成功下载控制台输出中的所有工件来验证它。

接下来,安装缺少的依赖项manually in your local repo

mvn install:install-file -Dfile=<PATH_TO_MISSING_DEP_JAR_FILE> 
                         -DgroupId=does  
                         -DartifactId=not   
                         -Dversion=exist 
                         -Dpackaging=jar 

这将生成not-exist.jar 的副本)和not-exist.pom 以及&lt;LOCAL_REPO_PATH&gt;/.m2/repository/does/not/exist/ 下本地存储库中的元数据文件

验证这些文件存在于该确切目录结构下。 不同平台的本地存储库的默认位置是here,但如果不存在,则运行:

mvn help:effective-settings > settings.log

这会将您项目的interpolated settings 转储到settings.log 文件。用文本编辑器打开,read the path of your local repo 下:

<settings>
  ...
  <localRepository>/path/to/local/repo/</localRepository>
  ...
</settings>

现在您可以在离线模式下运行构建:

mvn clean install -o

您也可以设置offline mode in your settings file,但这将为a specified user or system-wide 设置离线模式,而不是在您需要时为每个项目设置命令行开关。

结论

小心运行此过程完全按照描述,如果您仍然无法构建您的项目,请运行:

mvn help:effective-pom > pom.log
mvn help:effective-settings > settings.log

并在此处发布pom.logsettings.log 文件的内容。

【讨论】:

  • 有趣。 1)您是否尝试过 -o 开关? 2) mvn -version 输出什么?
  • 我尝试了 -o 和 -U 开关,我得到了同样的错误。 mvn -version 输出是Apache Maven 3.1.0 (893ca28a1da9d5f51ac03827af98bb730128f9f2; 2013-06-27 22:15:3 2-0400) Maven home: /opt/apache-maven-3.1.0 Java version: 1.7.0_25, vendor: Oracle Corporation Java home: /usr/java/jdk1.7.0_25/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "2.6.39-400.17.1.el6uek.x86_64", arch: "amd64", family: "unix" 我尝试注释掉存储库,它刚刚开始从另一个存储库搜索。有没有办法强制 Maven 在其本地存储库中搜索?
  • 是的,通过使用 -o 开关。我刚刚验证了这一点,我从我的项目中删除了一个 dep 并使用 -o 开关运行它,但构建失败了。没有它就成功了。我有 Maven 3.0.4。也许还有另一种方法,只需一秒钟
  • 似乎即使使用 -o 开关,它仍在 jboss 存储库中搜索 .jar 文件。非常感谢 linski 的帮助!
  • 呃,我今天的工作就结束了,我的版本比你的还早 :))。如果没有人回答,我明天早上再试,祝你好运。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-10
  • 2018-10-20
  • 2011-03-26
相关资源
最近更新 更多