|
| 1 | +plugins { |
| 2 | + id 'java' |
| 3 | + id 'java-library' |
| 4 | + id 'maven-publish' |
| 5 | + id 'com.gradleup.shadow' version '9.4.0' |
| 6 | + id 'org.jetbrains.gradle.plugin.idea-ext' version '1.4.1' |
| 7 | + id 'xyz.wagyourtail.unimined' version '1.4.17-kappa' |
| 8 | + id 'net.kyori.blossom' version '2.2.0' |
| 9 | +} |
| 10 | + |
| 11 | +import org.jetbrains.gradle.ext.Gradle |
| 12 | + |
| 13 | +apply from: 'gradle/scripts/helpers.gradle' |
| 14 | + |
| 15 | +// Early Assertions |
| 16 | +assertProperty 'mod_version' |
| 17 | +assertProperty 'root_package' |
| 18 | +assertProperty 'mod_id' |
| 19 | +assertProperty 'mod_name' |
| 20 | + |
| 21 | +assertSubProperties 'use_access_transformer', 'access_transformer_locations' |
| 22 | +assertSubProperties 'is_coremod', 'coremod_includes_mod', 'coremod_plugin_class_name' |
| 23 | +assertSubProperties 'use_asset_mover', 'asset_mover_version' |
| 24 | + |
| 25 | +setDefaultProperty 'generate_sources_jar', true, false |
| 26 | +setDefaultProperty 'generate_javadocs_jar', true, false |
| 27 | +setDefaultProperty 'minecraft_username', true, 'Developer' |
| 28 | +setDefaultProperty 'extra_jvm_args', false, '' |
| 29 | + |
| 30 | +version = propertyString('mod_version') |
| 31 | +group = propertyString('root_package') |
| 32 | + |
| 33 | +base { |
| 34 | + archivesName = propertyString('mod_id') |
| 35 | +} |
| 36 | + |
| 37 | + |
| 38 | +java { |
| 39 | + toolchain { |
| 40 | + languageVersion = JavaLanguageVersion.of(25) |
| 41 | + } |
| 42 | + if (propertyBool('generate_sources_jar')) { |
| 43 | + withSourcesJar() |
| 44 | + } |
| 45 | + if (propertyBool('generate_javadocs_jar')) { |
| 46 | + withJavadocJar() |
| 47 | + } |
| 48 | +} |
| 49 | + |
| 50 | +configurations { |
| 51 | + contain |
| 52 | + implementation.extendsFrom(contain) |
| 53 | + modCompileOnly |
| 54 | + compileOnly.extendsFrom(modCompileOnly) |
| 55 | + modRuntimeOnly |
| 56 | + runtimeOnly.extendsFrom(modRuntimeOnly) |
| 57 | +} |
| 58 | + |
| 59 | +String remapTaskName = propertyBool('enable_shadow') ? "remapShadowJar" : "remapJar" |
| 60 | + |
| 61 | +unimined.minecraft { |
| 62 | + version "1.12.2" |
| 63 | + |
| 64 | + mappings { |
| 65 | + mcp("stable", "39-1.12") |
| 66 | + } |
| 67 | + |
| 68 | + cleanroom { |
| 69 | + if (propertyBool('use_access_transformer')) { |
| 70 | + accessTransformer "${rootProject.projectDir}/src/main/resources/${propertyString('access_transformer_locations')}" |
| 71 | + } |
| 72 | + loader "0.5.6-alpha" |
| 73 | + runs.auth.username = minecraft_username |
| 74 | + runs.all { |
| 75 | + def extraArgs = propertyString('extra_jvm_args') |
| 76 | + if (extraArgs != null && !extraArgs.trim().isEmpty()) { |
| 77 | + jvmArgs += extraArgs.split { "\\s+" }.toList() |
| 78 | + } |
| 79 | + if (propertyBool('enable_foundation_debug')) { |
| 80 | + systemProperty("foundation.dump", "true") |
| 81 | + systemProperty("foundation.verbose", "true") |
| 82 | + } |
| 83 | + if (propertyBool('is_coremod')) { |
| 84 | + systemProperty("fml.coreMods.load", propertyString('coremod_plugin_class_name')) |
| 85 | + } |
| 86 | + return |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + defaultRemapJar = false |
| 91 | + |
| 92 | + String jarTaskName = propertyBool('enable_shadow') ? "shadowJar" : "jar" |
| 93 | + |
| 94 | + remap(tasks.named(jarTaskName).get()) { |
| 95 | + mixinRemap { |
| 96 | + enableBaseMixin() |
| 97 | + enableMixinExtra() |
| 98 | + disableRefmap() |
| 99 | + } |
| 100 | + } |
| 101 | + |
| 102 | + mods { |
| 103 | + remap(configurations.modCompileOnly) |
| 104 | + remap(configurations.modRuntimeOnly) |
| 105 | + } |
| 106 | +} |
| 107 | + |
| 108 | +dependencies { |
| 109 | + if (propertyBool('use_asset_mover')) { |
| 110 | + implementation "com.cleanroommc:assetmover:${propertyString('asset_mover_version')}" |
| 111 | + } |
| 112 | + if (propertyBool('enable_junit_testing')) { |
| 113 | + testImplementation 'org.junit.jupiter:junit-jupiter:6.0.3' |
| 114 | + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +apply from: 'gradle/scripts/dependencies.gradle' |
| 119 | + |
| 120 | +processResources { |
| 121 | + rename '(.+_at.cfg)', 'META-INF/$1' |
| 122 | +} |
| 123 | + |
| 124 | +sourceSets { |
| 125 | + main { |
| 126 | + blossom { |
| 127 | + javaSources { |
| 128 | + property('mod_id', propertyString('mod_id')) |
| 129 | + property('mod_name', propertyString('mod_name')) |
| 130 | + property('mod_version', propertyString('mod_version')) |
| 131 | + property('package', "${root_package}.${mod_id}") |
| 132 | + } |
| 133 | + resources { |
| 134 | + property('mod_id', propertyString('mod_id')) |
| 135 | + property('mod_name', propertyString('mod_name')) |
| 136 | + property('mod_version', propertyString('mod_version')) |
| 137 | + property('mod_description', propertyString('mod_description')) |
| 138 | + property('mod_authors', propertyStringList('mod_authors', ',').collect {it.strip()}.join('", "')) |
| 139 | + property('mod_credits', propertyString('mod_credits')) |
| 140 | + property('mod_url', propertyString('mod_url')) |
| 141 | + property('mod_update_json', propertyString('mod_update_json')) |
| 142 | + property('mod_logo_path', propertyString('mod_logo_path')) |
| 143 | + } |
| 144 | + } |
| 145 | + } |
| 146 | +} |
| 147 | + |
| 148 | +idea { |
| 149 | + module { |
| 150 | + inheritOutputDirs = true |
| 151 | + } |
| 152 | + project { |
| 153 | + settings { |
| 154 | + runConfigurations { |
| 155 | + '1. Build'(Gradle) { |
| 156 | + taskNames = ["build"] |
| 157 | + } |
| 158 | + '2. Run Client'(Gradle) { |
| 159 | + taskNames = ["runClient"] |
| 160 | + } |
| 161 | + '3. Run Server'(Gradle) { |
| 162 | + taskNames = ["runServer"] |
| 163 | + } |
| 164 | + } |
| 165 | + compiler.javac { |
| 166 | + afterEvaluate { |
| 167 | + javacAdditionalOptions = '-encoding utf8' |
| 168 | + moduleJavacAdditionalOptions = [ |
| 169 | + (project.name + '.main'): tasks.compileJava.options.compilerArgs.collect { '"' + it + '"' }.join(' ') |
| 170 | + ] |
| 171 | + } |
| 172 | + } |
| 173 | + } |
| 174 | + } |
| 175 | +} |
| 176 | + |
| 177 | +if (!propertyBool('enable_shadow')) { |
| 178 | + shadowJar.enabled = false |
| 179 | +} |
| 180 | + |
| 181 | +compileJava { |
| 182 | + sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21 |
| 183 | +} |
| 184 | + |
| 185 | +jar { |
| 186 | + archiveClassifier = 'dev' |
| 187 | + duplicatesStrategy = DuplicatesStrategy.EXCLUDE |
| 188 | + if (configurations.contain.size() > 0) { |
| 189 | + into('/') { |
| 190 | + from configurations.contain |
| 191 | + } |
| 192 | + } |
| 193 | + doFirst { |
| 194 | + manifest { |
| 195 | + def attribute_map = [:] |
| 196 | + attribute_map['ModType'] = "CRL" |
| 197 | + if (configurations.contain.size() > 0) { |
| 198 | + attribute_map['ContainedDeps'] = configurations.contain.collect { it.name }.join(' ') |
| 199 | + attribute_map['NonModDeps'] = true |
| 200 | + } |
| 201 | + if (propertyBool('is_coremod')) { |
| 202 | + attribute_map['FMLCorePlugin'] = propertyString('coremod_plugin_class_name') |
| 203 | + if (propertyBool('coremod_includes_mod')) { |
| 204 | + attribute_map['FMLCorePluginContainsFMLMod'] = true |
| 205 | + } |
| 206 | + } |
| 207 | + if (propertyBool('use_access_transformer')) { |
| 208 | + attribute_map['FMLAT'] = propertyString('access_transformer_locations') |
| 209 | + } |
| 210 | + attributes(attribute_map) |
| 211 | + } |
| 212 | + } |
| 213 | + finalizedBy(tasks.named(remapTaskName).get()) |
| 214 | +} |
| 215 | + |
| 216 | + |
| 217 | +shadowJar { |
| 218 | + configurations = [project.configurations.shadow] |
| 219 | + archiveClassifier = "shadow" |
| 220 | +} |
| 221 | + |
| 222 | + |
| 223 | +tasks.named(remapTaskName).configure { |
| 224 | + doFirst { |
| 225 | + logging.captureStandardOutput LogLevel.INFO |
| 226 | + } |
| 227 | + doLast { |
| 228 | + logging.captureStandardOutput LogLevel.QUIET |
| 229 | + } |
| 230 | +} |
| 231 | + |
| 232 | +compileTestJava { |
| 233 | + sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21 |
| 234 | +} |
| 235 | + |
| 236 | +test { |
| 237 | + useJUnitPlatform() |
| 238 | + javaLauncher.set(javaToolchains.launcherFor { |
| 239 | + languageVersion = JavaLanguageVersion.of(25) |
| 240 | + }) |
| 241 | + if (propertyBool('show_testing_output')) { |
| 242 | + testLogging { |
| 243 | + showStandardStreams = true |
| 244 | + } |
| 245 | + } |
| 246 | +} |
| 247 | + |
| 248 | +tasks.withType(JavaCompile).configureEach { |
| 249 | + options.encoding = 'UTF-8' |
| 250 | +} |
| 251 | + |
| 252 | +apply from: 'gradle/scripts/publishing.gradle' |
| 253 | +apply from: 'gradle/scripts/extra.gradle' |
0 commit comments