在 Maven 中,如果配置文件中提到了子 pom 依赖项,则它们不会从父 pom 依赖项获取版本
我有一个多模块项目,并且我在父 pom 中使用配置文件,其中包含其中提到的特定依赖项。 这里的问题是,如果在子 pom 中,我重写 dependency 元素,并提及父 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
I have a multi-module project, and I am using profiles in the parent pom , which have specific dependencies mentioned in them.
The issue here is that, if in a child pom , I am overriding the dependency element, and mentioning one of the dependencies in the parent pom (which is declared in a profile in parent pom) , the version of that specific dependency needs to be mentioned again.
E.g
Parent 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>
Now in child 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>
Any idea what might be wrong and how can I fix this??
NOTE: The profile is marked as activeByDefault
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
对于这种要求,您的 dependencyManagement 正是对于此类情况。或者查看 Sonatype 书。
这种情况不应该由配置文件处理。
For this kind of requirments you the dependencyManagement which is exactly for such cases. Or take look into the Sonatype Book.
This case shouldn't be handled by profiles.