Kotlin-dsl-samples: How to apply plugins with modularity?

Created on 1 Aug 2017  路  3Comments  路  Source: gradle/kotlin-dsl-samples

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.

question kotlin-dsl-plugins duplicate

Most helpful comment

Here's a nicer workaround, basically doing the same with less code:

apply(plugin = "maven-publish")
configure<PublishingExtension> {
    repositories { ... }
}

All 3 comments

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 { ... }
}
Was this page helpful?
0 / 5 - 0 ratings