fabric/build.gradle

423 lines
10 KiB
Groovy
Raw Normal View History

2020-07-01 13:58:47 -04:00
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.114'
}
}
plugins {
id "java"
id "eclipse"
id "idea"
id "maven-publish"
2020-12-12 10:24:19 -05:00
id "fabric-loom" version "0.5.43" apply false
id "net.minecrell.licenser" version "0.4.1"
id "org.ajoberstar.grgit" version "3.1.1"
id "com.matthewprenger.cursegradle" version "1.4.0"
id "com.modrinth.minotaur" version "1.1.0"
}
def ENV = System.getenv()
class Globals {
2021-05-05 01:59:13 -04:00
static def baseVersion = "0.34.1"
2021-04-28 18:29:12 -04:00
static def mcVersion = "21w17a"
static def yarnVersion = "+build.2"
static def loaderVersion = "0.10.5+build.213"
static def preRelease = true
}
version = Globals.baseVersion + "+" + (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
import net.fabricmc.loom.task.RunClientTask
import net.fabricmc.loom.task.RunServerTask
def getSubprojectVersion(project, version) {
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(Globals.mcVersion).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: 'dev') }
project.dependencies {
deps.each {
compile it
}
}
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 {
apply plugin: "checkstyle"
apply plugin: "maven-publish"
apply plugin: "fabric-loom"
apply plugin: "net.minecrell.licenser"
2018-12-14 13:48:37 -05:00
tasks.withType(JavaCompile).configureEach {
def targetVersion = 8
if (JavaVersion.current().isJava9Compatible()) {
it.options.release = targetVersion
} else {
sourceCompatibility = JavaVersion.toVersion(targetVersion)
targetCompatibility = JavaVersion.toVersion(targetVersion)
}
}
2019-04-24 13:15:08 -04:00
group = "net.fabricmc.fabric-api"
2020-05-03 12:56:50 -04:00
sourceSets {
testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
}
task runTestmodClient(type: RunClientTask) {
classpath sourceSets.testmod.runtimeClasspath
}
task runTestmodServer(type: RunServerTask) {
classpath sourceSets.testmod.runtimeClasspath
}
dependencies {
minecraft "com.mojang:minecraft:$Globals.mcVersion"
mappings "net.fabricmc:yarn:${Globals.mcVersion}${Globals.yarnVersion}:v2"
modCompile "net.fabricmc:fabric-loader:${Globals.loaderVersion}"
// TODO remove when updating to loom 0.7
annotationProcessor "net.fabricmc:fabric-mixin-compile-extensions:0.4.3"
}
2018-12-09 11:47:35 -05:00
configurations {
dev
}
loom {
shareCaches = true
}
repositories {
mavenLocal()
}
2019-07-24 17:07:45 -04:00
jar {
classifier = "dev"
}
afterEvaluate {
2019-07-24 17:07:45 -04:00
remapJar {
input = file("${project.buildDir}/libs/$archivesBaseName-${version}-dev.jar")
archiveName = "${archivesBaseName}-${version}.jar"
}
artifacts {
dev file: file("${project.buildDir}/libs/$archivesBaseName-${version}-dev.jar"), type: "jar", builtBy: jar
}
processResources {
inputs.property "version", project.version
from(sourceSets.main.resources.srcDirs) {
include "fabric.mod.json"
expand "version": project.version
}
from(sourceSets.main.resources.srcDirs) {
exclude "fabric.mod.json"
}
}
license {
header rootProject.file("HEADER")
include "**/*.java"
}
}
task sourcesJar(type: Jar, dependsOn: classes) {
archiveClassifier = "sources"
from sourceSets.main.allSource
}
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "8.31"
}
}
// Apply auxiliary buildscripts to submodules
// This must be done after all plugins are applied to subprojects
apply from: "gradle/module-validation.gradle"
javadoc {
options {
source = "8"
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
// Runs a dedicated headless server with all test mods that closes once complete.
task runAutoTestServer(type: RunServerTask) {
project.subprojects {
classpath it.sourceSets.testmod.runtimeClasspath
}
jvmArgs "-Dfabric.autoTest"
args "--nogui"
}
subprojects {
2020-05-03 12:56:50 -04:00
dependencies {
testmodCompile sourceSets.main.output
}
task remapMavenJar(type: Copy, dependsOn: remapJar) {
afterEvaluate {
from("${project.buildDir}/libs/$archivesBaseName-${version}.jar")
into("${project.buildDir}/libs/")
rename { String fn -> "$archivesBaseName-${version}-maven.jar" }
}
}
2019-04-23 19:14:43 -04:00
publishing {
publications {
mavenJava(MavenPublication) {
2020-04-05 10:51:59 -04:00
afterEvaluate {
artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}-maven.jar")) {
builtBy remapMavenJar
}
2020-04-05 10:51:59 -04:00
artifact(sourcesJar) {
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
setupRepositories(repositories)
2019-04-23 19:14:43 -04:00
}
javadoc.enabled = false
}
task remapMavenJar(type: net.fabricmc.loom.task.RemapJarTask, dependsOn: jar) {
afterEvaluate {
input = file("${project.buildDir}/libs/${archivesBaseName}-${version}-dev.jar")
2019-07-24 17:07:45 -04:00
archiveName = "${archivesBaseName}-${version}-maven.jar"
addNestedDependencies = false
}
}
publishing {
publications {
mavenJava(MavenPublication) {
2019-04-23 19:14:43 -04:00
artifact(file("${project.buildDir}/libs/$archivesBaseName-${version}-maven.jar")) {
builtBy remapMavenJar
}
2019-04-23 19:14:43 -04:00
artifact(sourcesJar) {
builtBy remapSourcesJar
}
artifact javadocJar
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
subprojects.each {
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")
}
}
}
}
2019-04-23 19:14:43 -04:00
setupRepositories(repositories)
}
void setupRepositories(RepositoryHandler repositories) {
//repositories.mavenLocal() // uncomment for testing
def ENV = System.getenv()
if (ENV.MAVEN_URL) {
repositories.maven {
url ENV.MAVEN_URL
credentials {
username ENV.MAVEN_USERNAME
password ENV.MAVEN_PASSWORD
2019-04-23 19:14:43 -04:00
}
}
}
}
task licenseFormatAll
subprojects { p -> licenseFormatAll.dependsOn("${p.path}:licenseFormat") }
subprojects.each { remapJar.dependsOn("${it.path}:remapJar") }
2020-05-03 12:56:50 -04:00
sourceSets {
testmod
}
dependencies {
afterEvaluate {
subprojects.each {
compile project(path: ":${it.name}", configuration: "dev")
include project("${it.name}:")
2020-05-03 12:56:50 -04:00
testmodCompile project("${it.name}:").sourceSets.testmod.output
}
}
}
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"
changelog = "A changelog can be found at https://github.com/FabricMC/fabric/commits"
releaseType = Globals.preRelease ? "beta" : "release"
2020-11-25 14:34:48 -05:00
addGameVersion "1.17"
addGameVersion "Fabric"
2019-05-11 18:00:57 -04:00
mainArtifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) {
2020-11-05 13:42:17 -05:00
displayName = "[$Globals.mcVersion] Fabric API $Globals.baseVersion"
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
2020-07-01 13:58:47 -04:00
import org.kohsuke.github.GHReleaseBuilder
import org.kohsuke.github.GitHub
task github(dependsOn: remapMavenJar) {
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)
2020-11-05 13:53:10 -05:00
releaseBuilder.name("[$Globals.mcVersion] Fabric API $Globals.baseVersion")
releaseBuilder.body("A changelog can be found at https://github.com/FabricMC/fabric/commits")
2020-07-01 13:58:47 -04:00
releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(Globals.preRelease)
2020-07-01 13:58:47 -04:00
def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
}
}
task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload, dependsOn: remapMavenJar) {
onlyIf {
ENV.MODRINTH_TOKEN
}
token = ENV.MODRINTH_TOKEN
projectId = "P7dR8mSH"
versionNumber = version
versionName = "[$Globals.mcVersion] Fabric API $Globals.baseVersion"
releaseType = Globals.preRelease ? "beta" : "release"
uploadFile = file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")
addGameVersion(Globals.mcVersion)
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