fabric/build.gradle

502 lines
12 KiB
Groovy
Raw Normal View History

2020-07-01 13:58:47 -04:00
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.135'
2020-07-01 13:58:47 -04:00
}
}
plugins {
2021-05-12 15:23:04 -04:00
id "java-library"
id "eclipse"
id "idea"
id "maven-publish"
id "fabric-loom" version "0.12.19" apply false
id "com.diffplug.spotless" version "6.5.1"
2021-05-12 15:23:04 -04:00
id "org.ajoberstar.grgit" version "3.1.0"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "1.1.0"
id "me.modmuss50.remotesign" version "0.2.4" apply false
}
def ENV = System.getenv()
def signingEnabled = ENV.SIGNING_SERVER
version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch()
2020-04-05 10:51:59 -04:00
logger.lifecycle("Building Fabric: " + version)
import org.apache.commons.codec.digest.DigestUtils
def getSubprojectVersion(project) {
// Get the version from the gradle.properties file
def version = project.properties["${project.name}-version"]
if (!version) {
throw new NullPointerException("Could not find version for " + project.name)
}
if (grgit == null) {
return version + "+nogit"
}
2021-04-14 13:35:48 -04:00
def latestCommits = grgit.log(paths: [project.name], maxCommits: 1)
if (latestCommits.isEmpty()) {
return version + "+uncommited"
}
return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2)
}
def getBranch() {
def ENV = System.getenv()
if (ENV.GITHUB_REF) {
def branch = ENV.GITHUB_REF
2019-08-27 15:40:07 -04:00
return branch.substring(branch.lastIndexOf("/") + 1)
2019-08-27 15:26:27 -04:00
}
if (grgit == null) {
return "unknown"
}
def branch = grgit.branch.current().name
return branch.substring(branch.lastIndexOf("/") + 1)
}
def moduleDependencies(project, List<String> depNames) {
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') }
project.dependencies {
deps.each {
2021-05-12 15:23:04 -04:00
api it
}
}
// As we manually handle the maven artifacts, we need to also manually specify the deps.
project.publishing {
publications {
mavenJava(MavenPublication) {
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
deps.each {
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}
}
allprojects {
group = "net.fabricmc.fabric-api"
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
if (signingEnabled) {
remoteSign {
requestUrl = ENV.SIGNING_SERVER
pgpAuthKey = ENV.SIGNING_PGP_KEY
jarAuthKey = ENV.SIGNING_JAR_KEY
afterEvaluate {
// PGP sign all maven publications.
sign publishing.publications.mavenJava
}
}
}
publishing {
setupRepositories(repositories)
}
if (it.name == "deprecated") return
2021-05-12 15:23:04 -04:00
apply plugin: "java-library"
apply plugin: "checkstyle"
apply plugin: "maven-publish"
apply plugin: "fabric-loom"
apply plugin: "com.diffplug.spotless"
apply plugin: "me.modmuss50.remotesign"
2018-12-14 13:48:37 -05:00
tasks.withType(JavaCompile).configureEach {
2021-11-16 13:41:10 -05:00
it.options.release = 17
}
2020-05-03 12:56:50 -04:00
sourceSets {
testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}
2021-05-12 15:23:04 -04:00
loom {
runtimeOnlyLog4j = true
2021-05-12 15:23:04 -04:00
runs {
testmodClient {
client()
ideConfigGenerated project.rootProject == project
name = "Testmod Client"
source sourceSets.testmod
}
testmodServer {
server()
ideConfigGenerated project.rootProject == project
name = "Testmod Server"
source sourceSets.testmod
}
}
}
dependencies {
minecraft "com.mojang:minecraft:$rootProject.minecraft_version"
mappings "net.fabricmc:yarn:${rootProject.minecraft_version}${project.yarn_version}:v2"
modApi "net.fabricmc:fabric-loader:${project.loader_version}"
}
loom {
shareRemapCaches = true
}
processResources {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER"))
}
}
java {
withSourcesJar()
}
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "9.1"
}
2021-05-12 15:23:04 -04:00
tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
if (signingEnabled) {
remoteSign {
sign remapJar
}
}
Add fabric-convention-tags-v1 (#2063) * Add framework for common-tags-v1 * Add javadoc to fabric tool tags * Fix wrong package arrangement * Add some more tags * Add more biome tags Thanks to TelepathicGrunt for the suggestions * Update fabric-common-tags-api-v1/src/main/java/net/fabricmc/fabric/api/tags/v1/CommonEnchantmentTags.java Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com> * Update fabric-common-tags-api-v1/src/main/java/net/fabricmc/fabric/api/tags/v1/CommonEnchantmentTags.java Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com> * Clarify enchantment tags * Add no-shulker tag * Add minecart tag * Begin work on datagen and populating tags * Add bucket tags * First pass at populating biome tags * Add boat tag * Fix missing inclusion of f:shears into c:shears * Hide fabric tool tags in datagen * Add weapon damage enhancement tag * Change impl package name to be inline with rest of fapi * Rename enchantment tags * Some cleanup * Populate blocktag datagen Remove crops tag * Add javadoc links to vanilla counterparts * Move datagen to its own sourceset * Fix package names for checkstyle * Populate more entries * Remove exclusion tag * Add license headers Fix checkstyle * Add missing nether quarts to ores tag * Use `worldgen/biome` instead of `biomes` for biome tags Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com> * Manually include all biomes for overworld * Remove ancient debris from NetheriteOres * Add and populate glass tags * Add and populate movement enhancement * Break up item tags * Add armour damage reduction tag * Add missing ore and related tags * Fix quartz tags * Add floral tag * Add golden carrot * Correct some biome tag issues * Separate SNOWY_PLAINS and PLAINS * Add SNOWY tag and remove snowy biomes from ICY * Correct enchantment tag Remove silk touch tag * Fix more biome issues * Add deep and shllow ocean tags * Add no-move tag * Remove netherite ores * Add shulker tags * Add raw ore * Add dye tags * Fif dye tags * Fix typo * Document some biome tags where the naming may not be clear * Remove tag mirroring for blocks and items * Rename module Remove unused methods * Rename impl package * Rename packages and module * Rename folder * Rename api classes * Add generateResources task to cover all resource generation tasks. * Add generated tags to repo * Fix ocean tag excluding shallow ocean * Iterate registry to generate foods tag * Remove cache, add to gitignore * Rename generated folder Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com> Co-authored-by: modmuss50 <modmuss50@gmail.com>
2022-04-17 14:23:48 -04:00
// Run this task after updating minecraft to regenerate any required resources
task generateResources {
group = "fabric"
}
}
// Apply auxiliary buildscripts to submodules
// This must be done after all plugins are applied to subprojects
apply from: "gradle/module-validation.gradle"
apply from: "gradle/module-versioning.gradle"
javadoc {
options {
2021-11-16 13:41:10 -05:00
source = "17"
encoding = "UTF-8"
charSet = "UTF-8"
memberLevel = JavadocMemberLevel.PACKAGE
links(
"https://guava.dev/releases/21.0/api/docs/",
"https://asm.ow2.io/javadoc/",
"https://docs.oracle.com/javase/8/docs/api/",
"http://jenkins.liteloader.com/job/Mixin/javadoc/",
"https://logging.apache.org/log4j/2.x/log4j-api/apidocs/"
// Need to add minecraft jd publication etc once there is one available
)
// Disable the crazy super-strict doclint tool in Java 8
addStringOption("Xdoclint:none", "-quiet")
}
allprojects.each {
source(it.sourceSets.main.allJava.srcDirs)
}
classpath = sourceSets.main.compileClasspath
include("**/api/**")
failOnError false
2018-12-22 10:21:31 -05:00
}
task javadocJar(type: Jar) {
dependsOn javadoc
from javadoc.destinationDir
//Set as `fatjavadoc` to prevent an ide form trying to use this javadoc, over using the modules javadoc
archiveClassifier = "fatjavadoc"
}
build.dependsOn javadocJar
2021-05-12 15:23:04 -04:00
loom {
runs {
gametest {
inherit testmodServer
name "Game Test"
// Enable the gametest runner
vmArg "-Dfabric-api.gametest"
vmArg "-Dfabric-api.gametest.report-file=${project.buildDir}/junit.xml"
runDir "build/gametest"
}
2021-05-12 15:23:04 -04:00
autoTestServer {
inherit testmodServer
name "Auto Test Server"
2021-05-12 15:23:04 -04:00
vmArg "-Dfabric.autoTest"
}
}
}
test.dependsOn runGametest
subprojects {
if (it.name == "deprecated") return
2020-05-03 12:56:50 -04:00
dependencies {
2021-05-12 15:23:04 -04:00
testmodImplementation sourceSets.main.output
// Make all modules depend on the gametest api (and thus res loader) to try and promote its usage.
if (project.name != "fabric-gametest-api-v1") {
testmodImplementation project(path: ':fabric-gametest-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-resource-loader-v0', configuration: 'namedElements')
}
// Make all testmods run with registry-sync-v0 as it is required to register new objects.
if (project.name != "fabric-registry-sync-v0") {
testmodRuntimeOnly project(path: ':fabric-registry-sync-v0', configuration: 'namedElements')
}
2020-05-03 12:56:50 -04:00
}
2019-04-23 19:14:43 -04:00
publishing {
publications {
mavenJava(MavenPublication) {
artifact(signingEnabled ? signRemapJar.output : remapJar) {
builtBy(signingEnabled ? signRemapJar : remapJar)
}
artifact(remapSourcesJar) {
builtBy remapSourcesJar
}
2019-04-23 19:14:43 -04:00
}
2019-07-24 17:07:45 -04:00
}
2019-04-23 19:14:43 -04:00
}
// We manually handle the pom generation
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
javadoc.enabled = false
afterEvaluate {
// Disable the gen sources task on sub projects
2021-11-03 14:57:29 -04:00
genSourcesWithFernFlower.enabled = false
genSourcesWithCfr.enabled = false
unpickJar.enabled = false
}
}
task remapMavenJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: jar) {
input = jar.archiveFile
archiveFileName = "${archivesBaseName}-${project.version}-maven.jar"
addNestedDependencies = false
}
build.dependsOn remapMavenJar
if (signingEnabled) {
remoteSign {
sign remapMavenJar
}
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(signingEnabled ? signRemapMavenJar.output : remapMavenJar) {
builtBy(signingEnabled ? signRemapMavenJar : remapMavenJar)
2019-04-23 19:14:43 -04:00
}
2019-04-23 19:14:43 -04:00
artifact(sourcesJar) {
builtBy remapSourcesJar
}
artifact javadocJar
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
subprojects.each {
// Dont depend on the deprecated modules in the main artifact.
if (it.path.startsWith(":deprecated")) return
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
2019-05-17 10:20:37 -04:00
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
}
}
}
}
// Required until the deprecation is removed. Fabric API's main jar that is published to maven does not contain sub modules.
2021-09-17 13:42:42 -04:00
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
void setupRepositories(RepositoryHandler repositories) {
//repositories.mavenLocal() // uncomment for testing
def ENV = System.getenv()
if (ENV.MAVEN_URL) {
repositories.maven {
url ENV.MAVEN_URL
if (ENV.MAVEN_USERNAME) {
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
}
2019-04-23 19:14:43 -04:00
}
}
}
}
subprojects.each {
if (it.name == "deprecated") return
remapJar.dependsOn("${it.path}:remapJar")
}
2020-05-03 12:56:50 -04:00
sourceSets {
testmod
}
// These modules are not included in the fat jar, maven will resolve them via the pom.
def devOnlyModules = [
"fabric-gametest-api-v1",
"fabric-data-generation-api-v1"
]
dependencies {
afterEvaluate {
subprojects.each {
if (it.name == "deprecated") return
api project(path: "${it.path}", configuration: "namedElements")
testmodImplementation project("${it.path}:").sourceSets.testmod.output
}
}
}
remapJar {
afterEvaluate {
subprojects.each {
if (it.name in devOnlyModules || it.name == "deprecated") return
// Include the signed or none signed jar from the sub project.
nestedJars.from project("${it.path}").tasks.getByName(signingEnabled ? "signRemapJar" : "remapJar")
}
}
}
2019-05-11 18:00:57 -04:00
curseforge {
if (ENV.CURSEFORGE_API_KEY) {
apiKey = ENV.CURSEFORGE_API_KEY
2019-05-11 18:00:57 -04:00
}
2019-05-11 18:00:57 -04:00
project {
id = "306612"
2021-07-23 12:05:52 -04:00
changelog = ENV.CHANGELOG ?: "No changelog provided"
2021-12-03 09:51:34 -05:00
releaseType = project.prerelease == "true" ? "beta" : "release"
2022-03-17 19:46:36 -04:00
addGameVersion "1.19-Snapshot"
addGameVersion "Fabric"
mainArtifact(signingEnabled ? signRemapJar.output : remapJar) {
displayName = "[$project.minecraft_version] Fabric API $project.version"
2019-05-11 18:00:57 -04:00
}
2019-05-11 18:00:57 -04:00
afterEvaluate {
uploadTask.dependsOn("remapJar")
}
}
options {
2019-05-11 18:00:57 -04:00
forgeGradleIntegration = false
}
}
2018-12-14 13:48:37 -05:00
if (signingEnabled) {
project.tasks.curseforge.dependsOn signRemapJar
build.dependsOn signRemapJar
}
2020-07-01 13:58:47 -04:00
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: (signingEnabled ? signRemapJar : remapJar)) {
2020-07-01 13:58:47 -04:00
onlyIf {
ENV.GITHUB_TOKEN
2020-07-01 13:58:47 -04:00
}
2020-07-01 13:58:47 -04:00
doLast {
def github = GitHub.connectUsingOAuth(ENV.GITHUB_TOKEN as String)
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)
2020-07-01 13:58:47 -04:00
def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("[$project.minecraft_version] Fabric API $project.version")
2021-07-23 12:05:52 -04:00
releaseBuilder.body(ENV.CHANGELOG ?: "No changelog provided")
2020-07-01 13:58:47 -04:00
releaseBuilder.commitish(getBranch())
2021-12-03 09:51:34 -05:00
releaseBuilder.prerelease(project.prerelease == "true")
2020-07-01 13:58:47 -04:00
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(signingEnabled ? signRemapJar.output.get().getAsFile() : remapJar.archiveFile.get().getAsFile(), "application/java-archive");
2020-07-01 13:58:47 -04:00
}
}
task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload, dependsOn: (signingEnabled ? signRemapJar : remapJar)) {
onlyIf {
ENV.MODRINTH_TOKEN
}
token = ENV.MODRINTH_TOKEN
projectId = "P7dR8mSH"
versionNumber = version
versionName = "[$project.minecraft_version] Fabric API $project.version"
2021-12-03 09:51:34 -05:00
releaseType = project.prerelease == "true" ? "beta" : "release"
2021-07-23 12:05:52 -04:00
changelog = ENV.CHANGELOG ?: "No changelog provided"
uploadFile = signingEnabled ? signRemapJar.output : remapJar
addGameVersion(project.minecraft_version)
addLoader('fabric')
}
// A task to ensure that the version being released has not already been released.
task checkVersion {
doFirst {
def xml = new URL("https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api/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!")
}
}
}
github.mustRunAfter checkVersion
modrinth.mustRunAfter checkVersion
publish.mustRunAfter checkVersion
project.tasks.curseforge.mustRunAfter checkVersion