Java ';dependencies.dependency.version';缺少错误,但版本在父级中管理
我有一个maven项目,它包含几个模块。在Eclipse(Juno,带有m2e)中,它似乎编译得很好。但当我在其中一个模块上安装maven时,构建立即失败 父pom:Java ';dependencies.dependency.version';缺少错误,但版本在父级中管理,java,maven-3,Java,Maven 3,我有一个maven项目,它包含几个模块。在Eclipse(Juno,带有m2e)中,它似乎编译得很好。但当我在其中一个模块上安装maven时,构建立即失败 父pom: <groupId>com.sw.system4</groupId> <artifactId>system4-parent</artifactId> <version>${system4.version}</version> <packag
<groupId>com.sw.system4</groupId>
<artifactId>system4-parent</artifactId>
<version>${system4.version}</version>
<packaging>pom</packaging>
<name>System 4 Parent Project</name>
<modules>
<module>system4-data</module>
...others...
</modules>
<properties>
<system4.version>0.0.1-SNAPSHOT</system4.version>
<spring.version>3.2.3.RELEASE</spring.version>
... others...
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
</dependency>
... lots of others ...
</dependencies>
</dependencyManagement>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sw.system4</groupId>
<artifactId>system4-data</artifactId><!-- child artifact id -->
<version>${project.version}</version>
<dependency>
<!-- add all third party libraries ... -->
</dependencies>
<dependencyManagement>
我不明白为什么它甚至不尝试编译。我尝试从父级和子级删除运行时作用域,但没有任何区别。请帮忙 理论上,maven不允许使用属性设置父版本 在您的情况下,maven根本无法确定父pom的0.0.1-SNAPSHOT版本是当前在您的项目中的版本,因此它会尝试在您的本地repo中找到它。它可能会找到一个,因为它是一个快照,但它是一个旧版本,可能不包含依赖项管理部分 不过,有一个解决办法: 只需使用以下命令更改子pom中的父部分:
<parent>
<groupId>com.sw.system4</groupId>
<artifactId>system4-parent</artifactId>
<version>${system4.version}</version>
<relativePath>../pom.xml</relativePath> <!-- this must match your parent pom location -->
</parent>
com.sw.system4
系统4父级
${system4.version}
../pom.xml
我认为您可以尝试以下几件事:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.3.RELEASE</version>
<scope>runtime</scope>
</dependency>
org.springframework
弹簧芯
3.2.3.1发布
运行时
<parent>
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
com.mycompany.app
我的应用程序
1.
../parent/pom.xml
看起来您的POM中总共有8个错误。在添加父pom和属性之前,我会尝试运行一些基本的编译。对,在经历了很多麻烦之后,我有了一个编译系统 清理.m2缓存是一件有帮助的事情(感谢Brian) 我犯的一个错误是将每个依赖项的两个版本放在父pom dependencyManagement部分—一个有运行时,一个没有—这是为了让eclipse高兴(即不显示恶意编译错误)并能够在命令行上运行。这只是让事情变得复杂,所以我删除了运行时的部分 显式地设置父级的版本似乎也起作用(遗憾的是maven没有更广泛的支持来使用这样的属性!)
com.sw.system4
系统4父级
0.0.1-快照
然后,我在所有依赖项的子模块中发现奇怪的“收集依赖项失败”错误,说它找不到父模块——尽管它的设置与编译的其他模块相同
我最终通过从父pom编译来解决问题,而不是试图单独编译每个模块。这告诉我一个错误,在不同的模块中有一个相对简单的修复,奇怪的是,它使所有的代码都被编译了
换句话说,如果您得到与子模块A相关的maven错误,那么实际上可能是不相关的子模块Z的问题,所以请看这里。(并删除您的缓存)如果有人发现这里有与我相同的问题,我的问题是,我丢失了从子pom复制的依赖项周围的
标记。确保子节点的project/parent/version节点中的值与其父节点的project/version值匹配。在执行子模块之前,必须先构建父模块。刚刚起作用的是删除子节点中的settings.xml.m2文件夹:此文件告诉项目查找不存在的spring mvc和web版本。我也有同样的错误,我忘记在
中添加子依赖项。例如,在父pom中:
<groupId>com.sw.system4</groupId>
<artifactId>system4-parent</artifactId>
<version>${system4.version}</version>
<packaging>pom</packaging>
<name>System 4 Parent Project</name>
<modules>
<module>system4-data</module>
...others...
</modules>
<properties>
<system4.version>0.0.1-SNAPSHOT</system4.version>
<spring.version>3.2.3.RELEASE</spring.version>
... others...
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
<scope>runtime</scope>
</dependency>
... lots of others ...
</dependencies>
</dependencyManagement>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sw.system4</groupId>
<artifactId>system4-data</artifactId><!-- child artifact id -->
<version>${project.version}</version>
<dependency>
<!-- add all third party libraries ... -->
</dependencies>
<dependencyManagement>
com.sw.system4
系统4数据
${project.version}
我也遇到了同样的问题,我将“repository”文件夹重命名为“.m2”(类似repositoryBkp的名称并不重要,只是为了防止出错),并创建一个新的“repository”文件夹,然后我重新运行maven,所有项目都成功编译问题是父项目有其他子项目(模块)好的。relativePath默认值正确地指向父pom的位置。只是澄清一下-我排除的其他7个错误都是同一类型的-即dependencies.dependency.version缺少(其他dependency)对我来说是关键:一个模块不在默认子位置,而是更深的一个子目录。谢谢。Maven抱怨缺少依赖项的另一个原因是父pom中声明的依赖项与子pom要查找的类型不对应。谢谢。2为我修正了。清理整个本地回购协议有点太激进了。。。只要删除项目所涉及的子树就足够了。关于同一主题的另一篇文章:可能与的重复,我一直想知道dependencyManagement标签的用途是什么。。这对我很有用。。我在家长pom中遗漏了这个标签。这感觉像是适用于大多数来这里的人的答案。某种解释:(你创造了我的一天)这应该是公认的答案。
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.sw.system4</groupId>
<artifactId>system4-data</artifactId><!-- child artifact id -->
<version>${project.version}</version>
<dependency>
<!-- add all third party libraries ... -->
</dependencies>
<dependencyManagement>