Closed jjtParadox closed 7 years ago
Groovy and Scala functionality is built into Gradle via the groovy
and scala
plugins. Both of these plugins are part of the default gradle distribution just like the java
plugin, and dont require any extra dependencies.
Kotlin on the other hand has its own Gradle plugin that you need to get. To avoid an extra dependency at built time that the majority of modders dont use, I didnt include support for Kotlin, Clojure or any of the other possible languages that could be used on the JVM.
You could however put a roughly equivalent piece of code into your own build.gradle: disclaimer, I just wrote this off the top of my head, take with a grain of salt
import net.minecraftforge.gradle.user.TaskSourceCopy;
task sourceMainKotlin(type: TaskSourceCopy) {
source = sourceSets.main.kotlin
output = file("build/sources/kotlin")
}
// assuming this is the kotlin compile task name
compileKotlin {
dependsOn sourceMainKotlin
source = file('build/sources/kotlin')
}
Yes this will automatically grab the replacements specified in the minecraft{}
block.
As far as I can tell, your snippet should work, but something in Kotlin's gradle plugin is causing the source defined in compileKotlin
to be appended to the list of sources, not replacing it as it should. This causes Kotlin to double-compile everything, which then errors everything with "this has already been declared" junk.
This obviously isn't an issue with ForgeGradle, but if anyone stumbles across this issue they should know that as of right now something with Kotlin's gradle plugin is preventing a simple fix like the snippet above. Just stick with a Java file of constants.
An earlier version of the Kotlin gradle plugin didn't have this issue, at the time I wrote something similar to Abrar's code, only more generic. I thought FG added something to enable the replacement until I noticed that they still didn't take effect. Turns out you have to also modify the in- and exclude list of the compile task in order to make it only grab the files form the build/sources
directory. I've implemented a general purpose solution (for all source sets) here: build.gradle. I wasn't able to get the includes working with a normal path spec, if anybody knows why, please enlighten me :D
The functions
replace
andreplaceIn
in theminecraft
block do not appear to operate on the Kotlin source set. Everything compiles and runs just fine, but tokens in source files are not changed as they are supposed to be. Replacing a Kotlin file with the equivalent Java file is a workaround but isn't preferred.I believe Kotlin may need a section declared here similar to how Java, Scala, and Groovy are declared.
Otherwise, is there a way I can fit a fix into my build.gradle so I can avoid jumping between Java source and Kotlin source?