build.gradle 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565
  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 "1.16.3"
  254. addGameVersion "Java 8"
  255. addGameVersion "Fabric"
  256. relations {
  257. requiredDependency "fabric-api"
  258. embeddedLibrary "cloth-api"
  259. embeddedLibrary "cloth-config"
  260. embeddedLibrary "auto-config-updated-api"
  261. }
  262. mainArtifact(file("${project.buildDir}/libs/${project.archivesBaseName}-${project.version}.jar")) {
  263. displayName = "[Fabric $project.supported_version] v$project.version"
  264. }
  265. addArtifact(file("${project.buildDir}/libs/${project.archivesBaseName}-${project.version}-sources.jar")) {
  266. displayName = "[Fabric $project.supported_version] v$project.version Sources"
  267. }
  268. afterEvaluate {
  269. uploadTask.dependsOn("build")
  270. }
  271. }
  272. }
  273. options {
  274. forgeGradleIntegration = false
  275. javaVersionAutoDetect = false
  276. }
  277. }
  278. publishing {
  279. publications {
  280. mavenJava(MavenPublication) {
  281. artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}-maven.jar")) {
  282. builtBy remapMavenJar
  283. }
  284. artifact(sourcesJar) {
  285. builtBy remapSourcesJar
  286. }
  287. pom.withXml {
  288. def depsNode = asNode().appendNode("dependencies")
  289. subprojects.each {
  290. def depNode = depsNode.appendNode("dependency")
  291. depNode.appendNode("groupId", it.group)
  292. depNode.appendNode("artifactId", it.name)
  293. depNode.appendNode("version", it.version)
  294. depNode.appendNode("scope", "compile")
  295. }
  296. }
  297. }
  298. }
  299. repositories {
  300. if (project.hasProperty('danielshe_pass')) {
  301. maven {
  302. url = "http://deploy.modmuss50.me/"
  303. credentials {
  304. username = "danielshe"
  305. password = project.getProperty('danielshe_pass')
  306. }
  307. }
  308. }
  309. }
  310. }
  311. /*
  312. The following code is licensed under MIT License.
  313. Copyright (c) 2016 FabricMC
  314. Permission is hereby granted, free of charge, to any person obtaining a copy
  315. of this software and associated documentation files (the "Software"), to deal
  316. in the Software without restriction, including without limitation the rights
  317. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  318. copies of the Software, and to permit persons to whom the Software is
  319. furnished to do so, subject to the following conditions:
  320. The above copyright notice and this permission notice shall be included in all
  321. copies or substantial portions of the Software.
  322. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  323. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  324. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  325. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  326. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  327. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  328. SOFTWARE.
  329. */
  330. class MojangMappingsDependency implements SelfResolvingDependency {
  331. private final Project project
  332. private final LoomGradleExtension extension
  333. MojangMappingsDependency(Project project, LoomGradleExtension extension) {
  334. this.project = project
  335. this.extension = extension
  336. }
  337. @Override
  338. Set<File> resolve() {
  339. Path mappingsDir = extension.getMappingsProvider().getMappingsDir()
  340. Path mappingsFile = mappingsDir.resolve(String.format("net.mojang.minecraft-mappings-%s.tiny", getVersion()))
  341. Path clientMappings = mappingsDir.resolve(String.format("net.mojang.minecraft.mappings-%s-client.map", getVersion()))
  342. Path serverMappings = mappingsDir.resolve(String.format("net.mojang.minecraft.mappings-%s-server.map", getVersion()))
  343. if (!Files.exists(mappingsFile) || project.getGradle().getStartParameter().isRefreshDependencies()) {
  344. MappingSet mappingSet
  345. try {
  346. mappingSet = getMappingsSet(clientMappings, serverMappings)
  347. Writer writer = new StringWriter()
  348. new TinyWriter(writer, "intermediary", "named").write(mappingSet)
  349. Files.deleteIfExists(mappingsFile)
  350. ZipUtil.pack([
  351. new ByteSource("mappings/mappings.tiny", writer.toString().getBytes(StandardCharsets.UTF_8))
  352. ] as ZipEntrySource[], mappingsFile.toFile())
  353. writer.close()
  354. } catch (IOException e) {
  355. throw new RuntimeException("Failed to resolve Mojang mappings", e)
  356. }
  357. }
  358. return Collections.singleton(mappingsFile.toFile())
  359. }
  360. private MappingSet getMappingsSet(Path clientMappings, Path serverMappings) throws IOException {
  361. MinecraftVersionInfo versionInfo = extension.getMinecraftProvider().getVersionInfo()
  362. if (versionInfo.downloads.get("client_mappings") == null) {
  363. throw new RuntimeException("Failed to find official mojang mappings for " + getVersion())
  364. }
  365. String clientMappingsUrl = versionInfo.downloads.get("client_mappings").url
  366. String serverMappingsUrl = versionInfo.downloads.get("server_mappings").url
  367. DownloadUtil.downloadIfChanged(new URL(clientMappingsUrl), clientMappings.toFile(), project.getLogger())
  368. DownloadUtil.downloadIfChanged(new URL(serverMappingsUrl), serverMappings.toFile(), project.getLogger())
  369. MappingSet mappings = MappingSet.create()
  370. BufferedReader clientBufferedReader = Files.newBufferedReader(clientMappings, StandardCharsets.UTF_8)
  371. BufferedReader serverBufferedReader = Files.newBufferedReader(serverMappings, StandardCharsets.UTF_8)
  372. ProGuardReader proGuardReaderClient = new ProGuardReader(clientBufferedReader)
  373. ProGuardReader proGuardReaderServer = new ProGuardReader(serverBufferedReader)
  374. proGuardReaderClient.read(mappings)
  375. proGuardReaderServer.read(mappings)
  376. clientBufferedReader.close()
  377. serverBufferedReader.close()
  378. proGuardReaderClient.close()
  379. proGuardReaderServer.close()
  380. MappingSet officialToNamed = mappings.reverse()
  381. MappingSet intermediaryToOfficial
  382. BufferedReader reader = Files.newBufferedReader(extension.getMappingsProvider().getIntermediaryTiny(), StandardCharsets.UTF_8)
  383. intermediaryToOfficial = new TinyMappingsReader(TinyMappingFactory.loadWithDetection(reader), "intermediary", "official").read()
  384. reader.close()
  385. MappingSet intermediaryToMojang = MappingSet.create()
  386. // Merging. Don't use MappingSet#merge
  387. iterateClasses(intermediaryToOfficial, { inputMappings ->
  388. officialToNamed.getClassMapping(inputMappings.getFullDeobfuscatedName())
  389. .ifPresent({ namedClass ->
  390. ClassMapping mojangClassMapping = intermediaryToMojang.getOrCreateClassMapping(inputMappings.getFullObfuscatedName())
  391. .setDeobfuscatedName(namedClass.getFullDeobfuscatedName())
  392. for (FieldMapping fieldMapping : inputMappings.getFieldMappings()) {
  393. namedClass.getFieldMapping(fieldMapping.getDeobfuscatedName())
  394. .ifPresent({ namedField ->
  395. mojangClassMapping.getOrCreateFieldMapping(fieldMapping.getSignature())
  396. .setDeobfuscatedName(namedField.getDeobfuscatedName())
  397. })
  398. }
  399. for (MethodMapping methodMapping : inputMappings.getMethodMappings()) {
  400. namedClass.getMethodMapping(methodMapping.getDeobfuscatedSignature())
  401. .ifPresent({ namedMethod ->
  402. mojangClassMapping.getOrCreateMethodMapping(methodMapping.getSignature())
  403. .setDeobfuscatedName(namedMethod.getDeobfuscatedName())
  404. })
  405. }
  406. })
  407. })
  408. return intermediaryToMojang
  409. }
  410. @Override
  411. Set<File> resolve(boolean transitive) {
  412. return resolve()
  413. }
  414. @Override
  415. TaskDependency getBuildDependencies() {
  416. return { Collections.emptySet() }
  417. }
  418. @Override
  419. String getGroup() {
  420. return "net.mojang.minecraft"
  421. }
  422. @Override
  423. String getName() {
  424. return "mappings"
  425. }
  426. @Override
  427. String getVersion() {
  428. return extension.getMinecraftProvider().getMinecraftVersion()
  429. }
  430. @Override
  431. boolean contentEquals(Dependency dependency) {
  432. if (dependency instanceof MojangMappingsDependency) {
  433. return ((MojangMappingsDependency) dependency).extension.getMinecraftProvider().getMinecraftVersion() == getVersion()
  434. }
  435. return false
  436. }
  437. @Override
  438. Dependency copy() {
  439. return new MojangMappingsDependency(project, extension)
  440. }
  441. @Override
  442. String getReason() {
  443. return null
  444. }
  445. @Override
  446. void because(String s) {
  447. }
  448. private static void iterateClasses(MappingSet mappings, Closure<ClassMapping> consumer) {
  449. for (TopLevelClassMapping classMapping : mappings.getTopLevelClassMappings()) {
  450. iterateClass(classMapping, consumer)
  451. }
  452. }
  453. private static void iterateClass(ClassMapping classMapping, Consumer<ClassMapping> consumer) {
  454. consumer.accept(classMapping)
  455. for (InnerClassMapping innerClassMapping : classMapping.getInnerClassMappings()) {
  456. iterateClass(innerClassMapping, consumer)
  457. }
  458. }
  459. private static class TinyWriter extends TextMappingsWriter {
  460. private final String namespaceFrom
  461. private final String namespaceTo
  462. protected TinyWriter(Writer writer, String namespaceFrom, String namespaceTo) {
  463. super(writer)
  464. this.namespaceFrom = namespaceFrom
  465. this.namespaceTo = namespaceTo
  466. }
  467. @Override
  468. void write(MappingSet mappings) {
  469. writer.println("tiny\t2\t0\t" + namespaceFrom + "\t" + namespaceTo)
  470. iterateClasses(mappings, { classMapping ->
  471. writer.println("c\t" + classMapping.getFullObfuscatedName() + "\t" + classMapping.getFullDeobfuscatedName())
  472. for (FieldMapping fieldMapping : classMapping.getFieldMappings()) {
  473. fieldMapping.getType().ifPresent({ fieldType ->
  474. writer.println("\tf\t" + fieldType + "\t" + fieldMapping.getObfuscatedName() + "\t" + fieldMapping.getDeobfuscatedName())
  475. })
  476. }
  477. for (MethodMapping methodMapping : classMapping.getMethodMappings()) {
  478. writer.println("\tm\t" + methodMapping.getSignature().getDescriptor() + "\t" + methodMapping.getObfuscatedName() + "\t" + methodMapping.getDeobfuscatedName())
  479. }
  480. })
  481. }
  482. }
  483. }