Maven 继承时 发生的奇怪版本相同时编译不通过
一共写了三个项目:
------Parent
------Hello
------HelloFriend
做法是 用Hello,HelloFriend的pom.xml都继承Parent的pom.xml
Parent--pom.xml
如下:
<project。。。
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>Hello</artifactId>
<version>0.0.1-SNAPSHOT</version> // **********************注意这里
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>HelloFriend</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
。。。
</project>
在Hello--pom.xml
中继承
<project 。。。
<parent>
<groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
没有问题
但是在HelloFriend---pom.xml
中报错了
<project 。。。
<parent>
<groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>Hello</artifactId>
</dependency>
</dependencies>
</project>
报错内容是:
Description Resource Path Location Type
ArtifactDescriptorException: Failed to read artifact descriptor for cn.itcast.maven:Hello:jar:0.0.1-SNAPSHOT: UnresolvableModelException: Could not find artifact cn.itcast.maven:Parent:pom:0.0.1-SNAPSHOT pom.xml /HelloFriend line 1 Maven Dependency Problem
Missing artifact junit:junit:jar:4.9 pom.xml /HelloFriend line 1 Maven Dependency Problem
Missing artifact org.hamcrest:hamcrest-core:jar:1.1 pom.xml /HelloFriend line 1 Maven Dependency Problem
奇怪的是 错误行号为1!
我尝试过重新建立工程 ,换用MyEclipse都不行
于是我改了一下Parent--pom.xml的内容(注意的那个地方),把版本号改了一下 如0.0.1
就没事了,立即HelloFriend---pom.xml中提示找不到那个版本错误行也是对的,重新install一下Hello之后(编译时候也报错,但是却运行过去了);HelloFriend也能install了
有经验的朋友指导一下,这里为什么奇怪的就是指定的版本必须是不同于默认版本呢?我看视频的例子就是这样写的没有问题啊
---------------问题补充---------------
@独孤季落 :这是传智博客的视频内容,老师讲解时候也出了个类似的问题 ,不知道怎么搞得,下节课也没说如何解决的,就神奇的回避了。到底我还是不知道他怎么处理的,我对比了一下工程,跟源代码是形同的,问题依旧,有经验的朋友请想一下是不是跟环境有关(11个月前)
按票数排序 显示最新答案 共有3个答案 (最后回答: 11个月前)
独孤季落11个月前
问题已经解决, 三个配置文件都没有问题!
解决过程:重新在IDE中建立MAVEN工程,并使用统一的jdk版本, 问题不再出现(java文件pom文件没有一丝更改);
感觉是jdk版本不一致捣的鬼
vincen...11个月前
你这个依赖确实有问题,简单说,依赖关系错乱,你的parent依赖子pom 而子pom依赖parent。
独孤季落11个月前
引用来自“vincent1988”的答案
你这个依赖确实有问题,简单说,依赖关系错乱,你的parent依赖子pom 而子pom依赖parent。
这里的原意是parent定义后,供子pom依赖的,parent的pom贴的时候没注意,把<dependencies>前面的<dependencyManagement>省掉了 sorry,
现在把三个文件都贴出来 :
子pom1:
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion><artifactId>Hello</artifactId>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties><parent>
<groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies></project>
子pom2:
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>HelloFriend</artifactId><properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../Parent/pom.xml</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>Hello</artifactId>
</dependency>
</dependencies></project>
父pom:
<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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion><groupId>cn.itcast.maven</groupId>
<artifactId>Parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging><name>Parent</name>
<url>http://maven.apache.org</url><dependencyManagement>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>cn.itcast.maven</groupId>
<artifactId>Hello</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>Myeclipse错误:
ArtifactDescriptorException: Failed to read artifact descriptor for cn.itcast.maven:Hello:jar:0.0.1-SNAPSHOT: UnresolvableModelException: Could not find artifact cn.itcast.maven:Parent:pom:0.0.1-SNAPSHOT pom.xml /HelloFriend line 1 Maven Dependency Problem
Missing artifact junit:junit:jar:4.9 pom.xml /HelloFriend line 1 Maven Dependency Problem
Missing artifact org.hamcrest:hamcrest-core:jar:1.1 pom.xml /HelloFriend line 1 Maven Dependency Problem
Project configuration is not up-to-date with pom.xml. Run project configuration update Hello line 1 Maven Configuration Problem其他java中的错误省略