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

I have a dependency A

compile “”

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?

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

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.

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.

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