How do I mark a transitive dependency explicitly as 'compile', without redeclaring the dependency itself?


(getsatisfaction) #1

I have a dependency A

compile “org.group:A:version”

which has a transitive dependency B.

Because we set

compile.transitive = false

the transitive dependency is not in the ‘compile’ configuration.

How can I mark ‘B’ as ‘compile’, without explicitly defining the dependency again?


(Peter Niederwieser) #2

I don’t understand the question. Can you elaborate?


(getsatisfaction) #3

I hope I’m using the correct terms here.

There are different configurations which influence the classpaths. We have 'compile‘, ‘testCompile’, ‘providedCompile’ etc.

When I define a dependency:

compile “org.glassfish.jersey.core:jersey-server:$JERSEY_2_VERSION”

all transitive dependencies this has are not in the ‘compile’ configuration. That’s because we set this:

configurations {

compile.transitive = false

}

But now I need Jersey’s transitive dependency on HK2 to be in the ‘compile’ configuration. (because it needs to be on the classpath while compiling and the Gradle IDEA plugin marks everything that is not ‘compile’ as ‘runtime’ and so in our IDE it doesn’t compile).

Now my workaround is this:

compile “org.glassfish.hk2:hk2-api:$HK2_VERSION”

By explicitly defining the dependency it is in ‘compile’. BUT now I need to specify the version of HK2 explicitly as well. But I don’t want to do that. I want the version that Jersey requires.

So I want to put the HK2 dependency in the ‘compile’ configuration without re-defining the complete dependency with its version.


(Peter Niederwieser) #4

That’s not something that’s currently supported. If you turn off transitive resolution, you need to fully specify any transitive dependencies yourself. Alternatively, you can leave transitive resolution on, and exclude selected transitive dependencies by group or module name.


(getsatisfaction) #5

Thanks for the clarification. And the fast response :slight_smile: