For example, if there are dependencies:
a -> b
a -> c
b -> c
I want to remove the dependency a -> c
, because there is a -> b -> c
.
I know there may be some strong dependencies which should not be reduced, but it's not relevant to this question.
Example:
In a.pom:
<dependencies>
<dependency>b</dependency>
<dependency>c</dependency>
</dependencies>
In b.pom:
<dependencies>
<dependency>c</dependency>
</dependencies>
Expected result:
In a.pom:
<dependencies>
<dependency>b</dependency>
</dependencies>
If a transitive dependency exists, we remove the transitively dependent attribute(s) from the relation by placing the attribute(s) in a new relation along with a copy of the determinant.
Multiple transitive dependencies can be excluded by using the <exclusion> tag for each of the dependency you want to exclude and placing all these exclusion tags inside the <exclusions> tag in pom. xml.
Transitive Dependencies. Maven avoids the need to discover and specify the libraries that your own dependencies require by including transitive dependencies automatically. This feature is facilitated by reading the project files of your dependencies from the remote repositories specified.
Use mvn dependency:analyze
to show you whether there are dependencies in your pom that you don't need (it may also identify some that you have missed, add -DoutputXML=true
to show the missing entries).
Use mvn dependency:tree
to show you the dependencies currently in use by your project and where Maven is finding them. Add -Dverbose=true
to show all the duplicates and conflicts.
If a
directly depends on c
(that is if code in a
mentions classes in c
), then the pom should reflect it. If a
only depends directly on b
, then you can safely remove the c
dependency from a
's pom.xml file. The commands above should enable you to determine what is the appropriate next action.
Edit: Okay, you updated your question. Here is how you do it:
a
, run mvn dependency:tree -Dverbose=true
. This will show you a complete tree of all dependencies considered by Maven for your project.Or are you looking for a way to do it automatically? I do not think there is any automated way unless you write one yourself, because what you are trying to do is a BAD IDEA. You are telling people that their objections are "irrelevant" to your question, but the fact is that your question is like asking "How can I use Maven to make it more difficult to use Maven?"
There is no good reason why you would want to do this. If you think there is a good reason, then you must be trying to do it to produce some result. You should ask for help with the desired result, because your plan is a bad one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With