Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven same dependency on different scopes

Tags:

maven

maven-3

I have a maven (3) project with multiple submodules. One on of them, I want it to explicitly depend on a dependency, without depending on its transitive dependencies. To do this, I'm using the folloing:

<dependency>
  <groupId>org.example</groupId>
  <artifactId>foo</artifactId>
  <version>${project.version}</version>
  <exclusions>
    <exclusion>
      <groupId>*</groupId>
      <artifactId>*</artifactId>
    </exclusion>
  </exclusions>
</dependency>

This works as itended. During runtime, the transitive dependencies of "foo" will already be in the classpath, so everything goes well.

However, I need "foo"'s transitive dependencies for test. I tried to also declare a dependency of "foo" with scope test, but it seems that it conflicts with the one that excludes everything. It either works as expected in tests but fails in runtime, or vice-versa.

Do you known if something like this is possible with maven?

like image 468
halfwarp Avatar asked Mar 31 '26 18:03

halfwarp


1 Answers

Of course it's possible, you need to declare 2 different maven profiles holding your dependencies.

http://maven.apache.org/guides/introduction/introduction-to-profiles.html

Different dependencies for different build profiles in maven

like image 134
Gab Avatar answered Apr 03 '26 17:04

Gab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!