Hi Leo,
This is a good question. Would you mind posting it on the new Gradle Forums?
http://forums.gradle.org/
It has much greater visibility to future users there. I'll keep an eye out for
it and respond there when I see it.
On 29/10/2011, at 3:11 AM, Leo Neumeyer wrote:
> I have the following use case:
>
> The compile configuration only needs the API of a dependent library. I use
> transitive = false and works perfectly. I can build my application without
> using transitive dependencies as follows:
>
> dependencies {
>
> libsList.each { module ->
> compile( module ) { transitive = false }
> api( module )
> }
>
> /* Logging. */
> compile( libraries.slf4j )
> compile( libraries.logback_core )
> compile( libraries.logback_classic )
>
> /* Commons. */
> compile( libraries.commons_io )
> compile( libraries.commons_config )
> compile( libraries.commons_coll )
>
> ...
> }
>
> Later in the build script, I need a list all the transitive dependencies for
> those libraries because I don't want to include them in a fat jar.
>
> Couldn't figure out how to get the transitive dependencies in a custom
> configuration. I'm sure there must be a simple way to do this.
>
> Thanks!
> -leo
>
> On Sep 27, 2011, at 1:07 PM, Hans Dockter wrote:
>
>>
>>
>> On Tue, Sep 27, 2011 at 9:42 PM, Adrian Abraham <[email protected]>
>> wrote:
>> I'm working on a fairly significant multiproject build which has many
>> dependencies (both inter-project and 3rd party). For reasons I won't get
>> into, I have to have explicit control over all dependencies used in the
>> project, so I've had to disable transitive dependency resolution for 3rd
>> party libraries.
>>
>> Right now, I'm using
>> allprojects {
>> afterEvaluate {
>> configurations.each { configuration -> configuration.transitive = false }
>> }
>> }
>>
>> You can also use:
>>
>> allprojects {
>> configurations.all {
>> transitive = true
>> }
>> }
>>
>> That will create a rule that sets for all configurations that haven been
>> created or will be created the transitive property to false.
>>
>>
>> Which seems to do the job.
>>
>> Of course, with no transitive dependencies, if my project Foo depends on
>> ReallyCoolLibrary, and my project Bar depends on Foo, then Bar also has to
>> explicitly depend on ReallyCoolLibrary. What I'd love is to find a way to
>> automatically include transitive dependencies as declared by my own projects.
>>
>> Is there a good way to do this?
>>
>> You can also declare transitive dependencies on a per dependency base. So
>> you would not specify rules for configuration construction but for
>> dependency construction:
>>
>> configurations.all {
>> dependencies.all { dep ->
>> if (!(dep instanceof ProjectDependency)) {
>> dep.transitive = false
>> }
>> }
>> }
>>
>> This rule translates to:
>>
>> For the dependencies that have been created or will be created of the
>> configurations that have been created or will be created resolve external
>> dependencies non transitively.
>>
>> Those rules are one of the hidden gems of Gradle. I'm looking forward to see
>> them properly covered in one of the upcoming O'Reilly books by Tim and
>> Matthew.
>>
>> Hans
>>
>> --
>> Hans Dockter
>> Founder, Gradle
>> http://www.gradle.org, http://twitter.com/gradleware
>> CEO, Gradleware - Gradle Training, Support, Consulting
>> http://www.gradleware.com
>>
>>
>>
>>
>
--
Luke Daley
Principal Engineer, Gradleware
http://gradleware.com