https://kotlinlang.org logo
#getting-started
Title
# getting-started
j

James Hendry

01/11/2022, 3:13 PM
Hi everyone, I hope this is an appropriate place to ask about the use of kotlin gradle (build.gradle.kts). Im having trouble moving from groovy to kotlin. I've put my original build.gradle and attempt at the new one https://gist.github.com/tyhdefu/0cdf5428be7699a8bb7ef7fa97e278b7
j

Joffrey

01/11/2022, 3:36 PM
Maybe this would fit the #gradle channel. As for your question, do you have these errors in the IDE only or when running gradle from command line too?
v

Vampire

01/11/2022, 3:47 PM
You are applying the plugin the legacy way instead of using the recommended
plugins
dsl. If you apply using the legacy way, then no accessors are generated for applied plugins, so there is no
minecraft
accessor that you could use. The recommendation is, that you use the
plugins
dsl to apply the plugin, because then you get for Koltin DSL build scripts and precompiled script plugins accessors generated for extensions added by those plugins. If you for whatever reason insist on using the legacy way to apply the plugin, then you need to use the uglier verbose syntax like
Copy code
configure<MinecraftExtension> {
    ...
}
or whatever the class name of that extension is.
👍 2
j

Joffrey

01/11/2022, 3:51 PM
If you apply using the legacy way, then no accessors are generated for applied plugins, so there is no 
minecraft
 accessor that you could use.
TIL that this doesn't only apply to the IDE 😄 thanks
j

James Hendry

01/11/2022, 5:30 PM
Thanks very much. For some reason I can't get the plugins DSL to work, which I think is mostly the gradle creator not conforming to the standards which make it break, but I have successfully achieved the same result by using the legacy one.
v

Vampire

01/11/2022, 6:41 PM
Yeah, I had a quick look, they are doing dirty evil stuff that makes it incompatible with plugins DSL. You should report that as noone did yet as far as I can see. The plugin requires the extension to be configured in a certain way and the plugins DSL requires that the plugin does not require that. Because the plugins block is extracted and applied to a dummy project to find which extensions are added to the project to be able to generate the accessors for the Kotlin DSL.
Btw., either
Copy code
apply(plugin = "net.minecraftforge.gradle")

configure<MinecraftExtension> {
    mappings("official", "1.18.1")
}

val minecraft by configurations.getting
dependencies {
    minecraft("net.minecraftforge:forge:1.18.1-39.0.14")
}
or
Copy code
apply(plugin = "net.minecraftforge.gradle")

configure<MinecraftExtension> {
    mappings(mapOf("channel" to "official", "version" to "1.18.1"))
}

val minecraft by configurations.getting
dependencies {
    minecraft("net.minecraftforge:forge:1.18.1-39.0.14")
}
is what you want
4 Views