build.gradle 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. plugins {
  2. id("fabric-loom") version("0.5-SNAPSHOT") apply false
  3. id("maven-publish")
  4. id("java")
  5. id("java-library")
  6. id("net.minecrell.licenser") version("0.4.1")
  7. id("com.matthewprenger.cursegradle") version("1.4.0")
  8. id("net.corda.plugins.jar-filter") version("5.0.8") apply false
  9. }
  10. import net.fabricmc.loom.LoomGradleExtension
  11. import net.fabricmc.loom.task.RemapJarTask
  12. import net.fabricmc.loom.util.DownloadUtil
  13. import net.fabricmc.loom.util.MinecraftVersionInfo
  14. import net.fabricmc.lorenztiny.TinyMappingsReader
  15. import net.fabricmc.mapping.tree.TinyMappingFactory
  16. import org.cadixdev.lorenz.MappingSet
  17. import org.cadixdev.lorenz.io.TextMappingsWriter
  18. import org.cadixdev.lorenz.io.proguard.ProGuardReader
  19. import org.cadixdev.lorenz.model.*
  20. import org.zeroturnaround.zip.ByteSource
  21. import org.zeroturnaround.zip.ZipEntrySource
  22. import org.zeroturnaround.zip.ZipUtil
  23. import java.nio.charset.StandardCharsets
  24. import java.nio.file.Files
  25. import java.nio.file.Path
  26. import java.text.SimpleDateFormat
  27. import java.util.function.Consumer
  28. archivesBaseName = "RoughlyEnoughItems"
  29. version = project.mod_version
  30. group = "me.shedaniel"
  31. allprojects {
  32. apply plugin: 'maven-publish'
  33. apply plugin: 'maven'
  34. apply plugin: 'fabric-loom'
  35. apply plugin: 'net.minecrell.licenser'
  36. apply plugin: 'net.corda.plugins.jar-filter'
  37. sourceCompatibility = targetCompatibility = 1.8
  38. sourceSets {
  39. testmod {
  40. compileClasspath += main.compileClasspath
  41. runtimeClasspath += main.runtimeClasspath
  42. }
  43. }
  44. loom {
  45. shareCaches = true
  46. }
  47. repositories {
  48. maven { url "https://dl.bintray.com/shedaniel/shedaniel-mods" }
  49. mavenLocal()
  50. }
  51. afterEvaluate {
  52. processResources {
  53. filesMatching('fabric.mod.json') {
  54. expand 'version': project.version
  55. }
  56. inputs.property "version", project.version
  57. }
  58. license {
  59. header rootProject.file('HEADER')
  60. include '**/*.java'
  61. }
  62. jar {
  63. from rootProject.file("LICENSE")
  64. }
  65. }
  66. dependencies {
  67. minecraft("com.mojang:minecraft:${project.minecraft_version}")
  68. mappings(new MojangMappingsDependency(project, loom))
  69. modApi("net.fabricmc:fabric-loader:${project.fabricloader_version}")
  70. modApi("net.fabricmc.fabric-api:fabric-api:${project.fabric_api}") {
  71. exclude(module: "fabric-biomes-v1")
  72. }
  73. modApi("me.shedaniel.cloth.api:cloth-client-events-v0:${cloth_client_events_v0_version}") {
  74. transitive(false)
  75. }
  76. modApi("me.shedaniel.cloth:config-2:${cloth_config_version}") {
  77. exclude(module: "fabric-api")
  78. }
  79. modApi("me.sargunvohra.mcmods:autoconfig1u:${project.autoconfig1u}") {
  80. exclude(module: "fabric-api")
  81. }
  82. modApi("org.jetbrains:annotations:19.0.0")
  83. modCompileOnly("io.github.prospector:modmenu:${modmenu_version}") {
  84. transitive(false)
  85. }
  86. modRuntime("io.github.prospector:modmenu:${modmenu_version}") {
  87. transitive(false)
  88. }
  89. modRuntime("me.shedaniel:SmoothScrollingEverywhere:3.0.3-unstable") {
  90. transitive(false)
  91. }
  92. }
  93. tasks.withType(JavaCompile) {
  94. options.encoding = "UTF-8"
  95. }
  96. task sourcesJar(type: Jar, dependsOn: classes) {
  97. classifier("sources")
  98. from sourceSets.main.allSource
  99. }
  100. }
  101. subprojects {
  102. group = rootProject.group
  103. version = rootProject.version
  104. dependencies {
  105. testmodCompile sourceSets.main.output
  106. }
  107. task remapMavenJar(type: Copy, dependsOn: remapJar) {
  108. afterEvaluate {
  109. from("${project.buildDir}/libs/$archivesBaseName-${version}.jar")
  110. into("${project.buildDir}/libs/")
  111. rename { String fn -> "$archivesBaseName-${version}-maven.jar" }
  112. }
  113. }
  114. configurations {
  115. dev
  116. remapped
  117. }
  118. jar {
  119. classifier("dev")
  120. }
  121. remapJar {
  122. input.set(file("${project.buildDir}/filtered-libs/$archivesBaseName-${version}-dev-filtered.jar"))
  123. classifier(null)
  124. }
  125. artifacts {
  126. dev file: file("${project.buildDir}/libs/$archivesBaseName-${version}-dev.jar"), type: "jar", builtBy: jar
  127. remapped file: file("${project.buildDir}/libs/$archivesBaseName-${version}.jar"), type: "jar", builtBy: remapJar
  128. }
  129. task jarFilter(type: net.corda.gradle.jarfilter.JarFilterTask) {
  130. jars jar
  131. annotations {
  132. forRemove = [
  133. "org.jetbrains.annotations.NotNull",
  134. "org.jetbrains.annotations.Nullable",
  135. "org.jetbrains.annotations.ApiStatus\$Experimental",
  136. "org.jetbrains.annotations.ApiStatus\$Internal",
  137. "org.jetbrains.annotations.ApiStatus\$ScheduledForRemoval",
  138. "org.jetbrains.annotations.ApiStatus\$AvailableSince",
  139. "org.jetbrains.annotations.ApiStatus\$NonExtendable",
  140. "org.jetbrains.annotations.ApiStatus\$OverrideOnly"
  141. ]
  142. }
  143. }
  144. remapJar.dependsOn("jarFilter")
  145. publishing {
  146. publications {
  147. create("${archivesBaseName}_mavenJava", MavenPublication) {
  148. afterEvaluate {
  149. artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}-maven.jar")) {
  150. builtBy remapMavenJar
  151. }
  152. artifact(sourcesJar) {
  153. builtBy remapSourcesJar
  154. }
  155. }
  156. }
  157. }
  158. repositories {
  159. if (project.hasProperty('danielshe_pass')) {
  160. maven {
  161. url = "http://deploy.modmuss50.me/"
  162. credentials {
  163. username = "danielshe"
  164. password = project.getProperty('danielshe_pass')
  165. }
  166. }
  167. }
  168. }
  169. }
  170. }
  171. task licenseFormatAll
  172. subprojects { licenseFormatAll.dependsOn("${path}:licenseFormat") }
  173. subprojects { rootProject.remapJar.dependsOn("${path}:remapJar") }
  174. task remapMavenJar(type: RemapJarTask, dependsOn: jar) {
  175. afterEvaluate {
  176. input.set(file("${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar"))
  177. archiveName = "${archivesBaseName}-${version}-maven.jar"
  178. addNestedDependencies.set(false)
  179. }
  180. }
  181. sourceSets {
  182. testmod
  183. }
  184. dependencies {
  185. afterEvaluate {
  186. subprojects.each {
  187. compile project(path: ":${it.name}", configuration: "dev")
  188. include project(path: ":${it.name}", configuration: "remapped")
  189. testmodCompile project("${it.name}:").sourceSets.testmod.output
  190. }
  191. def listAdded = new ArrayList(Arrays.asList((api_exculde as String).split(',')))
  192. def eachDep = { dep ->
  193. for (apiIncludeDepStr in (api_include as String).split(',')) {
  194. if (apiIncludeDepStr.isEmpty()) continue
  195. def apiIncludeGroup = apiIncludeDepStr.split(':')[0]
  196. def apiIncludeDep = apiIncludeDepStr.split(':')[1]
  197. if (dep.module.id.group == apiIncludeGroup && dep.module.id.name.startsWith(apiIncludeDep)) {
  198. def version = dep.module.id.version.indexOf('@') >= 0 ? dep.module.id.version.substring(0, dep.module.id.version.indexOf('@')) : dep.module.id.version
  199. def mavenDep = "${dep.module.id.group}:${dep.module.id.name}:$version"
  200. if (!(mavenDep in listAdded)) {
  201. include(mavenDep) {
  202. transitive = false
  203. }
  204. listAdded.add(mavenDep)
  205. }
  206. break
  207. }
  208. }
  209. }
  210. rootProject.configurations.compile.resolvedConfiguration.firstLevelModuleDependencies.each eachDep
  211. rootProject.configurations.runtimeClasspath.resolvedConfiguration.firstLevelModuleDependencies.each eachDep
  212. }
  213. }
  214. def releaseChangelog = "No changelog"
  215. /* Thank you modmenu & fablabs */
  216. task releaseOnCf {
  217. def df = new SimpleDateFormat("yyyy-MM-dd HH:mm")
  218. df.setTimeZone(TimeZone.getTimeZone("UTC"))
  219. def branch
  220. if (System.env.BRANCH_NAME) {
  221. branch = System.env.BRANCH_NAME
  222. branch = branch.substring(branch.lastIndexOf("/") + 1)
  223. } else {
  224. branch = "git rev-parse --abbrev-ref HEAD".execute().in.text.trim()
  225. }
  226. if (branch == "HEAD") {
  227. branch = "git rev-parse --short HEAD".execute().in.text.trim()
  228. }
  229. def time = df.format(new Date())
  230. def changes = new StringBuilder()
  231. changes << "<h2>REI v$project.version for $project.supported_version</h2>Updated at <b>$time</b>.<br><a href=\"https://www.github.com/shedaniel/RoughlyEnoughItems/commits/$branch\">Click here for changelog</a>"
  232. def proc = "git log --max-count=200 --pretty=format:%s".execute()
  233. proc.in.eachLine { line ->
  234. def processedLine = line.toString()
  235. if (!processedLine.contains("New translations") && !processedLine.contains("Merge") && !processedLine.contains("branch")) {
  236. changes << "<br>- ${processedLine.capitalize()}"
  237. }
  238. }
  239. proc.waitFor()
  240. releaseChangelog = changes.toString()
  241. dependsOn tasks.getByName("curseforge")
  242. }
  243. curseforge {
  244. if (project.hasProperty('danielshe_curse_api_key') || System.getenv('danielshe_curse_api_key') != null) {
  245. apiKey = project.hasProperty('danielshe_curse_api_key') ? project.property('danielshe_curse_api_key') : System.getenv('danielshe_curse_api_key')
  246. project {
  247. id = "310111"
  248. releaseType = "release"
  249. changelogType = "html"
  250. changelog = releaseChangelog
  251. addGameVersion "1.16-Snapshot"
  252. addGameVersion "1.16.2"
  253. addGameVersion "Java 8"
  254. addGameVersion "Fabric"
  255. relations {
  256. requiredDependency "fabric-api"
  257. embeddedLibrary "cloth-api"
  258. embeddedLibrary "cloth-config"
  259. embeddedLibrary "auto-config-updated-api"
  260. }
  261. mainArtifact(file("${project.buildDir}/libs/${project.archivesBaseName}-${project.version}.jar")) {
  262. displayName = "[Fabric $project.supported_version] v$project.version"
  263. }
  264. addArtifact(file("${project.buildDir}/libs/${project.archivesBaseName}-${project.version}-sources.jar")) {
  265. displayName = "[Fabric $project.supported_version] v$project.version Sources"
  266. }
  267. afterEvaluate {
  268. uploadTask.dependsOn("build")
  269. }
  270. }
  271. }
  272. options {
  273. forgeGradleIntegration = false
  274. javaVersionAutoDetect = false
  275. }
  276. }
  277. publishing {
  278. publications {
  279. mavenJava(MavenPublication) {
  280. artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}-maven.jar")) {
  281. builtBy remapMavenJar
  282. }
  283. artifact(sourcesJar) {
  284. builtBy remapSourcesJar
  285. }
  286. pom.withXml {
  287. def depsNode = asNode().appendNode("dependencies")
  288. subprojects.each {
  289. def depNode = depsNode.appendNode("dependency")
  290. depNode.appendNode("groupId", it.group)
  291. depNode.appendNode("artifactId", it.name)
  292. depNode.appendNode("version", it.version)
  293. depNode.appendNode("scope", "compile")
  294. }
  295. }
  296. }
  297. }
  298. repositories {
  299. if (project.hasProperty('danielshe_pass')) {
  300. maven {
  301. url = "http://deploy.modmuss50.me/"
  302. credentials {
  303. username = "danielshe"
  304. password = project.getProperty('danielshe_pass')
  305. }
  306. }
  307. }
  308. }
  309. }
  310. /*
  311. The following code is licensed under MIT License.
  312. Copyright (c) 2016 FabricMC
  313. Permission is hereby granted, free of charge, to any person obtaining a copy
  314. of this software and associated documentation files (the "Software"), to deal
  315. in the Software without restriction, including without limitation the rights
  316. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  317. copies of the Software, and to permit persons to whom the Software is
  318. furnished to do so, subject to the following conditions:
  319. The above copyright notice and this permission notice shall be included in all
  320. copies or substantial portions of the Software.
  321. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  322. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  323. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  324. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  325. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  326. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  327. SOFTWARE.
  328. */
  329. class MojangMappingsDependency implements SelfResolvingDependency {
  330. private final Project project
  331. private final LoomGradleExtension extension
  332. MojangMappingsDependency(Project project, LoomGradleExtension extension) {
  333. this.project = project
  334. this.extension = extension
  335. }
  336. @Override
  337. Set<File> resolve() {
  338. Path mappingsDir = extension.getMappingsProvider().getMappingsDir()
  339. Path mappingsFile = mappingsDir.resolve(String.format("net.mojang.minecraft-mappings-%s.tiny", getVersion()))
  340. Path clientMappings = mappingsDir.resolve(String.format("net.mojang.minecraft.mappings-%s-client.map", getVersion()))
  341. Path serverMappings = mappingsDir.resolve(String.format("net.mojang.minecraft.mappings-%s-server.map", getVersion()))
  342. if (!Files.exists(mappingsFile) || project.getGradle().getStartParameter().isRefreshDependencies()) {
  343. MappingSet mappingSet
  344. try {
  345. mappingSet = getMappingsSet(clientMappings, serverMappings)
  346. Writer writer = new StringWriter()
  347. new TinyWriter(writer, "intermediary", "named").write(mappingSet)
  348. Files.deleteIfExists(mappingsFile)
  349. ZipUtil.pack([
  350. new ByteSource("mappings/mappings.tiny", writer.toString().getBytes(StandardCharsets.UTF_8))
  351. ] as ZipEntrySource[], mappingsFile.toFile())
  352. writer.close()
  353. } catch (IOException e) {
  354. throw new RuntimeException("Failed to resolve Mojang mappings", e)
  355. }
  356. }
  357. return Collections.singleton(mappingsFile.toFile())
  358. }
  359. private MappingSet getMappingsSet(Path clientMappings, Path serverMappings) throws IOException {
  360. MinecraftVersionInfo versionInfo = extension.getMinecraftProvider().getVersionInfo()
  361. if (versionInfo.downloads.get("client_mappings") == null) {
  362. throw new RuntimeException("Failed to find official mojang mappings for " + getVersion())
  363. }
  364. String clientMappingsUrl = versionInfo.downloads.get("client_mappings").url
  365. String serverMappingsUrl = versionInfo.downloads.get("server_mappings").url
  366. DownloadUtil.downloadIfChanged(new URL(clientMappingsUrl), clientMappings.toFile(), project.getLogger())
  367. DownloadUtil.downloadIfChanged(new URL(serverMappingsUrl), serverMappings.toFile(), project.getLogger())
  368. MappingSet mappings = MappingSet.create()
  369. BufferedReader clientBufferedReader = Files.newBufferedReader(clientMappings, StandardCharsets.UTF_8)
  370. BufferedReader serverBufferedReader = Files.newBufferedReader(serverMappings, StandardCharsets.UTF_8)
  371. ProGuardReader proGuardReaderClient = new ProGuardReader(clientBufferedReader)
  372. ProGuardReader proGuardReaderServer = new ProGuardReader(serverBufferedReader)
  373. proGuardReaderClient.read(mappings)
  374. proGuardReaderServer.read(mappings)
  375. clientBufferedReader.close()
  376. serverBufferedReader.close()
  377. proGuardReaderClient.close()
  378. proGuardReaderServer.close()
  379. MappingSet officialToNamed = mappings.reverse()
  380. MappingSet intermediaryToOfficial
  381. BufferedReader reader = Files.newBufferedReader(extension.getMappingsProvider().getIntermediaryTiny(), StandardCharsets.UTF_8)
  382. intermediaryToOfficial = new TinyMappingsReader(TinyMappingFactory.loadWithDetection(reader), "intermediary", "official").read()
  383. reader.close()
  384. MappingSet intermediaryToMojang = MappingSet.create()
  385. // Merging. Don't use MappingSet#merge
  386. iterateClasses(intermediaryToOfficial, { inputMappings ->
  387. officialToNamed.getClassMapping(inputMappings.getFullDeobfuscatedName())
  388. .ifPresent({ namedClass ->
  389. ClassMapping mojangClassMapping = intermediaryToMojang.getOrCreateClassMapping(inputMappings.getFullObfuscatedName())
  390. .setDeobfuscatedName(namedClass.getFullDeobfuscatedName())
  391. for (FieldMapping fieldMapping : inputMappings.getFieldMappings()) {
  392. namedClass.getFieldMapping(fieldMapping.getDeobfuscatedName())
  393. .ifPresent({ namedField ->
  394. mojangClassMapping.getOrCreateFieldMapping(fieldMapping.getSignature())
  395. .setDeobfuscatedName(namedField.getDeobfuscatedName())
  396. })
  397. }
  398. for (MethodMapping methodMapping : inputMappings.getMethodMappings()) {
  399. namedClass.getMethodMapping(methodMapping.getDeobfuscatedSignature())
  400. .ifPresent({ namedMethod ->
  401. mojangClassMapping.getOrCreateMethodMapping(methodMapping.getSignature())
  402. .setDeobfuscatedName(namedMethod.getDeobfuscatedName())
  403. })
  404. }
  405. })
  406. })
  407. return intermediaryToMojang
  408. }
  409. @Override
  410. Set<File> resolve(boolean transitive) {
  411. return resolve()
  412. }
  413. @Override
  414. TaskDependency getBuildDependencies() {
  415. return { Collections.emptySet() }
  416. }
  417. @Override
  418. String getGroup() {
  419. return "net.mojang.minecraft"
  420. }
  421. @Override
  422. String getName() {
  423. return "mappings"
  424. }
  425. @Override
  426. String getVersion() {
  427. return extension.getMinecraftProvider().getMinecraftVersion()
  428. }
  429. @Override
  430. boolean contentEquals(Dependency dependency) {
  431. if (dependency instanceof MojangMappingsDependency) {
  432. return ((MojangMappingsDependency) dependency).extension.getMinecraftProvider().getMinecraftVersion() == getVersion()
  433. }
  434. return false
  435. }
  436. @Override
  437. Dependency copy() {
  438. return new MojangMappingsDependency(project, extension)
  439. }
  440. @Override
  441. String getReason() {
  442. return null
  443. }
  444. @Override
  445. void because(String s) {
  446. }
  447. private static void iterateClasses(MappingSet mappings, Closure<ClassMapping> consumer) {
  448. for (TopLevelClassMapping classMapping : mappings.getTopLevelClassMappings()) {
  449. iterateClass(classMapping, consumer)
  450. }
  451. }
  452. private static void iterateClass(ClassMapping classMapping, Consumer<ClassMapping> consumer) {
  453. consumer.accept(classMapping)
  454. for (InnerClassMapping innerClassMapping : classMapping.getInnerClassMappings()) {
  455. iterateClass(innerClassMapping, consumer)
  456. }
  457. }
  458. private static class TinyWriter extends TextMappingsWriter {
  459. private final String namespaceFrom
  460. private final String namespaceTo
  461. protected TinyWriter(Writer writer, String namespaceFrom, String namespaceTo) {
  462. super(writer)
  463. this.namespaceFrom = namespaceFrom
  464. this.namespaceTo = namespaceTo
  465. }
  466. @Override
  467. void write(MappingSet mappings) {
  468. writer.println("tiny\t2\t0\t" + namespaceFrom + "\t" + namespaceTo)
  469. iterateClasses(mappings, { classMapping ->
  470. writer.println("c\t" + classMapping.getFullObfuscatedName() + "\t" + classMapping.getFullDeobfuscatedName())
  471. for (FieldMapping fieldMapping : classMapping.getFieldMappings()) {
  472. fieldMapping.getType().ifPresent({ fieldType ->
  473. writer.println("\tf\t" + fieldType + "\t" + fieldMapping.getObfuscatedName() + "\t" + fieldMapping.getDeobfuscatedName())
  474. })
  475. }
  476. for (MethodMapping methodMapping : classMapping.getMethodMappings()) {
  477. writer.println("\tm\t" + methodMapping.getSignature().getDescriptor() + "\t" + methodMapping.getObfuscatedName() + "\t" + methodMapping.getDeobfuscatedName())
  478. }
  479. })
  480. }
  481. }
  482. }