Add Java version check
This commit is contained in:
parent
934e245fdf
commit
c095ab0265
4 changed files with 31 additions and 0 deletions
|
@ -42,6 +42,7 @@ import org.gradle.kotlin.dsl.*
|
|||
|
||||
class PaperweightCore : Plugin<Project> {
|
||||
override fun apply(target: Project) {
|
||||
checkJavaVersion()
|
||||
Git.checkForGit()
|
||||
|
||||
val ext = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightCoreExtension::class, target)
|
||||
|
|
|
@ -32,6 +32,7 @@ import io.papermc.paperweight.util.constants.*
|
|||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.io.OutputStream
|
||||
import java.lang.management.ManagementFactory
|
||||
import java.lang.reflect.Type
|
||||
import java.net.URI
|
||||
import java.net.URL
|
||||
|
@ -317,3 +318,29 @@ fun FileCollection.toJarClassProviderRoots(): List<ClassProviderRoot> =
|
|||
.filter { p -> p.isLibraryJar }
|
||||
.map { p -> ClassProviderRoot.fromJar(p) }
|
||||
.toList()
|
||||
|
||||
private fun javaVersion(): Int {
|
||||
val version = System.getProperty("java.specification.version")
|
||||
val parts = version.split("\\.".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
|
||||
val errorMsg = "Could not determine version of the current JVM"
|
||||
check(parts.isNotEmpty()) { errorMsg }
|
||||
return if (parts[0] == "1") {
|
||||
check(parts.size >= 2) { errorMsg }
|
||||
parts[1].toInt()
|
||||
} else {
|
||||
parts[0].toInt()
|
||||
}
|
||||
}
|
||||
|
||||
fun checkJavaVersion() {
|
||||
val minimumJava = 11
|
||||
val ver = javaVersion()
|
||||
if (ver < minimumJava) {
|
||||
var msg = "paperweight requires Gradle to be run with a Java $minimumJava runtime or newer."
|
||||
val runtimeMX = ManagementFactory.getRuntimeMXBean()
|
||||
if (runtimeMX != null) {
|
||||
msg += " Current runtime: Java ${runtimeMX.specVersion} (${runtimeMX.vmName} ${runtimeMX.vmVersion})"
|
||||
}
|
||||
throw PaperweightException(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.gradle.kotlin.dsl.registering
|
|||
class PaperweightPatcher : Plugin<Project> {
|
||||
|
||||
override fun apply(target: Project) {
|
||||
checkJavaVersion()
|
||||
Git.checkForGit()
|
||||
|
||||
val patcher = target.extensions.create(PAPERWEIGHT_EXTENSION, PaperweightPatcherExtension::class, target)
|
||||
|
|
|
@ -65,6 +65,8 @@ abstract class PaperweightUser : Plugin<Project> {
|
|||
abstract val javaToolchainService: JavaToolchainService
|
||||
|
||||
override fun apply(target: Project) {
|
||||
checkJavaVersion()
|
||||
|
||||
val sharedCacheRootRoot = target.gradle.gradleUserHomeDir.toPath().resolve("caches/paperweight-userdev")
|
||||
val sharedCacheRoot = if (target.sharedCaches) {
|
||||
logger.lifecycle("paperweight-userdev experimental shared caches are enabled.")
|
||||
|
|
Loading…
Reference in a new issue