Cengiz
Cengiz

Reputation: 4877

Error excluding transitive dependencies in Gradle build file

I have to exlude some dependencies from all modules of a multi module project. With Gradle 1.12 the following gradle build file worked:

subprojects {
    ...
    //blacklisted dependencies
    configurations {
        all*.exclude module: 'ojdbc14' //we use ojdbc6
        all*.exclude group: 'c3p0', module: 'c3p0' //newer versions use groupId: com.mchange
        all*.exclude module: 'oracledb' //we use ojdbc6
        ...
    }
    ...
}

After upgrading to gradle version 2.1 i got error:

You can't change configuration 'providedCompileScope' because it is already resolved!

How to define exclusions now with the newer Gradle?

Upvotes: 0

Views: 316

Answers (2)

Peter Niederwieser
Peter Niederwieser

Reputation: 123960

Exclusions are still specified in the same way. Gradle is just telling you about a problem with your build that it wasn't telling you about before, namely that exclusions can only be declared before a configuration gets resolved. Probably there is some custom code that iterates over configurations.providedCompileScope (or a derived configuration) and mistakenly does so in the configuration phase (i.e. during evaluation of the build scripts), rather than in the execution phase (e.g. inside a task action). This snippet (and the resulting --stacktrace) may help to locate the problematic code:

configurations.providedCompileScope.incoming.beforeResolve { 
    println new Exception("resolved here") 
}

EDIT: If you have something like the following in one of your build scripts:

idea.module {
    scopes.PROVIDED.plus += configurations.providedCompileScope
}

Change it to:

idea.module {
    scopes.PROVIDED.plus += [configurations.providedCompileScope]
}

This is necessary due to a change of behavior in the Groovy version used by Gradle 2.x.

Upvotes: 1

Sean
Sean

Reputation: 179

Normally, I'd exclude transitive dependencies by specifying

dependencies {
    myConfiguration('group:module:version') { transitive = false }
}

For more fine grained control over versions etc, have a look at ResolutionStrategy

Upvotes: 1

Related Questions