|
| 1 | +import org.jetbrains.changelog.Changelog |
| 2 | + |
| 3 | +plugins { |
| 4 | + id 'java' |
| 5 | + id 'java-library' |
| 6 | + id 'maven-publish' |
| 7 | + id 'com.gradleup.shadow' version '9.0.0-beta12' // Remove this line and shadowJar task if you don't need shadow |
| 8 | + id 'org.jetbrains.changelog' version '2.2.1' |
| 9 | + id 'xyz.wagyourtail.unimined' version '1.3.14' |
| 10 | +} |
| 11 | + |
| 12 | +apply from: 'gradle/scripts/helpers.gradle' |
| 13 | + |
| 14 | +// Early Assertions |
| 15 | +assertProperty 'mod_version' |
| 16 | +assertProperty 'root_package' |
| 17 | +assertProperty 'mod_id' |
| 18 | +assertProperty 'mod_name' |
| 19 | + |
| 20 | +injectTags() |
| 21 | + |
| 22 | +assertSubProperties 'use_access_transformer', 'access_transformer_locations' |
| 23 | +assertSubProperties 'is_coremod', 'coremod_includes_mod', 'coremod_plugin_class_name' |
| 24 | +assertSubProperties 'use_asset_mover', 'asset_mover_version' |
| 25 | + |
| 26 | +setDefaultProperty 'generate_sources_jar', true, false |
| 27 | +setDefaultProperty 'generate_javadocs_jar', true, false |
| 28 | +setDefaultProperty 'minecraft_username', true, 'Developer' |
| 29 | +setDefaultProperty 'extra_jvm_args', false, '' |
| 30 | + |
| 31 | +version = propertyString('mod_version') |
| 32 | +group = propertyString('root_package') |
| 33 | + |
| 34 | +base { |
| 35 | + archivesName.set(propertyString('mod_id')) |
| 36 | +} |
| 37 | + |
| 38 | + |
| 39 | +java { |
| 40 | + toolchain { |
| 41 | + languageVersion.set(JavaLanguageVersion.of(21)) |
| 42 | + } |
| 43 | + if (propertyBool('generate_sources_jar')) { |
| 44 | + withSourcesJar() |
| 45 | + } |
| 46 | + if (propertyBool('generate_javadocs_jar')) { |
| 47 | + withJavadocJar() |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +configurations { |
| 52 | + embed |
| 53 | + contain |
| 54 | + implementation.extendsFrom(embed) |
| 55 | +} |
| 56 | + |
| 57 | +unimined.minecraft { |
| 58 | + version "1.12.2" |
| 59 | + |
| 60 | + mappings { |
| 61 | + mcp("stable", "39-1.12") |
| 62 | + } |
| 63 | + |
| 64 | + cleanroom { |
| 65 | + if (propertyBool('use_access_transformer')) { |
| 66 | + accessTransformer 'src/main/resources/' + propertyString('access_transformer_locations') |
| 67 | + } |
| 68 | + loader "0.3.0-alpha" |
| 69 | + runs.auth.username = minecraft_username |
| 70 | + runs.all { |
| 71 | + if (hasProperty("extra_jvm_args")) { |
| 72 | + jvmArgs(propertyString('extra_jvm_args')) |
| 73 | + } |
| 74 | + if (propertyBool('enable_foundation_debug')) { |
| 75 | + systemProperty("foundation.dump", "true") |
| 76 | + systemProperty("foundation.verbose", "true") |
| 77 | + } |
| 78 | + return |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + |
| 83 | +} |
| 84 | + |
| 85 | +repositories { |
| 86 | + maven { |
| 87 | + name 'CleanroomMC Maven' |
| 88 | + url 'https://maven.cleanroommc.com' |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +dependencies { |
| 93 | + if (propertyBool('use_asset_mover')) { |
| 94 | + implementation "com.cleanroommc:assetmover:${propertyString('asset_mover_version')}" |
| 95 | + } |
| 96 | + if (propertyBool('enable_junit_testing')) { |
| 97 | + testImplementation 'org.junit.jupiter:junit-jupiter:5.7.1' |
| 98 | + testRuntimeOnly 'org.junit.platform:junit-platform-launcher' |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +apply from: 'gradle/scripts/dependencies.gradle' |
| 103 | + |
| 104 | +processResources { |
| 105 | + |
| 106 | + inputs.property 'mod_id', propertyString('mod_id') |
| 107 | + inputs.property 'mod_name', propertyString('mod_name') |
| 108 | + inputs.property 'mod_version', propertyString('mod_version') |
| 109 | + inputs.property 'mod_description', propertyString('mod_description') |
| 110 | + inputs.property 'mod_authors', "${propertyStringList('mod_authors', ',').join(', ')}" |
| 111 | + inputs.property 'mod_credits', propertyString('mod_credits') |
| 112 | + inputs.property 'mod_url', propertyString('mod_url') |
| 113 | + inputs.property 'mod_update_json', propertyString('mod_update_json') |
| 114 | + inputs.property 'mod_logo_path', propertyString('mod_logo_path') |
| 115 | + |
| 116 | + def filterList = ['mcmod.info', 'pack.mcmeta'] |
| 117 | + |
| 118 | + filesMatching(filterList) { fcd -> |
| 119 | + fcd.expand( |
| 120 | + 'mod_id': propertyString('mod_id'), |
| 121 | + 'mod_name': propertyString('mod_name'), |
| 122 | + 'mod_version': propertyString('mod_version'), |
| 123 | + 'mod_description': propertyString('mod_description'), |
| 124 | + 'mod_authors': "${propertyStringList('mod_authors', ',').join(', ')}", |
| 125 | + 'mod_credits': propertyString('mod_credits'), |
| 126 | + 'mod_url': propertyString('mod_url'), |
| 127 | + 'mod_update_json': propertyString('mod_update_json'), |
| 128 | + 'mod_logo_path': propertyString('mod_logo_path'), |
| 129 | + ) |
| 130 | + } |
| 131 | + |
| 132 | + rename '(.+_at.cfg)', 'META-INF/$1' |
| 133 | +} |
| 134 | + |
| 135 | +jar { |
| 136 | + duplicatesStrategy = DuplicatesStrategy.EXCLUDE |
| 137 | + if (configurations.contain.size() > 0) { |
| 138 | + into('/') { |
| 139 | + from configurations.contain |
| 140 | + } |
| 141 | + } |
| 142 | + doFirst{ |
| 143 | + manifest { |
| 144 | + def attribute_map = [:] |
| 145 | + attribute_map['ModType'] = "CRL" |
| 146 | + if (configurations.contain.size() > 0) { |
| 147 | + attribute_map['ContainedDeps'] = configurations.contain.collect { it.name }.join(' ') |
| 148 | + attribute_map['NonModDeps'] = true |
| 149 | + } |
| 150 | + if (propertyBool('is_coremod')) { |
| 151 | + attribute_map['FMLCorePlugin'] = propertyString('coremod_plugin_class_name') |
| 152 | + if (propertyBool('coremod_includes_mod')) { |
| 153 | + attribute_map['FMLCorePluginContainsFMLMod'] = true |
| 154 | + } |
| 155 | + } |
| 156 | + if (propertyBool('use_access_transformer')) { |
| 157 | + attribute_map['FMLAT'] = propertyString('access_transformer_locations') |
| 158 | + } |
| 159 | + attributes(attribute_map) |
| 160 | + } |
| 161 | + } |
| 162 | + if (propertyBool('enable_shadow')) { |
| 163 | + finalizedBy(shadowJar) |
| 164 | + } |
| 165 | +} |
| 166 | + |
| 167 | +tasks.remapJar { |
| 168 | + doFirst { |
| 169 | + logging.captureStandardOutput LogLevel.INFO |
| 170 | + } |
| 171 | + doLast { |
| 172 | + logging.captureStandardOutput LogLevel.QUIET |
| 173 | + } |
| 174 | +} |
| 175 | + |
| 176 | +shadowJar { |
| 177 | + configurations = [project.configurations.shadow] |
| 178 | + archiveClassifier = "shadow" |
| 179 | +} |
| 180 | + |
| 181 | +compileTestJava { |
| 182 | + sourceCompatibility = targetCompatibility = JavaVersion.VERSION_21 |
| 183 | +} |
| 184 | + |
| 185 | +test { |
| 186 | + useJUnitPlatform() |
| 187 | + javaLauncher.set(javaToolchains.launcherFor { |
| 188 | + languageVersion = JavaLanguageVersion.of(21) |
| 189 | + }) |
| 190 | + if (propertyBool('show_testing_output')) { |
| 191 | + testLogging { |
| 192 | + showStandardStreams = true |
| 193 | + } |
| 194 | + } |
| 195 | +} |
| 196 | + |
| 197 | +String parserChangelog() { |
| 198 | + if (!file('CHANGELOG.md').exists()) { |
| 199 | + throw new GradleException('publish_with_changelog is true, but CHANGELOG.md does not exist in the workspace!') |
| 200 | + } |
| 201 | + String parsedChangelog = changelog.renderItem( |
| 202 | + changelog.get(propertyString('mod_version')).withHeader(false).withEmptySections(false), |
| 203 | + Changelog.OutputType.MARKDOWN) |
| 204 | + if (parsedChangelog.isEmpty()) { |
| 205 | + throw new GradleException('publish_with_changelog is true, but the changelog for the latest version is empty!') |
| 206 | + } |
| 207 | + return parsedChangelog |
| 208 | +} |
| 209 | + |
| 210 | +def injectTags() { |
| 211 | + var target = new File("${rootProject.projectDir}/src/main/java/${root_package.replace('.', '/')}/${mod_id}/Reference.java") |
| 212 | + var template = new File("${rootProject.projectDir}/template/Reference.java") |
| 213 | + var replaceMap = [$mod_id : mod_id, $mod_name : mod_name, $mod_version : mod_version] |
| 214 | + target.withWriter { var writer -> |
| 215 | + template.eachLine { var line -> |
| 216 | + replaceMap.each {if (line.contains(it.key)) line = line.replace(it.key, it.value)} |
| 217 | + writer.write(line + "\n"); |
| 218 | + } |
| 219 | + } |
| 220 | +} |
| 221 | + |
| 222 | +tasks.withType(JavaCompile).configureEach { |
| 223 | + options.encoding = 'UTF-8' |
| 224 | +} |
| 225 | + |
| 226 | +apply from: 'gradle/scripts/publishing.gradle' |
| 227 | +apply from: 'gradle/scripts/extra.gradle' |
0 commit comments