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?

2 Answers 2

1

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

Sign up to request clarification or add additional context in comments.

Comments

0

You should check out Maven's <scope>import</scope> dependencies. Create a <profile/> for testing and define a dependency to a pom which contains these test dependencies you're interested in. (This might require some re-working of your pom.xml-s, but would be a good approach).

Check here for more details.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.