0 Star 0 Fork 0

FabricMC / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
build.gradle 20.37 KB
一键复制 编辑 原始数据 按行查看 历史
modmuss 提交于 2024-02-10 21:24 . Fix coverage task (#3583)
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
plugins {
id "java-library"
id "eclipse"
id "idea"
id "maven-publish"
id 'jacoco'
id "fabric-loom" version "1.5.4" apply false
id "com.diffplug.spotless" version "6.20.0"
id "org.ajoberstar.grgit" version "3.1.0"
id "me.modmuss50.remotesign" version "0.4.0" apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
}
def ENV = System.getenv()
version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch()
logger.lifecycle("Building Fabric: " + version)
def metaProjects = [
'deprecated',
'fabric-api-bom',
'fabric-api-catalog'
]
import net.fabricmc.loom.util.gradle.SourceSetHelper
import groovy.json.JsonSlurper
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"
}
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
return branch.substring(branch.lastIndexOf("/") + 1)
}
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') }
def clientOutputs = depNames.iterator().collect { findProject(":$it").sourceSets.client.output }
project.dependencies {
deps.each {
api it
}
clientOutputs.each {
clientImplementation 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")
}
}
}
}
}
}
def testDependencies(project, List<String> depNames) {
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') }
def clientOutputs = depNames.iterator().collect { findProject(":$it").sourceSets.client.output }
project.dependencies {
deps.each {
testmodImplementation it
}
clientOutputs.each {
testmodClientImplementation it
}
}
}
allprojects {
group = "net.fabricmc.fabric-api"
apply plugin: "maven-publish"
apply plugin: "me.modmuss50.remotesign"
tasks.withType(GenerateModuleMetadata) {
enabled = false
}
remoteSign {
requestUrl = ENV.SIGNING_SERVER
pgpAuthKey = ENV.SIGNING_PGP_KEY
jarAuthKey = ENV.SIGNING_JAR_KEY
useDummyForTesting = ENV.SIGNING_SERVER == null
afterEvaluate {
// PGP sign all maven publications.
sign publishing.publications.mavenJava
}
}
publishing {
setupRepositories(repositories)
}
if (metaProjects.contains(it.name)) {
return
}
apply plugin: "java-library"
apply plugin: "checkstyle"
apply plugin: "fabric-loom"
apply plugin: "com.diffplug.spotless"
tasks.withType(JavaCompile).configureEach {
it.options.release = 17
}
java {
// Must be added before the split source sets are setup.
withSourcesJar()
}
loom {
splitEnvironmentSourceSets()
mixin {
useLegacyMixinAp = true
}
}
sourceSets {
testmod {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
}
testmodClient {
compileClasspath += main.compileClasspath
runtimeClasspath += main.runtimeClasspath
compileClasspath += client.compileClasspath
runtimeClasspath += client.runtimeClasspath
compileClasspath += testmod.compileClasspath
runtimeClasspath += testmod.runtimeClasspath
}
test {
compileClasspath += testmodClient.compileClasspath
runtimeClasspath += testmodClient.runtimeClasspath
}
}
loom {
runtimeOnlyLog4j = true
runs {
testmodClient {
client()
ideConfigGenerated project.rootProject == project
name = "Testmod Client"
source sourceSets.testmodClient
}
testmodServer {
server()
ideConfigGenerated project.rootProject == project
name = "Testmod Server"
source sourceSets.testmod
}
}
}
loom.runs.configureEach {
vmArg("-enableassertions")
}
allprojects.each { p ->
if (metaProjects.contains(project.name)) {
return
}
loom.mods.register(p.name) {
sourceSet p.sourceSets.main
sourceSet p.sourceSets.client
}
loom.mods.register(p.name + "-testmod") {
sourceSet p.sourceSets.testmod
sourceSet p.sourceSets.testmodClient
}
}
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}"
testmodImplementation sourceSets.main.output
testmodClientImplementation sourceSets.main.output
testmodClientImplementation sourceSets.client.output
testmodClientImplementation sourceSets.testmod.output
testImplementation "net.fabricmc:fabric-loader-junit:${project.loader_version}"
testImplementation sourceSets.testmodClient.output
testImplementation 'org.mockito:mockito-core:5.4.0'
}
test {
useJUnitPlatform()
afterEvaluate {
// See: https://github.com/FabricMC/fabric-loader/pull/585
def classPathGroups = loom.mods.stream()
.map { modSettings ->
SourceSetHelper.getClasspath(modSettings, getProject()).stream()
.map(File.&getAbsolutePath)
.collect(Collectors.joining(File.pathSeparator))
}
.collect(Collectors.joining(File.pathSeparator+File.pathSeparator))
systemProperty("fabric.classPathGroups", classPathGroups)
}
}
tasks.withType(ProcessResources).configureEach {
inputs.property "version", project.version
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}
spotless {
java {
licenseHeaderFile(rootProject.file("HEADER"))
removeUnusedImports()
importOrder('java', 'javax', '', 'net.minecraft', 'net.fabricmc')
indentWithTabs()
trimTrailingWhitespace()
}
}
checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "10.12.1"
}
tasks.withType(AbstractArchiveTask).configureEach {
preserveFileTimestamps = false
reproducibleFileOrder = true
}
remoteSign {
sign remapJar
}
// Run this task after updating minecraft to regenerate any required resources
tasks.register('generateResources') {
group = "fabric"
}
tasks.register('testmodJar', Jar) {
from sourceSets.testmod.output
from sourceSets.testmodClient.output
destinationDirectory = new File(project.buildDir, "devlibs")
archiveClassifier = "testmod"
}
[jar, sourcesJar].each {
it.from(rootProject.file("LICENSE")) {
rename { "${it}-${project.base.archivesName.get()}"}
}
}
if (file("src/client").exists() && !file("src/main").exists()) {
remapJar {
additionalClientOnlyEntries.add("LICENSE-${project.base.archivesName.get()}")
}
remapSourcesJar {
additionalClientOnlyEntries.add("LICENSE-${project.base.archivesName.get()}")
}
}
tasks.register('remapTestmodJar', net.fabricmc.loom.task.RemapJarTask) {
dependsOn testmodJar
input = testmodJar.archiveFile
archiveClassifier = "testmod"
addNestedDependencies = false
includesClientOnlyClasses = true
clientOnlySourceSetName = sourceSets.testmodClient.name
}
build.dependsOn remapTestmodJar
tasks.register('validateMixinNames', net.fabricmc.loom.task.ValidateMixinNameTask) {
source(sourceSets.main.output)
source(sourceSets.client.output)
source(sourceSets.testmod.output)
}
// Apply to each valid subproject.
apply from: rootProject.file('gradle/package-info.gradle')
apply from: rootProject.file('gradle/validate-annotations.gradle')
}
remapTestmodJar {
def testModJarTasks = []
subprojects {
if (metaProjects.contains(it.name) || !(it.file("src/testmod").exists() || it.file("src/testmodClient").exists())) {
return
}
testModJarTasks += it.tasks.remapTestmodJar
}
nestedJars.setFrom(testModJarTasks)
addNestedDependencies = true
clientOnlySourceSetName = sourceSets.testmodClient.name
}
// 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"
loom {
// Required as the item-group API uses access widened classes in its API, without this the javadoc generation fails.
accessWidenerPath = file("fabric-item-group-api-v1/src/main/resources/fabric-item-group-api-v1.accesswidener")
}
javadoc {
options {
source = "17"
encoding = "UTF-8"
charSet = "UTF-8"
memberLevel = JavadocMemberLevel.PACKAGE
links(
"https://maven.fabricmc.net/docs/yarn-${rootProject.minecraft_version}${project.yarn_version}/"
)
// Disable the crazy super-strict doclint tool in Java 8
addStringOption("Xdoclint:none", "-quiet")
tags(
'apiNote:a:API Note:',
'implSpec:a:Implementation Requirements:',
'implNote:a:Implementation Note:'
)
}
allprojects.each {
if (metaProjects.contains(it.name)) {
return
}
source(it.sourceSets.main.allJava)
source(it.sourceSets.client.allJava)
}
classpath = files(sourceSets.main.compileClasspath, sourceSets.client.compileClasspath)
include("**/api/**")
failOnError true
}
tasks.register('javadocJar', 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
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"
}
autoTestServer {
inherit testmodServer
name "Auto Test Server"
vmArg "-Dfabric.autoTest"
}
autoTestClient {
inherit testmodClient
name "Auto Test Client"
vmArg "-Dfabric.autoTest"
}
// Create duplicate tasks for this, as jacoco slows things down a bit
gametestCoverage {
inherit gametest
name "Game Test Coverage"
ideConfigGenerated = false
}
autoTestClientCoverage {
inherit autoTestClient
name "Auto Test Client Coverage"
ideConfigGenerated = false
}
}
}
test.dependsOn runGametest
def coverageTasks = [
runGametestCoverage,
runAutoTestClientCoverage
]
jacoco {
coverageTasks.forEach {
applyTo it
}
}
tasks.register('coverage', JacocoReport) {
dependsOn coverageTasks
coverageTasks.forEach {
executionData it
}
// Add all source as input
allprojects { p ->
if (p.path.startsWith(":deprecated") || metaProjects.contains(p.name)) {
return
}
sourceSets p.sourceSets.main, p.sourceSets.client, p.sourceSets.testmod, p.sourceSets.testmodClient
}
// Exclude mixins
classDirectories.setFrom(files(classDirectories.files.collect {
fileTree(dir: it, exclude: '**/mixin/**')
}))
}
configurations {
productionRuntime {
extendsFrom configurations.minecraftLibraries
extendsFrom configurations.loaderLibraries
extendsFrom configurations.minecraftRuntimeLibraries
}
productionRuntimeServer
}
dependencies {
productionRuntime "net.fabricmc:fabric-loader:${project.loader_version}"
productionRuntime "net.fabricmc:intermediary:${project.minecraft_version}"
productionRuntimeServer "net.fabricmc:fabric-installer:${project.installer_version}:server"
}
import net.fabricmc.loom.util.Platform
// This is very far beyond loom's API if you copy this, you're on your own.
tasks.register('runProductionAutoTestClient', JavaExec) {
dependsOn remapJar, remapTestmodJar, downloadAssets
classpath.from configurations.productionRuntime
mainClass = "net.fabricmc.loader.impl.launch.knot.KnotClient"
workingDir = file("run")
doFirst {
classpath.from loom.minecraftProvider.minecraftClientJar
workingDir.mkdirs()
args(
"--assetIndex", loom.minecraftProvider.versionInfo.assetIndex().fabricId(loom.minecraftProvider.minecraftVersion()),
"--assetsDir", new File(loom.files.userCache, "assets").absolutePath,
"--gameDir", workingDir.absolutePath
)
if (Platform.CURRENT.operatingSystem.isMacOS()) {
jvmArgs(
"-XstartOnFirstThread"
)
}
jvmArgs(
"-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}",
"-Dfabric.autoTest",
"-enableassertions"
)
}
}
tasks.register('serverPropertiesJar', Jar) {
def propsFile = file("build/tmp/install.properties")
doFirst {
propsFile.text = """\
fabric-loader-version=${project.loader_version}
game-version=${project.minecraft_version}
""".stripMargin().stripIndent()
}
archiveFileName = "test-server-properties.jar"
destinationDirectory = file("build/tmp")
from(propsFile)
}
tasks.register('runProductionAutoTestServer', JavaExec) {
dependsOn remapJar, remapTestmodJar, serverPropertiesJar
classpath.from configurations.productionRuntimeServer, serverPropertiesJar
mainClass = "net.fabricmc.installer.ServerLauncher"
workingDir = file("run")
doFirst {
workingDir.mkdirs()
jvmArgs(
"-Dfabric.addMods=${remapJar.archiveFile.get().asFile.absolutePath}${File.pathSeparator}${remapTestmodJar.archiveFile.get().asFile.absolutePath}",
"-Dfabric.autoTest",
"-enableassertions"
)
args("nogui")
}
}
// Format all the gradle files
spotless {
groovyGradle {
target 'src/**/*.gradle', '*.gradle', 'gradle/*.gradle'
greclipse()
}
}
def addPomMetadataInformation(Project project, MavenPom pom) {
def modJsonFile = project.file("src/main/resources/fabric.mod.json")
if (!modJsonFile.exists()) {
modJsonFile = project.file("src/client/resources/fabric.mod.json")
}
def modJson = new JsonSlurper().parse(modJsonFile)
pom.name = modJson.name
pom.url = "https://github.com/FabricMC/fabric/tree/HEAD/${project.rootDir.relativePath(project.projectDir)}"
pom.description = modJson.description
pom.licenses {
license {
name = "Apache-2.0"
url = "https://github.com/FabricMC/fabric/blob/HEAD/LICENSE"
}
}
pom.developers {
developer {
name = "FabricMC"
url = "https://fabricmc.net/"
}
}
pom.scm {
connection = "scm:git:https://github.com/FabricMC/fabric.git"
url = "https://github.com/FabricMC/fabric"
developerConnection = "scm:git:git@github.com:FabricMC/fabric.git"
}
pom.issueManagement {
system = "GitHub"
url = "https://github.com/FabricMC/fabric/issues"
}
}
subprojects {
if (metaProjects.contains(it.name)) {
return
}
base {
archivesName = project.name
}
dependencies {
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')
testmodClientImplementation project(":fabric-gametest-api-v1").sourceSets.client.output
testmodImplementation project(path: ':fabric-resource-loader-v0', configuration: 'namedElements')
testmodClientImplementation project(":fabric-resource-loader-v0").sourceSets.client.output
}
// 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')
testmodClientImplementation project(":fabric-registry-sync-v0").sourceSets.client.output
}
}
publishing {
publications {
mavenJava(MavenPublication) {
pom {
addPomMetadataInformation(project, pom)
}
artifact(signRemapJar.output) {
builtBy(signRemapJar)
}
artifact(remapSourcesJar) {
builtBy remapSourcesJar
}
}
}
}
// We manually handle the pom generation
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)
javadoc.enabled = false
}
publishing {
publications {
mavenJava(MavenPublication) {
artifact(signRemapJar.output) {
builtBy(signRemapJar)
}
artifact(sourcesJar) {
builtBy remapSourcesJar
}
artifact javadocJar
artifact remapTestmodJar
pom {
addPomMetadataInformation(rootProject, pom)
}
pom.withXml {
def depsNode = asNode().appendNode("dependencies")
subprojects.each {
// The maven BOM containing all of the deprecated modules is added manually below.
if (it.path.startsWith(":deprecated") || metaProjects.contains(it.name)) {
return
}
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", it.group)
depNode.appendNode("artifactId", it.name)
depNode.appendNode("version", it.version)
depNode.appendNode("scope", "compile")
}
// Depend on the deprecated BOM to allow opting out of deprecated modules.
def depNode = depsNode.appendNode("dependency")
depNode.appendNode("groupId", group)
depNode.appendNode("artifactId", "fabric-api-deprecated")
depNode.appendNode("version", 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.
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
}
}
}
}
}
subprojects.each {
if (metaProjects.contains(it.name)) {
return
}
remapJar.dependsOn("${it.path}:remapJar")
}
// These modules are not included in the fat jar, maven will resolve them via the pom.
def devOnlyModules = ["fabric-gametest-api-v1",]
dependencies {
afterEvaluate {
subprojects.each {
if (metaProjects.contains(it.name)) {
return
}
api project(path: "${it.path}", configuration: "namedElements")
clientImplementation project("${it.path}:").sourceSets.client.output
testmodImplementation project("${it.path}:").sourceSets.testmod.output
testmodClientImplementation project("${it.path}:").sourceSets.testmodClient.output
}
}
}
remapJar {
afterEvaluate {
subprojects.each {
if (it.name in devOnlyModules || metaProjects.contains(it.name)) {
return
}
// Include the signed or none signed jar from the sub project.
nestedJars.from project("${it.path}").tasks.getByName("signRemapJar")
}
}
}
publishMods {
file = signRemapJar.output
changelog = providers.environmentVariable("CHANGELOG").getOrElse("No changelog provided")
type = project.prerelease == "true" ? BETA : STABLE
displayName = "[${project.minecraft_version}] Fabric API $project.version"
modLoaders.add("fabric")
dryRun = providers.environmentVariable("CURSEFORGE_API_KEY").getOrNull() == null
curseforge {
accessToken = providers.environmentVariable("CURSEFORGE_API_KEY")
projectId = "306612"
minecraftVersions.add(project.curseforge_minecraft_version)
}
modrinth {
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
projectId = "P7dR8mSH"
minecraftVersions.add(project.minecraft_version)
}
github {
accessToken = providers.environmentVariable("GITHUB_TOKEN")
repository = providers.environmentVariable("GITHUB_REPOSITORY").getOrElse("FabricMC/dryrun")
commitish = providers.environmentVariable("GITHUB_REF_NAME").getOrElse("dryrun")
}
}
assemble.dependsOn signRemapJar
import java.util.stream.Collectors
// A task to ensure that the version being released has not already been released.
tasks.register('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!")
}
}
}
tasks.publishMods.dependsOn checkVersion
publish.mustRunAfter checkVersion
1
https://gitee.com/fabric-mc/fabric.git
git@gitee.com:fabric-mc/fabric.git
fabric-mc
fabric
fabric
1.20.4

搜索帮助