Enforce a minimum Intelij version of 2021.1.

2021.1 is required for Java 16 and older versions have been known to cause crashes.
dev/0.11
modmuss50 2021-07-17 22:18:14 +01:00
parent a73696a83f
commit b4ac68825f
1 changed files with 17 additions and 0 deletions

View File

@ -15,8 +15,10 @@ import org.gradle.util.GradleVersion;
public class LoomGradlePluginBootstrap implements Plugin<PluginAware> { public class LoomGradlePluginBootstrap implements Plugin<PluginAware> {
private static final int MIN_SUPPORTED_MAJOR_GRADLE_VERSION = 7; private static final int MIN_SUPPORTED_MAJOR_GRADLE_VERSION = 7;
private static final int MIN_SUPPORTED_MAJOR_JAVA_VERSION = 16; private static final int MIN_SUPPORTED_MAJOR_JAVA_VERSION = 16;
private static final int MIN_SUPPORTED_MAJOR_IDEA_VERSION = 2021;
private static final String PLUGIN_CLASS_NAME = "net.fabricmc.loom.LoomGradlePlugin"; private static final String PLUGIN_CLASS_NAME = "net.fabricmc.loom.LoomGradlePlugin";
private static final String IDEA_VERSION_PROP_KEY = "idea.version";
@Override @Override
public void apply(PluginAware project) { public void apply(PluginAware project) {
@ -41,6 +43,10 @@ public class LoomGradlePluginBootstrap implements Plugin<PluginAware> {
} }
} }
if (!isValidIdeaRuntime()) {
errors.add(String.format("You are using an outdated version of intellij idea (%s). Intellij idea %d or higher is required.", System.getProperty(IDEA_VERSION_PROP_KEY), MIN_SUPPORTED_MAJOR_IDEA_VERSION));
}
if (!errors.isEmpty()) { if (!errors.isEmpty()) {
throw new UnsupportedOperationException(String.join("\n", errors)); throw new UnsupportedOperationException(String.join("\n", errors));
} }
@ -57,6 +63,17 @@ public class LoomGradlePluginBootstrap implements Plugin<PluginAware> {
return getMajorGradleVersion() >= MIN_SUPPORTED_MAJOR_GRADLE_VERSION; return getMajorGradleVersion() >= MIN_SUPPORTED_MAJOR_GRADLE_VERSION;
} }
private static boolean isValidIdeaRuntime() {
String version = System.getProperty(IDEA_VERSION_PROP_KEY);
if (version == null) {
return true;
}
int ideaYear = Integer.parseInt(version.substring(0, version.indexOf(".")));
return ideaYear >= MIN_SUPPORTED_MAJOR_IDEA_VERSION;
}
private static int getMajorGradleVersion() { private static int getMajorGradleVersion() {
String version = GradleVersion.current().getVersion(); String version = GradleVersion.current().getVersion();
return Integer.parseInt(version.substring(0, version.indexOf("."))); return Integer.parseInt(version.substring(0, version.indexOf(".")));