TechReborn/build.gradle

380 lines
10 KiB
Groovy
Raw Normal View History

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'
2023-06-28 00:02:00 +02:00
id 'com.diffplug.spotless' version '6.19.0'
id 'fabric-loom' version '1.3-SNAPSHOT'
2023-08-09 14:09:43 +02:00
id 'me.modmuss50.mod-publish-plugin' version '0.3.3'
2021-02-08 20:58:47 +01:00
}
2015-04-10 00:17:30 +02:00
2015-04-10 10:43:45 +02:00
repositories {
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
}
mavenCentral()
}
2015-04-10 00:17:30 +02:00
def ENV = System.getenv()
2021-05-29 14:29:04 +02:00
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"
apply plugin: "com.diffplug.spotless"
2021-11-16 23:38:31 +01:00
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
loom {
runtimeOnlyLog4j = true
2022-05-19 22:45:31 +02:00
splitEnvironmentSourceSets()
}
// 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 {
2023-06-28 00:02:00 +02:00
register("maven", MavenPublication) {
groupId project.name
2023-08-09 14:09:43 +02:00
artifactId project.archivesBaseName + "-" + (ENV.GITHUB_REF_NAME ?: "local")
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
}
}
}
}
}
spotless {
java {
licenseHeaderFile(file("HEADER"))
removeUnusedImports()
indentWithTabs()
trimTrailingWhitespace()
endWithNewline()
}
}
}
spotless {
groovy {
licenseHeaderFile(file("HEADER"))
indentWithTabs()
trimTrailingWhitespace()
endWithNewline()
}
}
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'
]
}
}
}
2022-05-19 22:45:31 +02:00
allprojects {
loom {
mods {
reborncore {
sourceSet project(":RebornCore").sourceSets.main
sourceSet project(":RebornCore").sourceSets.client
}
techreborn {
sourceSet project(":").sourceSets.main
sourceSet project(":").sourceSets.client
}
"techreborn-datagen" {
sourceSet project(":").sourceSets.datagen
}
"techreborn-gametest" {
sourceSet project(":").sourceSets.gametest
}
}
}
}
// 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")
clientImplementation project(":RebornCore").sourceSets.client.output
2022-05-19 22:45:31 +02:00
include project(":RebornCore")
2023-05-31 17:39:45 +02:00
optionalClientDependency("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}", true)
2022-08-09 00:04:22 +02:00
2021-12-03 16:58:43 +01:00
// Use groovy for datagen/gametest, if you are copying this you prob dont want it.
2023-03-14 20:05:58 +01:00
gametestImplementation 'org.apache.groovy:groovy:4.0.10'
datagenImplementation 'org.apache.groovy:groovy:4.0.10'
gametestImplementation ("com.google.truth:truth:1.1.3") {
exclude module: "guava"
exclude module: "asm"
}
}
2019-09-10 15:09:15 +02:00
2022-08-09 00:04:22 +02:00
def optionalClientDependency(String dep, runtime = true) {
def exclude = {
exclude group: "net.fabricmc.fabric-api"
exclude group: "net.fabricmc"
}
2022-08-09 00:04:22 +02:00
dependencies.modClientCompileOnly(dep, exclude)
2022-08-09 00:04:22 +02:00
if (runtime) {
dependencies.modClientRuntimeOnly(dep, exclude)
}
}
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
}
}
}
runDatagen {
// Doesn't re-run the task when its up-to date
outputs.dir('src/main/generated')
}
tasks.sourcesJar.dependsOn runDatagen
2015-04-10 00:17:30 +02:00
jar {
2017-04-14 21:35:09 +02:00
exclude "**/*.psd"
from file('src/main/generated')
2024-10-21 22:09:43 +02:00
from { fileTree('build/translations').matching{exclude "**/en_US.json"} }
// 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
}
2023-06-28 00:02:00 +02:00
tasks.register('crowdinExport') {
description "Triggers crowdin to export the latest translations"
2023-06-28 00:02:00 +02:00
onlyIf {
ENV.CROWDIN_KEY
}
doLast {
def apiKey = ENV.CROWDIN_KEY
def projectId = 'techreborn'
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)
}
}
2023-06-28 00:02:00 +02:00
def translationsUrl = "https://crowdin.com/backend/download/project/techreborn.zip"
def translationsZip = file("build/translations.zip")
2024-10-21 22:09:43 +02:00
// tasks.register('crowdin') {
// dependsOn crowdinExport
// description "Downloads translations from CrowdIn"
// outputs.file translationsZip
2023-06-28 00:02:00 +02:00
2024-10-21 22:09:43 +02:00
// doLast {
// translationsZip.bytes = new URL(translationsUrl).bytes
// }
// }
2018-09-02 14:57:41 +02:00
2023-06-28 00:02:00 +02:00
tasks.register('cleanCrowdin', Delete) {
description "Delete old translations"
2023-06-28 00:02:00 +02:00
delete 'build/translations'
}
2023-06-28 00:02:00 +02:00
clean.dependsOn cleanCrowdin
2023-06-28 00:02:00 +02:00
tasks.register('renameCrowdin', Copy) {
2024-10-21 22:09:43 +02:00
// dependsOn crowdin
description "Renames the translation files to be all lower case"
2023-06-28 00:02:00 +02:00
from zipTree(translationsZip)
into file('build/translations')
rename {
String filename -> return filename.toLowerCase()
}
doFirst {
file('build/translations').deleteDir()
}
2019-12-08 23:40:29 +01:00
}
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
2019-12-08 23:40:29 +01:00
2023-06-28 00:02:00 +02:00
tasks.register('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"
2023-06-28 00:02:00 +02: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))
}
}
}
}
// Use to test the crowdin translations in a dev env
2023-06-28 00:02:00 +02:00
tasks.register('copyTranslationsToGenerated', Copy) {
dependsOn fixTranslations
from file('build/translations')
into file('src/main/generated')
}
publishMods {
2023-08-09 14:09:43 +02:00
changelog = providers.environmentVariable("CHANGELOG").orElse("No changelog provided")
version = project.version
2023-08-09 14:09:43 +02:00
type = providers.environmentVariable("RELEASE_CHANNEL").orElse("release").map {it == "release" ? STABLE : BETA }
modLoaders.add("fabric")
2023-08-09 14:09:43 +02:00
dryRun = providers.environmentVariable("CURSEFORGE_API_KEY").getOrNull() == null
2021-02-08 20:58:47 +01:00
def options = curseforgeOptions {
accessToken = providers.environmentVariable("CURSEFORGE_API_KEY")
minecraftVersions.add("1.20.1")
2021-02-08 20:58:47 +01:00
requires {
slug = "fabric-api"
}
}
2021-02-08 20:58:47 +01:00
curseforge("curseforgeTechReborn") {
from options
projectId = "233564"
file = remapJar.archiveFile
2016-11-26 20:05:10 +01:00
requires {
slug = "reborncore"
}
optional {
slug = "roughly-enough-items"
}
}
curseforge("curseforgeRebornCore") {
from options
projectId = "237903"
file = project(":RebornCore").tasks.remapJar.archiveFile
2023-08-09 14:25:06 +02:00
displayName = "RebornCore $version"
}
2021-02-08 20:58:47 +01:00
2023-08-09 14:09:43 +02:00
github {
file = remapJar.archiveFile
additionalFiles.from project(":RebornCore").tasks.remapJar.archiveFile
repository = providers.environmentVariable("GITHUB_REPOSITORY").orElse("dryrun")
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = providers.environmentVariable("GITHUB_REF_NAME").orElse("dryrun")
2021-02-08 20:58:47 +01:00
}
}