我目前在尝试将另一个 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
提前致谢!
最佳答案
问题
控制台输出表明 Maven 正在搜索 com.aerospike:aerospike
JBoss public repository 中的神器但那个神器不在那里。
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,唯一可以覆盖此行为的是 artifact update policies在 settings.xml
中定义.
据我所知,离线构建 ( -o
) 应该覆盖任何此类策略。
我试图通过从我的本地存储库中删除依赖项并故意声明不存在的依赖项来重现这种情况,并且 Maven 的行为与记录的一样(离线构建不会尝试下载)。不过,我还没有玩过更新政策。
解决方案
根据评论,我已经在以下环境中验证了离线构建过程:
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 的远程 存储库中找不到的依赖项,例如:
<!--
<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
以及 <LOCAL_REPO_PATH>/.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.log
的内容和 settings.log
文件在这里。
关于linux - Maven 对另一个 Maven 项目的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18279024/