Skip to content

Commit 8703b50

Browse files
committed
fix(rider): Restore rd-gen model generation for both 2025.3 and 2026.1
Commit 292181d removed hashFolder, classpath, and sources from the RdGenExtension config to accommodate rd-gen 2026.1 API changes, but this broke the 2025.3 build and left 2026.1 model generation non- functional. For pre-2026 profiles, restore the extension properties via reflection to avoid script compilation failures when the 2026.1 rd-gen jar is on the buildscript classpath. For 2026.1+, add a compileModelSources task that pre-compiles model sources with an external Kotlin compiler, since rd-gen 2026.1 removed its built-in Kotlin compilation support.
1 parent 566a023 commit 8703b50

File tree

1 file changed

+43
-3
lines changed

1 file changed

+43
-3
lines changed

plugins/toolkit/jetbrains-rider/build.gradle.kts

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,56 @@ val rdModelJarFile: File by lazy {
136136
configure<RdGenExtension> {
137137
verbose = true
138138
packages = "model"
139+
140+
if (!ideProfile.name.startsWith("2026")) {
141+
// rd-gen pre-2026 compiles sources internally and requires these extension properties
142+
javaClass.getMethod("setHashFolder", String::class.java).invoke(this, rdgenDir.toString())
143+
javaClass.getMethod("classpath", Array<Any>::class.java).invoke(this, arrayOf<Any>({ rdModelJarFile }))
144+
javaClass.getMethod("sources", Array<Any>::class.java).invoke(this, arrayOf<Any>(projectDir.resolve("protocol/model")))
145+
}
146+
}
147+
148+
// Pre-compile model sources for rd-gen 2026.1+ which no longer has built-in Kotlin compilation
149+
val compiledModelsDir = File("$nonLazyBuildDir/rdgen/compiled-models")
150+
val compileModelSources = if (ideProfile.name.startsWith("2026")) {
151+
val kotlinCompilerConfig = configurations.detachedConfiguration(
152+
dependencies.create("org.jetbrains.kotlin:kotlin-compiler-embeddable:${libs.versions.kotlin.get()}")
153+
)
154+
155+
tasks.register<JavaExec>("compileModelSources") {
156+
group = protocolGroup
157+
description = "Compiles RD model sources for rd-gen 2026.1+"
158+
159+
mainClass.set("org.jetbrains.kotlin.cli.jvm.K2JVMCompiler")
160+
classpath(kotlinCompilerConfig)
161+
162+
val rdGenClasspath = project.buildscript.configurations.getByName("classpath")
163+
args(
164+
"-cp", (rdGenClasspath.files + rdModelJarFile).joinToString(File.pathSeparator),
165+
"-d", compiledModelsDir.absolutePath,
166+
"-jvm-target", "21",
167+
modelDir.absolutePath
168+
)
169+
170+
inputs.dir(modelDir)
171+
outputs.dir(compiledModelsDir)
172+
}
173+
} else {
174+
null
139175
}
140176

141177
// TODO: migrate to official rdgen gradle plugin https://www.jetbrains.com/help/resharper/sdk/Rider.html#plugin-project-jvm
142178
val generateModels = tasks.named<JavaExec>("generateModels") {
143179
group = protocolGroup
144180
description = "Generates protocol models"
145181

146-
// rd-gen 2026.1+ only adds rd-* jars to classpath, missing kotlin-stdlib
147-
classpath(project.buildscript.configurations.getByName("classpath"))
148-
classpath(rdModelJarFile)
182+
if (ideProfile.name.startsWith("2026")) {
183+
// rd-gen 2026.1+ only adds rd-* jars to classpath, missing kotlin-stdlib
184+
compileModelSources?.let { dependsOn(it) }
185+
classpath(project.buildscript.configurations.getByName("classpath"))
186+
classpath(rdModelJarFile)
187+
classpath(File("$nonLazyBuildDir/rdgen/compiled-models"))
188+
}
149189

150190
inputs.dir(file("protocol/model"))
151191

0 commit comments

Comments
 (0)