Kotlin-dsl-samples: Script plugins can use the plugins DSL to define their dependencies on arbitrary plugins

Created on 20 Jul 2017  Â·  5Comments  Â·  Source: gradle/kotlin-dsl-samples

The dependencies of a script plugin are currently completely hidden from the projects that apply them. That’s because “apply from:” statements are discovered only after the classpath of a project’s buildscript is already set up.

A very common pattern is applying a community plugin, pre-configuring it, but still giving projects the choice to further configure the community plugin. This “kind of works” with Groovy, because of its dynamic nature. As long as you don’t try to reference the types of the community plugin, you can still configure its extensions and tasks. However, this is not an option for statically typed Kotlin.

The following should work:

// bar.gradle.kts

plugins {
  id("foo.plugin.id") version "2.0"
}

// build.gradle.kts
plugins {
  script("bar.gradle.kts")
}

fooExtension { // contributed by "foo.plugin.id", a dependency of bar.gradle.kts
  //some more specific, statically typed configuration
}
feature gradle-api plugin-support dropped

Most helpful comment

Why this was dropped? Of course, precompiled script plugins solve problems, but require unnecessary buildSrc dir with settings.gradle and build.gradle and src/main/kotlin dir

All 5 comments

The script("...") seems not to be available in current versions.

@guenhter It is not.

Ah, sorry. I get you now. This should be done with this ticket.
Looking forward to this!

Also looking forward to this. This is a huge piece of the puzzle for applied script plugins.

Why this was dropped? Of course, precompiled script plugins solve problems, but require unnecessary buildSrc dir with settings.gradle and build.gradle and src/main/kotlin dir

Was this page helpful?
0 / 5 - 0 ratings