我有一个相当复杂的项目(大约100个模块),我想在这个项目上运行mvn dependency:tree。它失败了,抱怨它无法解决依赖关系。否则该项目会编译得很好。因此,我创建了一个最基本的项目,但它仍然失败,同样的错误。显然,要么我做了一些非常基本的错误,否则maven依赖插件还没有被任何人使用。以下是三个POMs im by测试项目:
pom.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>root</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>foo</module>
<module>bar</module>
</modules>
</project>foo/pu.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>foo</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
</project>bar/pu.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>bar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>foo</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
</project>然后,在顶层目录中发出以下命令mvn dependency:tree,并获得以下输出:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] foo
[INFO] bar
[INFO] root
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building foo 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ foo ---
[INFO] com.example:foo:jar:1.0.0-SNAPSHOT
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building bar 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] foo ................................................ SUCCESS [ 0.756 s]
[INFO] bar ................................................ FAILURE [ 0.011 s]
[INFO] root ............................................... SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.065 s
[INFO] Finished at: 2015-03-03T16:19:18+01:00
[INFO] Final Memory: 13M/309M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project bar: Could not resolve dependencies for project com.example:bar:jar:1.0.0-SNAPSHOT: Could not find artifact com.example:foo:jar:1.0.0-SNAPSHOT -> [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
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn <goals> -rf :bar我遗漏了什么?这样不就行了吗?
发布于 2016-09-19 05:07:31
我很沮丧为什么它不起作用。
一个简单的依赖分析就是不起作用。
而这位官员也没有任何指南。
另一个很有用的命令也没起作用
mvn dependency:resolve但是,也许您可以尝试使用以下命令
mvn test-compile dependency:resolve
mvn test-compile dependency:tree不管怎么说,对我来说很管用
2017年3月13日最新消息
通过跳过编译,我们可以使它更快。
mvn test-compile dependency:resolve -Dmaven.main.skip=true -Dmaven.test.skip=true
mvn test-compile dependency:tree -Dmaven.main.skip=true -Dmaven.test.skip=true很遗憾我们的项目没有成功,因为我们的项目使用了kotlin,也许是kotlin的bug没有跳过编译,也许我应该把这个bug报告给jetbrains。
发布于 2015-03-04 09:19:33
好的,让我们给出一个正确的答案,因为评论太短了,无法给出正确的解释。
Maven是一个具有各种组合面的工具,有时很难确定哪些部分对给定的命令起作用。
在您的示例中,您有两个经典项目,foo和bar,以及一个特殊的项目root。
root在它所扮演的意义上是特殊的,在您的示例中有两个角色。
<modules>标记中定义的部分。它定义了一组可以将命令作为组发送到的其他项目(例如:mvn clean install)。在执行此类命令时,maven将查看<modules>中描述的项目,并根据它们声明的依赖项,确定它们必须使用给定命令调用的顺序,以便最大限度地提高构建成功的可能性。现在,关于您尝试过的各种命令的行为(假设它们都是在root项目中调用的):
mvn dependency:tree将对<modules>标记中列出的所有项目执行依赖分析。此分析是针对存储库执行的,这意味着您的本地.m2回购以及其他需要的外部存储库。如果您没有首先在您的存储库中安装您的项目,它将在bar上失败,因为它无法在其中找到com.example:foo:1.0.0-SNAPSHOT。mvn [clean] install将执行将项目打包和部署到本地存储库的完整过程。由于bar将在foo被放入您的存储库后执行,所以一切都会很好,每个人都会很高兴。但是,在那个时候工作的mvn compile是什么呢?
你的案子有点棘手。由于您的示例没有要编译的实际代码,因此将跳过编译的依赖解决方案,因此在foo工件不可用时不会发生错误。
现在,关于你在回购中的分支和手工艺品的评论.
当您切换到分支时,除非所有其他项目(模块)都使用稳定的版本号(即没有快照后缀),否则您应该在反应堆pom上执行mvn [clean] install运行,以确保您开始使用一组连贯的模块和依赖项。
您可能会认为,与例如解释语言相比,这是浪费时间,但这是处理项目的MAVEN方法。它确保所有模块在开始工作之前都对齐。
发布于 2022-08-19 12:25:18
对我来说,这个问题出现了,试图强制执行requireUpperBoundDeps规则。我无法将maven-enforcer plugin降级(从3.1.0降至3.0.0-M3)。我不得不在某些依赖项中添加排除项。
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>${dep.ehcache}</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>sizeof-agent</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces</artifactId>
<version>${dep.richfaces}</version>
<exclusions>
<exclusion>
<groupId>jacorb</groupId>
<artifactId>jacorb</artifactId>
</exclusion>
<exclusion>
<groupId>org.richfaces.cdk</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-a4j</artifactId>
<version>${dep.richfaces}</version>
<exclusions>
<exclusion>
<groupId>jacorb</groupId>
<artifactId>jacorb</artifactId>
</exclusion>
<exclusion>
<groupId>org.richfaces.cdk</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-core</artifactId>
<version>${dep.richfaces}</version>
<exclusions>
<exclusion>
<groupId>jacorb</groupId>
<artifactId>jacorb</artifactId>
</exclusion>
<exclusion>
<groupId>org.richfaces.cdk</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>https://stackoverflow.com/questions/28835418
复制相似问题