Expected Behavior
Certain blocks should not be available in nested scopes, for example the top-level dependencies should not be available in Test Suites blocks to prevent confusion with its dependencies.
Current Behavior / Context
In Kotlin DSL, it is easy to do:
testing {
suites {
named("test") { // Should be named<JvmTestSuite>("test")
dependencies {
// Oops, this is the top-level one!
}
}
}
}
This should be a warning or error.
Path to Implementation
Kotlin's @DslMarker seems promising, though we would need to be careful to not overly restrict scopes. It might be possible for us to ask the Kotlin team for more features in this vein to allow us to allow certain functions to be kept.
One issue with @DslMarker that is immediately obvious is that there is no way to access the top-level receiver without saving it in a variable explicitly (val topLevelThis = this before a block). It would be nice if we could define e.g. this@project / this@script / this@build implicitly.
Also, it appears we already have @GradleDsl for marking this, though it isn't widely used.
Expected Behavior
Certain blocks should not be available in nested scopes, for example the top-level
dependenciesshould not be available in Test Suites blocks to prevent confusion with itsdependencies.Current Behavior / Context
In Kotlin DSL, it is easy to do:
testing { suites { named("test") { // Should be named<JvmTestSuite>("test") dependencies { // Oops, this is the top-level one! } } } }This should be a warning or error.
Path to Implementation
Kotlin's
@DslMarkerseems promising, though we would need to be careful to not overly restrict scopes. It might be possible for us to ask the Kotlin team for more features in this vein to allow us to allow certain functions to be kept.One issue with
@DslMarkerthat is immediately obvious is that there is no way to access the top-level receiver without saving it in a variable explicitly (val topLevelThis = thisbefore a block). It would be nice if we could define e.g.this@project/this@script/this@buildimplicitly.Also, it appears we already have
@GradleDslfor marking this, though it isn't widely used.