TechReborn/build.gradle

402 lines
10 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-11-28 15:53:01 +01:00
classpath 'org.kohsuke:github-api:1.135'
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 'groovy'
id 'java-library'
2021-02-08 20:58:47 +01:00
id 'idea'
id 'eclipse'
id 'maven-publish'
id "org.cadixdev.licenser" version "0.6.1"
id "fabric-loom" version "0.11-SNAPSHOT"
2021-02-08 20:58:47 +01:00
id "com.matthewprenger.cursegradle" version "1.4.0"
id "de.undercouch.download" version "4.1.1"
}
2015-04-10 00:17:30 +02:00
2015-04-10 10:43:45 +02:00
repositories {
maven {
url = "https://www.cursemaven.com"
content {
includeGroup "curse.maven"
}
}
maven {
name "DashLoader"
url = "https://maven.oskarstrom.net"
content {
includeGroup "net.oskarstrom"
}
}
2021-02-08 20:58:47 +01:00
maven {
name "REI"
2021-02-08 20:58:47 +01:00
url "https://maven.shedaniel.me/"
2021-07-23 01:43:57 +02:00
content {
includeGroup "me.shedaniel"
includeGroup "me.shedaniel.cloth"
includeGroup "dev.architectury"
}
2021-02-08 20:58:47 +01:00
}
2021-07-23 01:43:57 +02:00
maven {
url = 'https://ladysnake.jfrog.io/artifactory/mods'
content {
// Trinkets dependency
2021-07-23 01:43:57 +02:00
includeGroup "io.github.onyxstudios.Cardinal-Components-API"
}
}
maven {
url = "https://jitpack.io"
content {
// Trinkets API
includeGroup "com.github.emilyploszaj"
}
}
}
2015-04-10 00:17:30 +02:00
def ENV = System.getenv()
2021-05-29 14:29:04 +02:00
license {
2017-04-14 21:35:09 +02:00
header file('HEADER')
include '**/*.java'
include '**/*.groovy'
2017-04-14 21:35:09 +02:00
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'
allprojects {
version = project.mod_version + (ENV.GITHUB_ACTIONS ? "" : "+local")
apply plugin: "fabric-loom"
2021-05-29 14:29:04 +02:00
apply plugin: "maven-publish"
2021-11-16 23:38:31 +01:00
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
loom {
runtimeOnlyLog4j = true
}
// Shared deps between TR and RC
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
2021-11-21 12:50:00 +01:00
mappings "net.fabricmc:yarn:${project.yarn_version}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
//Fabric api
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fapi_version}"
2021-11-16 23:38:31 +01:00
include(modApi("teamreborn:energy:${project.energy_version}")) {
transitive = false
}
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
2021-11-16 23:38:31 +01:00
it.options.release = 17
}
java {
withSourcesJar()
}
publishing {
publications {
maven(MavenPublication) {
groupId project.name
2021-05-29 14:29:04 +02:00
artifactId project.archivesBaseName + "-" + getBranch()
version project.version
2021-11-11 11:54:33 +01:00
from components.java
}
}
repositories {
if (ENV.MAVEN_URL) {
maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
}
}
}
}
}
processResources {
doLast {
// Depend on the reborn core version it was built against
fileTree(dir: outputs.files.asPath, include: "fabric.mod.json").each {
def jsonSlurper = new JsonSlurper()
def modJson = jsonSlurper.parseText(it.text)
modJson.depends.reborncore = "~${project.version}"
it.text = JsonOutput.toJson(modJson)
}
}
}
2021-11-17 22:28:26 +01:00
loom {
accessWidenerPath = file("src/main/resources/techreborn.accesswidener")
}
sourceSets {
2021-12-03 16:58:43 +01:00
// Add a data gen sourceset
datagen {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
2021-12-03 16:58:43 +01:00
}
gametest {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
}
main {
resources {
srcDirs += [
'src/main/generated'
]
}
}
}
// TechReborn specific dependencies
2015-04-10 00:17:30 +02:00
dependencies {
2021-11-11 11:54:33 +01:00
api project(path: ":RebornCore", configuration: "namedElements")
include project(":RebornCore")
2021-11-21 12:50:00 +01:00
optionalDependency "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
disabledOptionalDependency "com.github.emilyploszaj:trinkets:${project.trinkets_version}"
disabledOptionalDependency "net.oskarstrom:DashLoader:${project.dashloader_version}"
2021-12-03 16:58:43 +01:00
// Use groovy for datagen/gametest, if you are copying this you prob dont want it.
gametestImplementation 'org.apache.groovy:groovy:4.0.0'
datagenImplementation 'org.apache.groovy:groovy:4.0.0'
gametestImplementation ("com.google.truth:truth:1.1.3") {
exclude module: "guava"
exclude module: "asm"
}
}
2019-09-10 15:09:15 +02:00
def optionalDependency(String dep) {
2021-11-11 11:54:33 +01:00
dependencies.modLocalRuntime (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"
}
}
loom {
runs {
2021-12-03 16:58:43 +01:00
// Add a data gen run config
datagen {
server()
name "Data Generation"
vmArg "-Dfabric-api.datagen"
vmArg "-Dfabric-api.datagen.output-dir=${file("src/main/generated")}"
2021-12-03 16:58:43 +01:00
vmArg "-Dfabric-api.datagen.modid=techreborn-datagen"
runDir "build/datagen"
source sourceSets.datagen
}
// Use to run the tests
gametest {
server()
name "Game Test"
vmArg "-Dfabric-api.gametest"
vmArg "-Dfabric-api.gametest.report-file=${project.buildDir}/junit.xml"
runDir "build/gametest"
source sourceSets.gametest
}
// Use to debug tests
gametestClient {
client()
name "Game Test Client"
source sourceSets.gametest
}
}
}
test.dependsOn runGametest
runDatagen {
// Doesn't re-run the task when its up-to date
outputs.dir('src/main/generated')
}
2015-04-10 00:17:30 +02:00
jar {
2017-04-14 21:35:09 +02:00
exclude "**/*.psd"
from file('src/main/generated')
2019-09-20 21:53:28 +02:00
from { crowdin.getDidWork() ? fileTree('build/translations').matching{exclude "**/en_US.json"} : null}
// A bit of a hack to allow the generated sources when they already exist
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
2019-12-08 23:40:29 +01:00
dependsOn 'fixTranslations'
dependsOn 'runDatagen'
2015-04-10 00:17:30 +02:00
}
task crowdinExport() {
description "Triggers crowdin to export the latest translations"
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'){
description "Downloads translations from CrowdIn"
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){
description "Delete old translations"
2018-09-02 14:57:41 +02:00
delete 'build/translations'
}
2018-09-02 14:57:41 +02:00
task renameCrowdin(type: Copy, dependsOn: ['crowdin', 'cleanCrowdin']){
description "Renames the translation files to be all lower case"
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
2019-12-08 23:40:29 +01:00
task fixTranslations(dependsOn: ['renameCrowdin']) {
description "Remove all translations that do not have an entry, ensures that minecraft falls back to EN_US over writing out an empty string"
2019-12-08 23:40:29 +01:00
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))
}
}
}
}
import groovy.util.XmlSlurper
2019-05-26 13:37:59 +02:00
2021-02-08 20:58:47 +01:00
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
}
project {
id = "233564"
2021-07-20 21:00:11 +02:00
changelog = ENV.CHANGELOG ?: "No changelog provided"
2021-02-08 20:58:47 +01:00
releaseType = ENV.RELEASE_CHANNEL ?: "release"
2022-03-02 03:41:20 +01:00
addGameVersion "1.18.2" // Also update in RebornCore/build.gradle
2021-02-08 20:58:47 +01:00
addGameVersion "Fabric"
2021-11-11 11:54:33 +01:00
mainArtifact remapJar
2021-02-08 20:58:47 +01:00
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
import org.kohsuke.github.GHReleaseBuilder
2021-02-08 20:58:47 +01:00
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}")
2021-07-20 20:59:04 +02:00
releaseBuilder.body(ENV.CHANGELOG)
2021-02-08 20:58:47 +01:00
releaseBuilder.commitish(getBranch())
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive")
ghRelease.uploadAsset(file("RebornCore/build/libs/RebornCore-${version}.jar"), "application/java-archive")
2017-04-11 01:21:30 +02:00
}
2020-01-30 14:56:43 +01:00
}
github.dependsOn(project(":RebornCore").getTasks().getByName("remapJar"))
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 {
2021-05-29 14:29:04 +02:00
def xml = new URL("https://maven.modmuss50.me/TechReborn/TechReborn-1.17/maven-metadata.xml").text
2021-02-08 20:58:47 +01:00
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!")
}
}
}
github.mustRunAfter checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion