SoFunction
Updated on 2025-03-03

maven Implementation of Transitive Dependency

1. maven passes packages that depend on scope=compile

For example: Project A depends on Project B, Project B depends on Project C, then the jar of Project A contains the scope=compile package in Project C

2. Exclude dependencies using <exclusions>

If Project A only wants to rely on B and does not want to rely on the package of Project C under Project B, you can:

<exclusions>
    <exclusion>
         <groupId>*</groupId>
         <artifactId>*</artifactId>
    </exclusion>         
</exclusions>

3. When there is no problem with compilation in the program and there is a problem with running, you need to find the project's dependency tree structure to see if there are packages required at runtime. The example is as follows:

The modeling-support project depends on the modeling-facade project, and the modeling-facade project depends on the metrics-api project

modeling-support pom:

<dependency>
	<groupId></groupId>
	<artifactId>modeling-facade</artifactId>
</dependency>

modeling-facade pom:

<dependency>
	<groupId></groupId>
	<artifactId>metrics-api</artifactId>
	<exclusions>
		<exclusion>
			<groupId>*</groupId>
			<artifactId>*</artifactId>
		</exclusion>
	</exclusions>
</dependency>

 metrics-api pom:

<dependency>
	<groupId></groupId>
	<artifactId>mvel2</artifactId>
</dependency>

When the modeling-support project execution code: (combinExpress, metricSourceIdMap);

Since Keval is in the metrics-api project, after passing the dependency, modeling-support compiles the above statement without any problem, but it cannot be executed, because executing this code requires the mvel2 package. However, the modeling-facade project has been ruled out, so the modeling-support project does not have this jar, and then it runs an error

This is the end of this article about the implementation of maven transitive dependencies. For more related maven transitive dependencies, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!