I have seen the modularity example here: https://github.com/gradle/kotlin-dsl/tree/master/samples/modularity.
With the current Groovy DSL, you can apply plugins in other *gradle files. For instance, I can apply this gradle file: https://github.com/jaredsburrows/android-gif-example/blob/master/gradle/scan.gradle in the main build.gradle here: https://github.com/jaredsburrows/android-gif-example/blob/master/build.gradle.kts#L34.
If I convert scan.gradle to Kotlin DSL, it no longer works and gives me errors.
Using extensions from script plugins is not yet supported. See #432.
As a workaround until this is fixed properly, you can apply the plugin dynamically.
IE rather than
plugins {
`maven-publish`
}
publishing {
repositories { }
}
You can do:
apply {
plugin("org.gradle.maven-publish")
}
extensions["publishing"].closureOf<PublishingExtension> {
repositories { }
}
Not ideal, but seems to work. Keen to hear any better solutions.
Here's a nicer workaround, basically doing the same with less code:
apply(plugin = "maven-publish")
configure<PublishingExtension> {
repositories { ... }
}
Most helpful comment
Here's a nicer workaround, basically doing the same with less code: