Kotlin-dsl-samples: Support excluding transitive dependencies in the dependencies DSL

Created on 28 Jul 2016  路  5Comments  路  Source: gradle/kotlin-dsl-samples

And configuring additional dependency properties in a statically-typed/IDE friendly way:

        dependencies {

            default(group = "org.gradle", name = "foo", version = "1.0") {
                isForce = true
            }

            compile(group = "org.gradle", name = "bar") {
                exclude(module = "foo")
            }

            runtime("org.gradle:baz:1.0-SNAPSHOT") {
                isChanging = true
                isTransitive = false
            }

            testCompile(group = "junit", name = "junit")

            testRuntime(project(path = ":core")) {
                exclude(group = "org.gradle")
            }
        }

The current workaround is to cast the returned dependency to ModuleDependency and call exclude(Map<String, String>) which is not very convenient:

(compile("module-with-transitive-dependencies") as ModuleDependency).apply {
    exclude(mapOf("module" to "excluded-module"))
}

See the relevant section in the user guide.

feature kotlin-dsl-api dependency-support groovy-parity

Most helpful comment

@bamboo Here is something that works and is less code all on 1 line:

 androidTestCompile(extra["mockitoKotlin"] as String) { exclude(group = "net.bytebuddy") }

All 5 comments

@bamboo Has this been updated/fixed?

I still have to use that work around:

  (androidTestCompile(extra["mockitoKotlin"]) as ModuleDependency).apply {
    exclude(mapOf("group" to "net.bytebuddy"))
  }

Instead of what I want to use:

  androidTestCompile(extra["mockitoKotlin"]) { exclude(group = "net.bytebuddy") }

Hi @jaredsburrows, the problem there is that extra["mockitoKotlin"] is not typed as String so the wrong overload is selected (the one which doesn't allow configuring the module dependency. This will work though:

    val mockitoKotlin: String by extra
    compile(mockitoKotlin) {
        exclude(group = "net.bytebuddy")
    }

@bamboo Thanks. Is there anyway to clean this up? To put this on a single line or at least inline val mockitoKotlin: String by extra?

@bamboo For some reason, using String by extra does work either. It does not exclude the transitive dependency that I need excluded:

$ gradlew
WARNING: Conflict with dependency 'org.mockito:mockito-core' in project 'android-gif-example'. Resolved versions for app (2.8.9) and test app (2.8.47) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
WARNING: Conflict with dependency 'org.mockito:mockito-core' in project 'android-gif-example'. Resolved versions for app (2.8.9) and test app (2.8.47) differ. See http://g.co/androidstudio/app-test-app-conflict for details.
WARNING: Conflict with dependency 'org.mockito:mockito-core' in project 'android-gif-example'. Resolved versions for app (2.8.9) and test app (2.8.47) differ. See http://g.co/androidstudio/app-test-app-conflict for details.

Build cache is an incubating feature.

> Task :help

Welcome to Gradle 4.1-rc-1.

To run a build, run gradlew <task> ...

To see a list of available tasks, run gradlew tasks

To see a list of command-line options, run gradlew --help

To see more detail about a task, run gradlew help --task <task>


BUILD SUCCESSFUL in 1s
1 actionable task: 1 executed

@bamboo Here is something that works and is less code all on 1 line:

 androidTestCompile(extra["mockitoKotlin"] as String) { exclude(group = "net.bytebuddy") }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

deeprim picture deeprim  路  4Comments

jmfayard picture jmfayard  路  3Comments

jaredsburrows picture jaredsburrows  路  3Comments

wuchengithub picture wuchengithub  路  4Comments

IgorAufricht picture IgorAufricht  路  3Comments