Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 907
Pranav Kevadiya Avatar asked Feb 19 '15 16:02

Pranav Kevadiya


People also ask

What is configurations in build Gradle?

A “configuration” is a named grouping of dependencies. A Gradle build can have zero or more of them. A “repository” is a source of dependencies. Dependencies are often declared via identifying attributes, and given these attributes, Gradle knows how to find a dependency in a repository.

What is default configuration in Gradle?

The default configuration extends from the runtime configuration, which means that it contains all the dependencies and artifacts of the runtime configuration, and potentially more. You can add dependencies and artifacts in the usual way (using a dependencies / artifacts block in B's build script).

What is Gradle properties used for?

Gradle project properties provide an easy way to customise builds which may need to run differently in certain situations. In this article you'll learn the most effective ways to use and set properties, along with some common scenarios you might come across in your Gradle project.


Video Answer


1 Answers

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.

like image 105
Invisible Arrow Avatar answered Oct 09 '22 10:10

Invisible Arrow