In dependencies of child pOM maven dependencies do not accept the version from the parent pom dependencies if they are mentioned in the profile

I have a multi-module project and I use profiles in the parent pom, which has certain dependencies mentioned in them. The problem here is that if in the child pom I override the dependency element and mention one of the dependencies of the parent pom (which is declared in the profile in the parent pom), the version of this particular dependency should 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 could be wrong, and how can I fix it ??

NOTE. Profile marked activeByDefault

+4
source share
1 answer

For this kind of requirements, you are dependencyManagement , which is exactly suitable for such cases. Or check out the Sonatipy Book . This case should not be handled by profiles.

+3
source

Source: https://habr.com/ru/post/1345729/


All Articles