Skip to content

Commit 7cbe49c

Browse files
committed
Verify that the published artifact was compiled with Java 8
Previous check was verifying that the `releaseCheck` task was running with Java 8, not necessarily that the published artifact was compiled with Java 8. By default, tasks will use Java 21 as it is the default JDK on our CI agents, and only compilation tasks will use 8 through Gradle toolchains. Signed-off-by: Pavlo Shevchenko <[email protected]>
1 parent 743f7aa commit 7cbe49c

File tree

1 file changed

+23
-2
lines changed

1 file changed

+23
-2
lines changed

build.gradle.kts

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
import java.io.BufferedReader
2+
import java.io.InputStreamReader
3+
14
plugins {
25
id("nebula.release") version "20.1.0"
36
id("org.gradle.wrapper-upgrade") version "0.12"
@@ -17,10 +20,28 @@ evaluationDependsOn("plugin")
1720

1821
val publishPlugins = tasks.findByPath(":plugin:publishPlugins")
1922

23+
fun runCommand(vararg command: String): String {
24+
val process = ProcessBuilder(command.toList()).start()
25+
val reader = BufferedReader(InputStreamReader(process.inputStream))
26+
val output = StringBuilder()
27+
var line: String?
28+
while (reader.readLine().also { line = it } != null) {
29+
output.append(line).append("\n")
30+
}
31+
process.waitFor()
32+
return output.toString()
33+
}
34+
35+
val jar = tasks.getByPath(":plugin:shadowJar")
2036
tasks.named("releaseCheck") {
37+
inputs.files(jar.outputs.files)
2138
doFirst {
22-
if (!JavaVersion.current().isJava8) {
23-
throw GradleException("Plugin releases should use Java 8, but used ${JavaVersion.current()} instead.")
39+
val jarPath = jar.outputs.files.singleFile.path
40+
val classFileInfo = runCommand("javap", "-cp", jarPath, "-v", "org.gradle.testretry.TestRetryPlugin")
41+
val classFileVersion = requireNotNull("major version: (\\d+)".toRegex().find(classFileInfo)).groupValues.last().toInt()
42+
val javaVersionForCompilation = JavaVersion.forClassVersion(classFileVersion)
43+
if (!javaVersionForCompilation.isJava8) {
44+
throw GradleException("Plugin releases should use Java 8, but was $javaVersionForCompilation")
2445
}
2546
}
2647
}

0 commit comments

Comments
 (0)