TechReborn/build.gradle
2024-10-21 22:09:43 +02:00

379 lines
10 KiB
Groovy

plugins {
id 'java'
id 'groovy'
id 'java-library'
id 'idea'
id 'eclipse'
id 'maven-publish'
id 'com.diffplug.spotless' version '6.19.0'
id 'fabric-loom' version '1.3-SNAPSHOT'
id 'me.modmuss50.mod-publish-plugin' version '0.3.3'
}
repositories {
maven {
name "REI"
url "https://maven.shedaniel.me/"
content {
includeGroup "me.shedaniel"
includeGroup "me.shedaniel.cloth"
includeGroup "dev.architectury"
}
}
mavenCentral()
}
def ENV = System.getenv()
group = 'TechReborn'
allprojects {
version = project.mod_version + (ENV.GITHUB_ACTIONS ? "" : "+local")
apply plugin: "fabric-loom"
apply plugin: "maven-publish"
apply plugin: "com.diffplug.spotless"
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
loom {
runtimeOnlyLog4j = true
splitEnvironmentSourceSets()
}
// Shared deps between TR and RC
dependencies {
minecraft "com.mojang:minecraft:${project.minecraft_version}"
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}"
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"
it.options.release = 17
}
java {
withSourcesJar()
}
publishing {
publications {
register("maven", MavenPublication) {
groupId project.name
artifactId project.archivesBaseName + "-" + (ENV.GITHUB_REF_NAME ?: "local")
version project.version
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)
}
}
}
loom {
accessWidenerPath = file("src/main/resources/techreborn.accesswidener")
}
sourceSets {
// Add a data gen sourceset
datagen {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
}
gametest {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += main.output
runtimeClasspath += main.output
}
main {
resources {
srcDirs += [
'src/main/generated'
]
}
}
}
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
dependencies {
api project(path: ":RebornCore", configuration: "namedElements")
clientImplementation project(":RebornCore").sourceSets.client.output
include project(":RebornCore")
optionalClientDependency("me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}", true)
// Use groovy for datagen/gametest, if you are copying this you prob dont want it.
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"
}
}
def optionalClientDependency(String dep, runtime = true) {
def exclude = {
exclude group: "net.fabricmc.fabric-api"
exclude group: "net.fabricmc"
}
dependencies.modClientCompileOnly(dep, exclude)
if (runtime) {
dependencies.modClientRuntimeOnly(dep, exclude)
}
}
loom {
runs {
// 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")}"
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
jar {
exclude "**/*.psd"
from file('src/main/generated')
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
dependsOn 'fixTranslations'
dependsOn 'runDatagen'
}
tasks.register('crowdinExport') {
description "Triggers crowdin to export the latest translations"
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)
}
}
def translationsUrl = "https://crowdin.com/backend/download/project/techreborn.zip"
def translationsZip = file("build/translations.zip")
// tasks.register('crowdin') {
// dependsOn crowdinExport
// description "Downloads translations from CrowdIn"
// outputs.file translationsZip
// doLast {
// translationsZip.bytes = new URL(translationsUrl).bytes
// }
// }
tasks.register('cleanCrowdin', Delete) {
description "Delete old translations"
delete 'build/translations'
}
clean.dependsOn cleanCrowdin
tasks.register('renameCrowdin', Copy) {
// dependsOn crowdin
description "Renames the translation files to be all lower case"
from zipTree(translationsZip)
into file('build/translations')
rename {
String filename -> return filename.toLowerCase()
}
doFirst {
file('build/translations').deleteDir()
}
}
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
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"
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
tasks.register('copyTranslationsToGenerated', Copy) {
dependsOn fixTranslations
from file('build/translations')
into file('src/main/generated')
}
publishMods {
changelog = providers.environmentVariable("CHANGELOG").orElse("No changelog provided")
version = project.version
type = providers.environmentVariable("RELEASE_CHANNEL").orElse("release").map {it == "release" ? STABLE : BETA }
modLoaders.add("fabric")
dryRun = providers.environmentVariable("CURSEFORGE_API_KEY").getOrNull() == null
def options = curseforgeOptions {
accessToken = providers.environmentVariable("CURSEFORGE_API_KEY")
minecraftVersions.add("1.20.1")
requires {
slug = "fabric-api"
}
}
curseforge("curseforgeTechReborn") {
from options
projectId = "233564"
file = remapJar.archiveFile
requires {
slug = "reborncore"
}
optional {
slug = "roughly-enough-items"
}
}
curseforge("curseforgeRebornCore") {
from options
projectId = "237903"
file = project(":RebornCore").tasks.remapJar.archiveFile
displayName = "RebornCore $version"
}
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")
}
}