TechReborn/build.gradle

354 lines
8.3 KiB
Groovy
Raw Normal View History

2015-04-10 00:17:30 +02:00
buildscript {
2017-04-14 21:35:09 +02:00
dependencies {
2021-02-08 20:58:47 +01:00
classpath 'org.kohsuke:github-api:1.114'
2017-04-14 21:35:09 +02:00
}
2015-04-10 00:17:30 +02:00
}
2021-02-08 20:58:47 +01:00
plugins {
id 'java'
id 'idea'
id 'eclipse'
id 'maven-publish'
id 'signing'
id "org.cadixdev.licenser" version "0.5.0"
id "fabric-loom" version "0.6-SNAPSHOT"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "de.undercouch.download" version "4.1.1"
}
2015-04-10 00:17:30 +02:00
2016-02-28 18:00:27 +01:00
sourceCompatibility = 1.8
targetCompatibility = 1.8
2015-11-24 20:37:15 +01:00
2015-04-10 10:43:45 +02:00
repositories {
2017-04-14 21:35:09 +02:00
maven {
name = "Modmuss50"
url = "https://maven.modmuss50.me/"
2017-04-14 21:35:09 +02:00
}
2020-01-17 18:07:27 +01:00
maven {
name = "BuildCraft"
url = "https://mod-buildcraft.com/maven"
content {
includeGroup "alexiil.mc.lib"
}
2020-01-17 18:07:27 +01:00
}
maven {
url = "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
2021-02-08 20:58:47 +01:00
maven {
url "https://maven.shedaniel.me/"
}
maven {
url = "https://jitpack.io"
content {
includeGroup "com.github.dexman545"
includeGroup "com.github.emilyploszaj"
includeGroup "io.github.onyxstudios.Cardinal-Components-API"
}
}
}
2021-04-22 14:05:24 +02:00
version = "3.8.3"
2015-12-30 18:23:45 +01:00
configurations {
2017-04-14 21:35:09 +02:00
shade
compile.extendsFrom shade
}
2015-04-10 00:17:30 +02:00
def ENV = System.getenv()
2019-09-15 14:43:04 +02:00
def build_number = ENV.BUILD_NUMBER ?: "local"
version = "${version}+build.$build_number"
2015-04-10 00:17:30 +02:00
license {
2017-04-14 21:35:09 +02:00
header file('HEADER')
include '**/*.java'
ignoreFailures = true //Stops the build from failing if a file does not have a license header
}
2015-04-10 00:17:30 +02:00
group = 'TechReborn'
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 2, 'minutes'
}
2015-04-10 00:17:30 +02:00
dependencies {
2021-02-08 20:58:47 +01:00
minecraft "com.mojang:minecraft:1.16.5"
mappings "net.fabricmc:yarn:1.16.5+build.4:v2"
modImplementation "net.fabricmc:fabric-loader:0.11.1"
2019-05-27 23:21:58 +02:00
2020-10-30 22:02:41 +01:00
//Fabric api
2021-02-08 20:58:47 +01:00
modImplementation "net.fabricmc.fabric-api:fabric-api:0.30.0+1.16"
2019-05-27 23:21:58 +02:00
2021-02-08 20:58:47 +01:00
optionalDependency "me.shedaniel:RoughlyEnoughItems:5.8.9"
2020-11-05 12:31:28 +01:00
disabledOptionalDependency ('com.github.emilyploszaj:trinkets:2.6.7')
2019-05-27 23:21:58 +02:00
2020-02-12 19:36:01 +01:00
def rcVersion = 'RebornCore:RebornCore-1.16:+'
modApi (rcVersion) {
2020-03-18 21:58:31 +01:00
exclude group: "net.fabricmc.fabric-api"
2019-07-25 15:16:30 +02:00
}
2019-09-15 14:43:04 +02:00
include rcVersion
2019-08-28 00:58:42 +02:00
2020-12-20 22:31:15 +01:00
modApi 'teamreborn:energy:0.1.1'
optionalDependency "com.github.dexman545:autoswitch-api:-SNAPSHOT"
}
2019-09-10 15:09:15 +02:00
def optionalDependency(String dep) {
dependencies.modRuntime (dep) {
2020-03-18 21:58:31 +01:00
exclude group: "net.fabricmc.fabric-api"
exclude module: "nbt-crafting"
}
dependencies.modCompileOnly (dep) {
2020-03-18 21:58:31 +01:00
exclude group: "net.fabricmc.fabric-api"
exclude module: "nbt-crafting"
}
2015-04-10 00:17:30 +02:00
}
2020-04-09 02:47:11 +02:00
def disabledOptionalDependency(String dep) {
dependencies.modCompileOnly (dep) {
exclude group: "net.fabricmc.fabric-api"
exclude module: "nbt-crafting"
}
}
processResources {
inputs.property "version", project.version
2017-04-14 21:35:09 +02:00
2021-02-08 20:58:47 +01:00
filesMatching("fabric.mod.json") {
expand "version": project.version
}
2021-02-08 20:58:47 +01:00
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
2017-06-20 19:54:45 +02:00
2021-02-08 20:58:47 +01:00
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = 8
}
2019-01-12 20:56:42 +01:00
}
2015-04-10 00:17:30 +02:00
jar {
2017-04-14 21:35:09 +02:00
exclude "**/*.psd"
classifier = 'universal'
2019-09-20 21:53:28 +02:00
from { crowdin.getDidWork() ? fileTree('build/translations').matching{exclude "**/en_US.json"} : null}
2019-12-08 23:40:29 +01:00
dependsOn 'fixTranslations'
dependsOn 'compileRecipes'
2015-04-10 00:17:30 +02:00
}
2015-11-22 17:24:50 +01:00
//Triggers crowdin to export the latest translations
task crowdinExport() {
onlyIf {
2021-02-08 20:58:47 +01:00
ENV.CROWDIN_KEY
}
doLast{
2021-02-08 20:58:47 +01:00
def apiKey = ENV.CROWDIN_KEY
def projectId = 'techreborn'
2018-08-31 17:00:31 +02:00
def response = new URL(sprintf('https://api.crowdin.com/api/project/%1$s/export?key=%2$s', [projectId, apiKey])).text
def metadata = new XmlParser().parseText(response)
project.logger.lifecycle("crowdin export status: " + metadata.@status)
}
}
2018-09-02 14:57:41 +02:00
task crowdin(type: Download, dependsOn: 'crowdinExport'){
src 'https://crowdin.com/backend/download/project/techreborn.zip'
2018-09-02 14:57:41 +02:00
dest file("build/translations.zip")
overwrite true
}
task cleanCrowdin(type: Delete){
delete 'build/translations'
}
//Renames the translation files to be all lower case
2018-09-02 14:57:41 +02:00
task renameCrowdin(type: Copy, dependsOn: ['crowdin', 'cleanCrowdin']){
mustRunAfter 'crowdin'
2018-09-02 14:57:41 +02:00
from zipTree(file("build/translations.zip"))
into file('build/translations')
rename {
String filename -> return filename.toLowerCase()
}
2019-12-08 23:40:29 +01:00
doFirst {
file('build/translations').deleteDir()
}
}
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
//Remove all translations that do not have an entry, ensures that minecraft falls back to EN_US over writing out an empty string.
task fixTranslations(dependsOn: ['renameCrowdin']) {
def jsonSlurper = new JsonSlurper()
doLast {
file('build/translations').eachFileRecurse(groovy.io.FileType.FILES) {
if(it.name.endsWith(".json")) {
def lang = jsonSlurper.parseText(it.text)
lang.values().removeIf { val -> val.empty}
it.text = JsonOutput.prettyPrint(JsonOutput.toJson(lang))
}
}
}
}
2019-07-25 15:16:30 +02:00
task sourcesJar(type: Jar, dependsOn: classes) {
classifier = "sources"
from sourceSets.main.allSource
}
2019-03-01 22:24:26 +01:00
publishing {
publications {
maven(MavenPublication) {
groupId 'TechReborn'
artifactId project.archivesBaseName
version project.version
2016-05-26 18:31:02 +02:00
2019-07-25 15:16:30 +02:00
artifact(remapJar) {
builtBy remapJar
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
repositories {
2021-02-08 20:58:47 +01:00
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
2018-02-19 16:01:37 +01:00
credentials {
2021-02-08 20:58:47 +01:00
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
2018-02-19 16:01:37 +01:00
}
2017-04-14 21:35:09 +02:00
}
}
}
}
2021-02-08 20:58:47 +01:00
if (ENV.SIGNING_KEY) {
signing {
useInMemoryPgpKeys(ENV.SIGNING_KEY, ENV.SIGNING_PASSWORD)
sign publishing.publications.maven
sign remapJar
}
task signAll(dependsOn: [signMavenPublication, signRemapJar, remapJar])
}
2016-11-26 20:05:10 +01:00
2018-04-02 11:42:02 +02:00
import com.google.gson.JsonArray
2017-04-14 21:35:09 +02:00
import groovy.util.XmlSlurper
import org.apache.commons.io.FileUtils
2016-11-26 20:05:10 +01:00
2019-05-26 13:37:59 +02:00
import java.util.function.Consumer
2021-02-08 20:58:47 +01:00
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
}
project {
id = "233564"
changelog = "A changelog can be found at https://github.com/TechReborn/TechReborn"
releaseType = ENV.RELEASE_CHANNEL ?: "release"
addGameVersion "1.16.5"
addGameVersion "Fabric"
mainArtifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"))
relations {
requiredDependency 'reborncore'
}
afterEvaluate {
uploadTask.dependsOn("remapJar")
2017-04-14 21:35:09 +02:00
}
2021-02-08 20:58:47 +01:00
}
2016-11-26 20:05:10 +01:00
2021-02-08 20:58:47 +01:00
options {
forgeGradleIntegration = false
}
}
def getBranch() {
def ENV = System.getenv()
if (ENV.GITHUB_REF) {
def branch = ENV.GITHUB_REF
return branch.substring(branch.lastIndexOf("/") + 1)
}
2016-11-26 20:05:10 +01:00
2021-02-08 20:58:47 +01:00
return "unknown"
}
2016-11-26 20:05:10 +01:00
2021-02-08 20:58:47 +01:00
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
2016-11-26 20:05:10 +01:00
2021-02-08 20:58:47 +01:00
task github(dependsOn: remapJar) {
onlyIf {
ENV.GITHUB_TOKEN
}
2016-11-26 20:05:10 +01:00
2021-02-08 20:58:47 +01:00
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)
2016-11-26 20:05:10 +01:00
2021-02-08 20:58:47 +01:00
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("${archivesBaseName}-${version}")
releaseBuilder.body("A changelog can be found at https://github.com/TechReborn/TechReborn")
releaseBuilder.commitish(getBranch())
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
2017-04-11 01:21:30 +02:00
}
2020-01-30 14:56:43 +01:00
}
// Generate recipe JSON for similar recipes
task compileRecipes {
def jsonSlurper = new JsonSlurper()
def recipePath = "build/resources/main/data/techreborn/recipes"
def smeltingPath = recipePath + "/smelting"
def blastingPath = recipePath + "/blasting"
doLast {
// Add any recipe filenames that don't match the regex here
String[] whitelist = []
def pattern = ~'^\\w+_(ingot(_from_dust)?)\\.json$'
file(smeltingPath).eachFileRecurse(groovy.io.FileType.FILES) {
if (whitelist.contains(it.name) || it.name ==~ pattern) {
def recipe = jsonSlurper.parseText(it.text)
// Final failsafe
if (["smelting", "minecraft:smelting"].contains(recipe.type)) {
recipe.type = "minecraft:blasting"
recipe.cookingtime = recipe.cookingtime / 2
File output = file(new File(blastingPath, it.name))
output.write(JsonOutput.prettyPrint(JsonOutput.toJson(recipe)))
}
}
}
}
2020-04-07 01:39:50 +02:00
}
2021-02-08 20:58:47 +01:00
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.modmuss50.me/TechReborn/TechReborn-1.16/maven-metadata.xml").text
def metadata = new XmlSlurper().parseText(xml)
def versions = metadata.versioning.versions.version*.text();
if (versions.contains(version)) {
throw new RuntimeException("${version} has already been released!")
}
}
}
if (ENV.SIGNING_KEY) {
publish.dependsOn signAll
}
github.mustRunAfter checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion