Skip to content

Commit 74ba48d

Browse files
1.29.1: support Gradle 8.13
1 parent 811916e commit 74ba48d

File tree

5 files changed

+93
-3
lines changed

5 files changed

+93
-3
lines changed

CHANGELOG.md

+10
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
33
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
6+
## 1.29.1
7+
8+
### Fixed
9+
10+
- Exception on Gradle 8.13:
11+
```
12+
java.lang.NoSuchMethodError: 'org.gradle.jvm.toolchain.internal.SpecificInstallationToolchainSpec org.gradle.jvm.toolchain.internal.SpecificInstallationToolchainSpec.fromJavaExecutable(org.gradle.api.model.ObjectFactory, java.lang.String)'
13+
```
14+
515
## 1.29.0
616

717
- `MpsCheck`, `MpsGenerate`, `MpsExecute`: put MPS jars at the beginning of the classpath of the corresponding backends,

build.gradle.kts

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ plugins {
2424
id("org.jetbrains.kotlinx.binary-compatibility-validator") version "0.13.2"
2525
}
2626

27-
val baseVersion = "1.29.0"
27+
val baseVersion = "1.29.1"
2828

2929
group = "de.itemis.mps"
3030

src/main/kotlin/de/itemis/mps/gradle/downloadJBR/Tasks.kt

+4-2
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ import java.io.File
1414
import javax.inject.Inject
1515

1616
open class DownloadJbrForPlatform @Inject constructor(
17-
private val objects: ObjectFactory,
17+
objects: ObjectFactory,
1818
private val javaToolchainService: JavaToolchainService
1919
) : DefaultTask() {
2020

21+
private val toolchainSpecFactory = objects.newInstance(ToolchainSpecFactory::class.java)
22+
2123
@get:Internal
2224
internal val jbrDirProperty: DirectoryProperty = objects.directoryProperty()
2325

@@ -44,7 +46,7 @@ open class DownloadJbrForPlatform @Inject constructor(
4446
*/
4547
@get:Internal
4648
val toolchainSpec: Provider<JavaToolchainSpec> =
47-
javaExecutableProperty.map { SpecificInstallationToolchainSpec.fromJavaExecutable(objects, it.asFile.path) }
49+
javaExecutableProperty.map { toolchainSpecFactory.fromJavaExecutable(it.asFile.path) }
4850

4951
/**
5052
* A [JavaLauncher] for the downloaded JBR that can be used with [JavaExec] task.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package de.itemis.mps.gradle.downloadJBR
2+
3+
import org.gradle.api.internal.provider.PropertyFactory
4+
import org.gradle.api.model.ObjectFactory
5+
import org.gradle.jvm.toolchain.internal.SpecificInstallationToolchainSpec
6+
import javax.inject.Inject
7+
8+
internal abstract class ToolchainSpecFactory {
9+
@get:Inject
10+
abstract val propertyFactory: PropertyFactory
11+
12+
val method813 = try {
13+
SpecificInstallationToolchainSpec::class.java.getMethod("fromJavaExecutable",
14+
PropertyFactory::class.java, String::class.java)
15+
} catch (_: NoSuchMethodException) {
16+
null
17+
}
18+
19+
@get:Inject
20+
abstract val objectFactory: ObjectFactory
21+
22+
val method812 = try {
23+
SpecificInstallationToolchainSpec::class.java.getMethod("fromJavaExecutable",
24+
ObjectFactory::class.java, String::class.java)
25+
} catch (_: NoSuchMethodException) {
26+
null
27+
}
28+
29+
fun fromJavaExecutable(javaExecutable: String): SpecificInstallationToolchainSpec =
30+
if (method813 != null) {
31+
method813.invoke(null, propertyFactory, javaExecutable) as SpecificInstallationToolchainSpec
32+
} else if (method812 != null) {
33+
method812.invoke(null, objectFactory, javaExecutable) as SpecificInstallationToolchainSpec
34+
} else {
35+
throw IllegalStateException("Unsupported Gradle version, cannot create a SpecificInstallationToolchainSpec")
36+
}
37+
}

src/test/kotlin/test/others/JBRDownloadTest.kt

+41
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class JBRDownloadTest {
6161
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":downloadJbr")?.outcome)
6262
Assert.assertTrue(File(testProjectDir.root, "jbrdl").exists())
6363
}
64+
6465
@Test
6566
fun `download without download dir`() {
6667
settingsFile.writeText("""
@@ -247,4 +248,44 @@ class JBRDownloadTest {
247248
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":exec")?.outcome)
248249
assertThat(result.output, containsString("OpenJDK Runtime Environment JBR"))
249250
}
251+
252+
@Test
253+
fun `use JavaLauncher with Gradle 8_13`() {
254+
buildFile.writeText("""
255+
import de.itemis.mps.gradle.downloadJBR.DownloadJbrForPlatform
256+
257+
plugins {
258+
id("download-jbr")
259+
}
260+
261+
repositories {
262+
mavenCentral()
263+
maven("https://artifacts.itemis.cloud/repository/maven-mps")
264+
}
265+
266+
downloadJbr {
267+
jbrVersion = "$JBR_VERSION"
268+
}
269+
270+
val downloadJbrTask = tasks.named("downloadJbr", DownloadJbrForPlatform::class)
271+
272+
tasks.register<JavaExec>("exec") {
273+
dependsOn(downloadJbrTask)
274+
javaLauncher.set(downloadJbrTask.flatMap { it.javaLauncher })
275+
jvmArgs("--version")
276+
277+
// Main class will be ignored due to --version but has to be provided
278+
mainClass.set("ignored")
279+
}
280+
""".trimIndent())
281+
282+
val result = GradleRunner.create()
283+
.withProjectDir(testProjectDir.root)
284+
.withArguments("exec")
285+
.withGradleVersion("8.13")
286+
.withPluginClasspath()
287+
.build()
288+
Assert.assertEquals(TaskOutcome.SUCCESS, result.task(":exec")?.outcome)
289+
assertThat(result.output, containsString("OpenJDK Runtime Environment JBR"))
290+
}
250291
}

0 commit comments

Comments
 (0)