3

Newly exposed to Maven, I can understand the use case of the <exclusion> tag, but not sure why it wouldn't cause compile error:

<dependencies>
<dependency>
  <groupId>org.apache.maven</groupId>
  <artifactId>maven-embedder</artifactId>
  <version>2.0</version>
  <exclusions>
    <exclusion>
      <groupId>org.apache.maven</groupId>
      <artifactId>maven-core</artifactId>
    </exclusion>
  </exclusions>
</dependency>
...

Is this only possible only when you have another direct dependency on maven-core? otherwise, compile error should happen. (assuming maven-core is used somewhere in maven-embedder)

J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
sthbuilder
  • 561
  • 1
  • 7
  • 22

3 Answers3

2

You are excluding that artifact from that specific dependency, but it could be getting pulled in from another dependency. Using something mvn dependency:tree -Dverbose -Dincludes=maven-core should show you what else is introducing the dependency. The Maven Enforcer plugin can also help exclude transitive dependencies.

Carl
  • 1,253
  • 9
  • 23
1

There are different possibilities:

  1. As Carl said: Check your dependency:tree if the dependency is not pulled in from somewhere else.
  2. It is possible that maven-core is not used at all, even if maven-embedder indeed uses it: Assume e.g. that maven-embedder has two classes A and B. You only use A, but maven-core is only used by B. Then (if A and B do not use each other), your project might be entirely independent of maven-core. (A side remark: some jars should logically be two separate jars, but where merged together by whatever reason - in our example, one should think about putting A and B in separate artifacts).
  3. It is possible that transitive dependencies are not necessary at compile time, but are used at runtime.
J Fabian Meier
  • 33,516
  • 10
  • 64
  • 142
0

The error will not thrown in the compile time, It will thrown in run time if you use any feature depends on maven-core

Fady Saad
  • 1,169
  • 8
  • 13