I have created two maven projects. Below are pom files of both projects;
- core-library -
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Core</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.12</version>
<scope>compile</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
</dependency>
</dependencies>
</project>
- utility-library -
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.demo</groupId>
<artifactId>utility-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Utility</name>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.demo</groupId>
<artifactId>core-library</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.demo</groupId>
<artifactId>core-library</artifactId>
</dependency>
</dependencies>
</project>
Now the core-library have some external dependencies e.g. org.reflections:reflections etc. So my expectation is when I add core-library to the utility-library, these external dependencies should automatically get added to dependency tree of utility-library.
But in actual, these nested dependencies are not getting included in dependency tree of utility-library.
Below is the output when I run mvn dependency:tree on utility-library
--- maven-dependency-plugin:2.8:tree (default-cli) @ utility-library ---
[INFO] com.demo:utility-library:jar:0.0.1-SNAPSHOT
[INFO] +- com.demo:core-library:jar:0.0.1-SNAPSHOT:compile
INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
I tried solution from this stack overflow question, but the problem is not solved yet.
Can someone please help me with this?
P.S. - I have to achieve this nested dependency inclusion without creating a fat/shaded/uber jar as it increses the actual jar size and I also want to further use utility-library as a maven dependency in other project.
UPDATE: When I tried building utility-library with -X (enable debug logs) flag, I got following errors,
[WARNING] The POM for com.demo:core-library:jar:0.0.1-SNAPSHOT is invalid, transitive dependencies (if any) will not be available: 3 problems were encountered while building the effective model for com.demo:core-library:0.0.1-SNAPSHOT
[ERROR] Invalid packaging for parent POM com.demo:core-library:0.0.1-SNAPSHOT, must be "pom" but is "jar" @
[ERROR] Invalid packaging for parent POMcom.demo:core-library:0.0.1-SNAPSHOT, must be "pom" but is "jar" @
[FATAL] The parents form a cycle: com.demo:core-library:0.0.1-SNAPSHOT -> com.demo:core-library:0.0.1-SNAPSHOT @