On Tue, Sep 27, 2011 at 9:42 PM, Adrian Abraham <adr...@shadowspire.net>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

Reply via email to