plugins {
groovy
`java-gradle-plugin`
}
gradlePlugin {
// unresolved reference. How do I configure this thing ??
}
Do I need to do some kind of project.extensions.getByType() or delegateClosureOf<SomeClassFromWithinThePlugin> thing to get access to the DSL added by the java-gradle-plugin extension?
You would use configure<> for plugin extensions. Use the fully qualified class name (or imports), at least for non-core classes. Your equivalent Kotlin build script could look like this:
This is not necessary with the latest Kotlin DSL version. What @Sam1 wrote should just work. Please make sure you are using both the latest Kotlin DSL as well as the latest Kotlin plugin for IntelliJ.
Thanks @jjustinic, that works! Although the syntax isn’t as terse/pretty as I’d hoped after seeing all the great presentations on Kotlin at the Gradle Summit. Rummaging through a plugin’s source to identify which class(es) are applies as extensions isn’t ideal.
@st_oehme, The command line and IntelliJ are in agreement that “gradlePlugin” is an “unresolved reference”.
I’m using the release version of Gradle 4.0 and have not specified anything anything about kotlin except appending ‘.kts’ the name of my build file. A build scan shows that I’m using the version of the Kotlin DSLs that comes with Gradle itself. Is it possible to specify a different version of the Kotlin DSLs without changing to a pre-release version of Gradle?
The Kotlin DSL repo’s documentation shows the Configure<Class> syntax and the samples I’ve looked at all use a pre-release version of Gradle (gradle-kotlin-dsl-4.1-20170707032407+0000-all.zip, in the linked example).
If there’s a way to opt-in to the latest release versions of the Kotlin DSLs without having to use pre-release Gradle I’d love to try it out!
The syntax that would require auto-generated accessors starts working for me as of gradle-kotlin-dsl-4.1-20170617005006+0000-bin.zip, which shows to be a snapshot of gradle-kotlin-dsl 0.10.0. According to core, 0.9.0 shipped with 4.0, and 0.9.1 is the latest in master, so it doesn’t look like there’s a published combo of released versions that can support this out of the box quite yet.
I have no knowledge of the actual release plans, but from the commit history, Gradle 4.0 -> 4.1 provides the Kotlin DSL 0.9.0 -> 0.9.1 update currently. The master branch is already for Gradle 4.2. I would hold off getting your hopes up for Gradle 4.1 until the update to 0.10.+ is committed (or there proves to be an easy opt-in to newer Kotlin DSL versions like you asked about).
The version shipped with Gradle 4.0 was 0.9.1 which already supported auto-generated accessors except they need to be explicitly enabled via a Gradle property.
Also, good job on your presentations on Gradle + Kotlin at the Gradle Summit, Rodrigo! I enjoyed them - enough to give Kotlin buildscripts a try in the first place.