Chad
Chad

Reputation: 2071

Dynamically add project dependency depending on build path when project packaged as jar

I have 2 projects dependency-project, main, support. Currently, main and support requires dependency-project in its build path.

We plan on adding support as another dependency for main. Is there a way to build a jar for support, but not include in it any dependency (from dependency-project) and when support-jar is already added into main, all dependencies of support-jar will be resolved via the classpath of main (since they both have dependency-project as dependency.

Upvotes: 0

Views: 126

Answers (1)

Jatin
Jatin

Reputation: 31724

You can do it as a compile-time scope. For example in pom.xml file for support

<dependency>
    <groupId>org.something</groupId>
    <artifactId>dependency-project</artifactId>
    <version>1.2</version>
    <scope>compile</scope>
</dependency>

And then in pom.xml for main:

<dependency>
    <groupId>org.something</groupId>
    <artifactId>dependency-project</artifactId>
    <version>1.2</version>
</dependency>

<dependency>
    <groupId>org.something</groupId>
    <artifactId>support</artifactId>
    <version>4.2</version>
</dependency>

This should solve your purpose.

Upvotes: 1

Related Questions