Also, is there a Kotlin DSL equivalent for excludi...
# gradle
i
Also, is there a Kotlin DSL equivalent for excluding transitive dependencies for a particular configuration? https://docs.gradle.org/current/userguide/managing_transitive_dependencies.html#example_excluding_transitive_dependency_for_a_particular_configuration The migration guide seems to imply it should be possible: https://guides.gradle.org/migrating-build-logic-from-groovy-to-kotlin/#configurations-and-dependencies ...but when I try:
Copy code
configurations {
	testImplementation {

	}
}
...I get:
Copy code
Script compilation error:

  Line 21: 	testImplementation {
            ^ Unresolved reference. None of the following candidates is applicable because of receiver type mismatch: 
                public inline fun <T : ModuleDependency> DependencyHandler.testImplementation(dependency: TypeVariable(T), dependencyConfiguration: TypeVariable(T).() -> Unit): TypeVariable(T) defined in org.gradle.kotlin.dsl
                public fun DependencyHandler.testImplementation(dependencyNotation: Any): Dependency? defined in org.gradle.kotlin.dsl
                public fun DependencyHandler.testImplementation(group: String, name: String, version: String? = ..., configuration: String? = ..., classifier: String? = ..., ext: String? = ...): ExternalModuleDependency defined in org.gradle.kotlin.dsl
                public inline fun DependencyHandler.testImplementation(group: String, name: String, version: String? = ..., configuration: String? = ..., classifier: String? = ..., ext: String? = ..., dependencyConfiguration: ExternalModuleDependency.() -> Unit): ExternalModuleDependency defined in org.gradle.kotlin.dsl
                public inline fun DependencyHandler.testImplementation(dependencyNotation: String, dependencyConfiguration: ExternalModuleDependency.() -> Unit): ExternalModuleDependency defined in org.gradle.kotlin.dsl

1 error
g
testImplementation is dynamic, you need something like configurations["testImplementation"]
Migration guide also have another syntax (check your link): use delegation to retrieve configuration:
Copy code
val testImplementation by configurations
i
Hmm, okay, so the following seem to work then:
Copy code
configurations {
	"testImplementation" {
		exclude(group = "org.foo")
	}
}
Copy code
configurations {
	getByName("implementation") {
		exclude(group = "org.foo")
	}
}
Copy code
configurations["testImplementation"].apply {
	exclude(group = "org.foo")
}
Copy code
val testImplementation by configurations
testImplementation.apply {
	exclude(group = "org.foo")
}
It's just that I'm applying the Kotlin plugin declaratively in the
plugins {}
block:
Copy code
plugins {
	kotlin("jvm") version "1.2.70"
}
...and the guide says:
Each configuration contributed by an applied plugin is also available as a member of the configurations container, so you can reference it just like any other configuration.
Knowing what configurations are available
The easiest way to find out what configurations are available is by asking your IDE for suggestions within the configurations container.
You can also use the
:kotlinDslAccessorsReport
task, which prints the Kotlin code for accessing the configurations contributed by applied plugins and provides the names for all of those accessors.
...and the
:kotlinDslAccessorsReport
task prints:
Copy code
/**
 * The 'testImplementation' configuration.
 */
val ConfigurationContainer.`testImplementation`: Configuration
    get() = getByName("testImplementation")
...so I was naively expecting the
testImplementation
, etc. extension properties to be statically available in the
configurations {}
block (as they are in
dependencies {}
):
Copy code
configurations {
	testImplementation {
		exclude(group = "org.foo")
	}
}
I see with Quick Documentation that
dependencies
has a Kotlin DSL
Project
extension function:
org.gradle.kotlin.dsl ProjectExtensionsKt.class
public fun Project.dependencies(
configuration: DependencyHandlerScope.() → Unit
): Unit
...whereas
configurations
does not:
org.gradle.api.Project
public abstract org.gradle.api.artifacts.ConfigurationContainer getConfigurations()
Is this by design, and if so, is it not possible to add similar DSL support for the
configurations {}
block as for
dependencies {}
?
e
Your reasoning is good @ianbrandt, could you please open an issue on
gradle/kotlin-dsl
about this?
👍 1
i
e
Thank you!
👍 1
129 Views