Pranav Kevadiya
Pranav Kevadiya

Reputation: 539

The actual use of custom configurations in gradle

I am new to gradle and struggling with a basic problem. I have a set of compile time dependencies declared in my project. My problem statement is, I want to make a subset of dependencies non transitive and the remaining transitive.

I have tried to make a custom configuration which extends from compile and set its transitive property to false.

Customcompile.extendsFrom(compile)
Customcompile.transitive = false

By this, I assume that whatever I declare with Customcompile 'xxx:xxx:1.0' will have transitive=false applied and that it will act as compile time dependency.

But this is not able to compile my project with these dependencies

Am I wrong anywhere in this assumption?

Upvotes: 14

Views: 19839

Answers (1)

Invisible Arrow
Invisible Arrow

Reputation: 4905

You need to change customCompile.extendsFrom(compile) to compile.extendsFrom(customCompile).

configurations {
    customCompile
    customCompile.transitive = false
    compile.extendsFrom(customCompile)
}

This is because the compilation classpath is derived from the dependencies for the compile configuration.

By making compile configuration extend from customCompile configuration, you are now including all dependencies from customCompile configuration into compile configuration.

Upvotes: 36

Related Questions