开发者社区> 问答> 正文

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🏺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🏺4.9 pom.xml /HelloFriend line 1 Maven Dependency Problem
Missing artifact org.hamcrest:hamcrest-core🏺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了

 

有经验的朋友指导一下,这里为什么奇怪的就是指定的版本必须是不同于默认版本呢?我看视频的例子就是这样写的没有问题啊


 

 

 

展开
收起
爱吃鱼的程序员 2020-06-22 15:22:58 614 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    问题已经解决,三个配置文件都没有问题!

    解决过程:重新在IDE中建立MAVEN工程,并使用统一的jdk版本,问题不再出现(java文件pom文件没有一丝更改);

    感觉是jdk版本不一致捣的鬼

    请问怎么解决ArtifactDescriptorException:Failedtoreadartifactdescriptorforcom.sun.xml.bind非常感谢,用你的方法我也解决了,初学mavenO(∩_∩)O~你这个依赖确实有问题,简单说,依赖关系错乱,你的parent依赖子pom 而子pom依赖parent。

    引用来自“vincent1988”的答案

    你这个依赖确实有问题,简单说,依赖关系错乱,你的parent依赖子pom 而子pom依赖parent。

    写得不错,这里再补充下,相互学习,共同进步。

    Maven详解之继承

    2020-06-22 15:23:15
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载