Added parameter checks

This commit is contained in:
Johann Bernhardt committed 2021-11-12 13:06:20 +01:00
1 parent ad7153900c
commit 7a86c872dd
1 file changed
+73 -4
+73 -4
View File
@@ -46,6 +46,79 @@ idea {
}
}
if(JavaVersion.current() != JavaVersion.VERSION_1_8) {
throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current())
}
def checkPropertyExsists(String propertyName) {
if (project.hasProperty(propertyName) == false) {
throw new GradleException("This project requires a property \"" + propertyName + "\"! Please add it your \"gradle.properties\". You can find all properties and their description here: https://github.com/SinTh0r4s/ExampleMod1.7.10/blob/main/gradle.properties")
}
}
checkPropertyExsists("modName")
checkPropertyExsists("modId")
checkPropertyExsists("modGroup")
checkPropertyExsists("minecraftVersion")
checkPropertyExsists("forgeVersion")
checkPropertyExsists("replaceGradleTokenInFile")
checkPropertyExsists("gradleTokenModId")
checkPropertyExsists("gradleTokenModName")
checkPropertyExsists("gradleTokenVersion")
checkPropertyExsists("gradleTokenGroupName")
checkPropertyExsists("apiPackage")
checkPropertyExsists("accessTransformersFile")
checkPropertyExsists("usesMixins")
checkPropertyExsists("mixinPlugin")
checkPropertyExsists("mixinsPackage")
checkPropertyExsists("coreModClass")
checkPropertyExsists("containsMixinsAndOrCoreModOnly")
checkPropertyExsists("usesShadowedDependencies")
checkPropertyExsists("developmentEnvironmentUserName")
String targetPackage = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/")
if(new File(targetPackage).exists() == false) {
throw new GradleException("Could not resolve \"modGroup\"! Could not find " + targetPackage)
}
if(apiPackage) {
targetPackage = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + apiPackage.toString().replaceAll("\\.", "/")
if(new File(targetPackage).exists() == false) {
throw new GradleException("Could not resolve \"apiPackage\"! Could not find " + targetPackage)
}
}
if(accessTransformersFile) {
targetPackage = "src/main/resources/META-INF/" + accessTransformersFile
if(new File(targetPackage).exists() == false) {
throw new GradleException("Could not resolve \"accessTransformersFile\"! Could not find " + targetPackage)
}
}
if(usesMixins.toBoolean()) {
if(mixinsPackage.isEmpty() || mixinPlugin.isEmpty()) {
throw new GradleException("\"mixinPlugin\" requires \"mixinsPackage\" and \"mixinPlugin\" to be set!")
}
targetPackage = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinsPackage.toString().replaceAll("\\.", "/")
if(new File(targetPackage).exists() == false) {
throw new GradleException("Could not resolve \"mixinsPackage\"! Could not find " + targetPackage)
}
String targetFile = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + mixinPlugin.toString().replaceAll("\\.", "/") + ".java"
if(new File(targetFile).exists() == false) {
throw new GradleException("Could not resolve \"mixinPlugin\"! Could not find " + targetFile)
}
}
if(coreModClass) {
String targetFile = "src/main/java/" + modGroup.toString().replaceAll("\\.", "/") + "/" + coreModClass.toString().replaceAll("\\.", "/") + ".java"
if(new File(targetFile).exists() == false) {
throw new GradleException("Could not resolve \"coreModClass\"! Could not find " + targetFile)
}
}
configurations.all {
resolutionStrategy.cacheChangingModulesFor(0, TimeUnit.SECONDS)
@@ -62,10 +135,6 @@ group = modGroup
archivesBaseName = modId
minecraft {
if(JavaVersion.current() != JavaVersion.VERSION_1_8) {
throw new GradleException("This project requires Java 8, but it's running on " + JavaVersion.current())
}
version = minecraftVersion + "-" + forgeVersion + "-" + minecraftVersion
runDir = "run"