在 maven 中,如果在配置文件中提到了子 pom 依赖项,则它们不会从父 pom 依赖项中获取版本

Nee*_*raj 5 maven-2 maven

我有一个多模块项目,我在父 pom 中使用配置文件,其中提到了特定的依赖项。这里的问题是,如果在子 pom 中,我覆盖了依赖项元素,并提到了父 pom 中的依赖项之一(在父 pom 的配置文件中声明),则该特定依赖项的版本需要是再次提到。

例如父 pom

<dependencies>
   <dependency>
      <groupId>com.mycode.apps</groupId>
      <artifactId>jobs</artifactId>
      <version>4</version>   
   </dependency>
</dependencies>
<profiles>
<profile>
    <id>common-dependencies</id>
<activation>
    <activeByDefault>true</activeByDefault>
</activation>
    <dependencies>
       <dependency>
          <groupId>com.mycode.apps</groupId>
          <artifactId>dao</artifactId>
          <version>4</version>   
       </dependency>
    </dependencies>
</profile>
</profiles>
Run Code Online (Sandbox Code Playgroud)

现在在子 pom.xml

<dependencies>
       <!--this one doesnt need a version specified -->
       <dependency>
          <groupId>com.mycode.apps</groupId>
          <artifactId>jobs</artifactId>
       </dependency>
       <!--this one makes maven throw an error(if version is not specified) while compilation -->
       <dependency>
          <groupId>com.mycode.apps</groupId>
          <artifactId>dao</artifactId>
       </dependency>
</dependencies>
Run Code Online (Sandbox Code Playgroud)

知道什么可能是错的,我该如何解决这个问题?

注意:配置文件被标记为 activeByDefault

khm*_*ise 3

对于这种要求,您需要依赖管理,它正是针对这种情况。或者查看Sonatype Book。这种情况不应该由配置文件处理。