Skip to content

Commit 0fe3351

Browse files
committed
kotlin support
1 parent 6699eba commit 0fe3351

File tree

1 file changed

+59
-15
lines changed

1 file changed

+59
-15
lines changed

build.gradle

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ plugins {
3030
id 'com.diffplug.spotless' version '6.13.0' apply false
3131
id 'com.palantir.git-version' version '3.0.0' apply false
3232
id 'com.github.johnrengelman.shadow' version '8.1.1' apply false
33+
id 'org.jetbrains.kotlin.jvm' version '1.8.0' apply false
34+
id 'org.jetbrains.kotlin.kapt' version '1.8.0' apply false
35+
id 'com.google.devtools.ksp' version '1.8.0-1.0.9' apply false
3336
}
3437

3538
def out = services.get(StyledTextOutputFactory).create('an-output')
@@ -86,24 +89,25 @@ propertyDefaultIfUnsetWithEnvVar("deploymentDebug", false, "DEPLOYMENT_DEBUG")
8689

8790
final String javaSourceDir = 'src/main/java/'
8891
final String scalaSourceDir = 'src/main/scala/'
89-
// If Kotlin is supported, add the path here
92+
final String kotlinSourceDir = 'src/main/kotlin/'
9093

9194
final String modGroupPath = modGroup.toString().replace('.' as char, '/' as char)
9295
final String apiPackagePath = apiPackage.toString().replace('.' as char, '/' as char)
9396

9497
String targetPackageJava = javaSourceDir + modGroupPath
9598
String targetPackageScala = scalaSourceDir + modGroupPath
96-
// If Kotlin is supported, add the path here
99+
String targetPackageKotlin = kotlinSourceDir + modGroupPath
97100

98-
if (!getFile(targetPackageJava).exists() && !getFile(targetPackageScala).exists()) {
99-
throw new GradleException("Could not resolve \"modGroup\"! Could not find ${targetPackageJava} or ${targetPackageScala}")
101+
if (!getFile(targetPackageJava).exists() && !getFile(targetPackageScala).exists() && !getFile(targetPackageKotlin).exists()) {
102+
throw new GradleException("Could not resolve \"modGroup\"! Could not find ${targetPackageJava} or ${targetPackageScala} or ${targetPackageKotlin}")
100103
}
101104

102105
if (apiPackage) {
103106
targetPackageJava = javaSourceDir + modGroupPath + '/' + apiPackagePath
104107
targetPackageScala = scalaSourceDir + modGroupPath + '/' + apiPackagePath
105-
if (!getFile(targetPackageJava).exists() && !getFile(targetPackageScala).exists()) {
106-
throw new GradleException("Could not resolve \"apiPackage\"! Could not find ${targetPackageJava} or ${targetPackageScala}")
108+
targetPackageKotlin = kotlinSourceDir + modGroupPath + '/' + apiPackagePath
109+
if (!getFile(targetPackageJava).exists() && !getFile(targetPackageScala).exists() && !getFile(targetPackageKotlin).exists()) {
110+
throw new GradleException("Could not resolve \"apiPackage\"! Could not find ${targetPackageJava} or ${targetPackageScala} or ${targetPackageKotlin}")
107111
}
108112
}
109113

@@ -125,8 +129,9 @@ if (usesMixins.toBoolean()) {
125129
final String mixinPackagePath = mixinsPackage.toString().replaceAll('\\.', '/')
126130
targetPackageJava = javaSourceDir + modGroupPath + '/' + mixinPackagePath
127131
targetPackageScala = scalaSourceDir + modGroupPath + '/' + mixinPackagePath
128-
if (!getFile(targetPackageJava).exists()) {
129-
throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find ${targetPackageJava} or ${targetPackageScala}")
132+
targetPackageKotlin = kotlinSourceDir + modGroupPath + '/' + mixinPackagePath
133+
if (!getFile(targetPackageJava).exists() && !getFile(targetPackageScala).exists() && !getFile(targetPackageKotlin).exists()) {
134+
throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find ${targetPackageJava} or ${targetPackageScala} or ${targetPackageKotlin}")
130135
}
131136
}
132137

@@ -135,8 +140,9 @@ if (coreModClass) {
135140
String targetFileJava = javaSourceDir + modGroupPath + '/' + coreModPath + '.java'
136141
String targetFileScala = scalaSourceDir + modGroupPath + '/' + coreModPath + '.scala'
137142
String targetFileScalaJava = scalaSourceDir + modGroupPath + '/' + coreModPath + '.java'
138-
if (!getFile(targetFileJava).exists() && !getFile(targetFileScala).exists() && !getFile(targetFileScalaJava).exists()) {
139-
throw new GradleException("Could not resolve \"coreModClass\"! Could not find " + targetFileJava)
143+
String targetFileKotlin = kotlinSourceDir + modGroupPath + '/' + coreModPath + '.kt'
144+
if (!getFile(targetFileJava).exists() && !getFile(targetFileScala).exists() && !getFile(targetFileScalaJava).exists() && !getFile(targetFileKotlin).exists()) {
145+
throw new GradleException("Could not resolve \"coreModClass\"! Could not find ${targetFileJava} or ${targetFileScala} or ${targetFileScalaJava} or ${targetFileKotlin}")
140146
}
141147
}
142148

@@ -148,6 +154,36 @@ if (getFile('src/main/scala').exists()) {
148154
apply plugin: 'scala'
149155
}
150156

157+
if (getFile('src/main/kotlin').exists()) {
158+
apply plugin: 'org.jetbrains.kotlin.jvm'
159+
}
160+
161+
// Kotlin
162+
pluginManager.withPlugin('org.jetbrains.kotlin.jvm') {
163+
kotlin {
164+
jvmToolchain(8)
165+
}
166+
def disabledKotlinTaskList = [
167+
"kaptGenerateStubsMcLauncherKotlin",
168+
"kaptGenerateStubsPatchedMcKotlin",
169+
"kaptGenerateStubsInjectedTagsKotlin",
170+
"compileMcLauncherKotlin",
171+
"compilePatchedMcKotlin",
172+
"compileInjectedTagsKotlin",
173+
"kaptMcLauncherKotlin",
174+
"kaptPatchedMcKotlin",
175+
"kaptInjectedTagsKotlin",
176+
"kspMcLauncherKotlin",
177+
"kspPatchedMcKotlin",
178+
"kspInjectedTagsKotlin",
179+
]
180+
tasks.configureEach { task ->
181+
if (task.name in disabledKotlinTaskList) {
182+
task.enabled = false
183+
}
184+
}
185+
}
186+
151187
// Spotless
152188
//noinspection GroovyAssignabilityCheck
153189
project.extensions.add(com.diffplug.blowdryer.Blowdryer, 'Blowdryer', com.diffplug.blowdryer.Blowdryer) // make Blowdryer available in plugin application
@@ -420,25 +456,25 @@ configurations {
420456
}
421457
}
422458

459+
String mixinProviderSpec = 'zone.rong:mixinbooter:8.3'
423460
dependencies {
424-
String mixin = 'zone.rong:mixinbooter:8.3'
425461
if (usesMixins.toBoolean()) {
426462
annotationProcessor 'org.ow2.asm:asm-debug-all:5.2'
427463
// should use 24.1.1 but 30.0+ has a vulnerability fix
428464
annotationProcessor 'com.google.guava:guava:30.0-jre'
429465
// should use 2.8.6 but 2.8.9+ has a vulnerability fix
430466
annotationProcessor 'com.google.code.gson:gson:2.8.9'
431467

432-
mixin = modUtils.enableMixins(mixin, "mixins.${modId}.refmap.json")
433-
api (mixin) {
468+
mixinProviderSpec = modUtils.enableMixins(mixinProviderSpec, "mixins.${modId}.refmap.json")
469+
api (mixinProviderSpec) {
434470
transitive = false
435471
}
436472

437-
annotationProcessor(mixin) {
473+
annotationProcessor(mixinProviderSpec) {
438474
transitive = false
439475
}
440476
} else if (forceEnableMixins.toBoolean()) {
441-
runtimeOnly(mixin)
477+
runtimeOnly(mixinProviderSpec)
442478
}
443479

444480
if (enableJUnit.toBoolean()) {
@@ -478,6 +514,14 @@ dependencies {
478514
}
479515
}
480516

517+
pluginManager.withPlugin('org.jetbrains.kotlin.kapt') {
518+
if (usesMixins.toBoolean()) {
519+
dependencies {
520+
kapt(mixinProviderSpec)
521+
}
522+
}
523+
}
524+
481525
if (getFile('dependencies.gradle').exists()) {
482526
apply from: 'dependencies.gradle'
483527
} else if (getFile('dependencies.gradle.kts').exists()) {

0 commit comments

Comments
 (0)