簡體   English   中英

在maven child pom依賴項中,如果在配置文件中提到它們,則不會從父pom依賴項中獲取版本

[英]In maven child pom dependencies are not taking version from parent pom dependencies if they are mentioned in a profile

我有一個多模塊項目,我在父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>

現在在子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>

知道什么可能是錯的,我該如何解決這個問題?

注意:配置文件標記為activeByDefault

對於這種要求,您可以使用依賴管理 ,這完全適用於此類情況。 或者看一下Sonatype Book 這種情況不應由配置文件處理。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM