Skip to content

Commit

Permalink
Update Loom and Loader. Cleanup/improve buildscript.
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Nov 12, 2021
1 parent 2e160e0 commit b4f4f6c
Show file tree
Hide file tree
Showing 57 changed files with 519 additions and 289 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ indent_style = tab

[*.java]
indent_style = tab
ij_continuation_indent_size = 8
ij_java_imports_layout = $*,|,java.**,|,javax.**,|,*,|,net.minectaft.**,|,net.fabricmc.**
ij_java_class_count_to_use_import_on_demand = 999

[*.json]
indent_style = space
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ jobs:
build:
strategy:
matrix:
java: [16-jdk]
java: [16-jdk, 17-jdk]
runs-on: ubuntu-20.04
container:
image: openjdk:${{ matrix.java }}
image: eclipse-temurin:${{ matrix.java }}
options: --user root
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: gradle/wrapper-validation-action@v1
- run: ./gradlew check build publishToMavenLocal --stacktrace --parallel --warning-mode=fail
- run: mkdir run && echo "eula=true" >> run/eula.txt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ jobs:
build:
runs-on: ubuntu-20.04
container:
image: adoptopenjdk:16-jdk
image: eclipse-temurin:17-jdk
options: --user root
steps:
- run: apt update && apt install git -y && git --version
Expand Down
146 changes: 61 additions & 85 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
dependencies {
classpath 'org.kohsuke:github-api:1.114'
classpath 'org.kohsuke:github-api:1.135'
}
}

Expand All @@ -9,7 +9,7 @@ plugins {
id "eclipse"
id "idea"
id "maven-publish"
id "fabric-loom" version "0.10.54" apply false
id "fabric-loom" version "0.10.55" apply false
id "org.cadixdev.licenser" version "0.6.1"
id "org.ajoberstar.grgit" version "3.1.0"
id "com.matthewprenger.cursegradle" version "1.4.0"
Expand All @@ -18,20 +18,19 @@ plugins {

def ENV = System.getenv()

class Globals {
static def baseVersion = "0.42.2"
static def mcVersion = "1.18-pre1"
static def yarnVersion = "+build.2"
static def loaderVersion = "0.11.7"
static def preRelease = true
}

version = Globals.baseVersion + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch()
version = project.version + "+" + (ENV.GITHUB_RUN_NUMBER ? "" : "local-") + getBranch()
logger.lifecycle("Building Fabric: " + version)

import org.apache.commons.codec.digest.DigestUtils

def getSubprojectVersion(project, version) {
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"
}
Expand All @@ -42,7 +41,7 @@ def getSubprojectVersion(project, version) {
return version + "+uncommited"
}

return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(Globals.mcVersion).substring(0, 2)
return version + "+" + latestCommits.get(0).id.substring(0, 8) + DigestUtils.sha256Hex(project.rootProject.minecraft_version).substring(0, 2)
}

def getBranch() {
Expand All @@ -61,28 +60,12 @@ def getBranch() {
}

def moduleDependencies(project, List<String> depNames) {
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'dev') }
def deps = depNames.iterator().collect { project.dependencies.project(path: ":$it", configuration: 'namedElements') }
project.dependencies {
deps.each {
api 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 {
Expand Down Expand Up @@ -123,13 +106,9 @@ allprojects {
}

dependencies {
minecraft "com.mojang:minecraft:$Globals.mcVersion"
mappings "net.fabricmc:yarn:${Globals.mcVersion}${Globals.yarnVersion}:v2"
modApi "net.fabricmc:fabric-loader:${Globals.loaderVersion}"
}

configurations {
dev
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 {
Expand All @@ -140,32 +119,17 @@ allprojects {
mavenLocal()
}

jar {
archiveClassifier = "dev"
}

afterEvaluate {
remapJar {
input = file("${project.buildDir}/libs/$archivesBaseName-${project.version}-dev.jar")
archiveFileName = "${archivesBaseName}-${project.version}.jar"
}

artifacts {
dev file: file("${project.buildDir}/libs/$archivesBaseName-${project.version}-dev.jar"), type: "jar", builtBy: jar
}

processResources {
inputs.property "version", project.version
processResources {
inputs.property "version", project.version

filesMatching("fabric.mod.json") {
expand "version": project.version
}
filesMatching("fabric.mod.json") {
expand "version": project.version
}
}

license {
header rootProject.file("HEADER")
include "**/*.java"
}
license {
header rootProject.file("HEADER")
include "**/*.java"
}

task sourcesJar(type: Jar, dependsOn: classes) {
Expand All @@ -175,18 +139,23 @@ allprojects {

checkstyle {
configFile = rootProject.file("checkstyle.xml")
toolVersion = "8.43"
toolVersion = "9.1"
}

tasks.withType(AbstractArchiveTask) {
preserveFileTimestamps = false
reproducibleFileOrder = true
}

tasks.withType(GenerateModuleMetadata) {
enabled = false
}
}

// 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 {
Expand Down Expand Up @@ -224,46 +193,52 @@ task javadocJar(type: Jar) {

build.dependsOn javadocJar

// Runs a dedicated headless server with all test mods that closes once complete.
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"
}
}
}
test.dependsOn runGametest

subprojects {
dependencies {
testmodImplementation sourceSets.main.output

// Make all modules depend on the gametest api to try and promote its usage.
if (project.name != "fabric-gametest-api-v1")
testmodImplementation project(path: ':fabric-gametest-api-v1', configuration: 'namedElements')
}

publishing {
publications {
mavenJava(MavenPublication) {
afterEvaluate {
artifact(remapJar) {
builtBy remapJar
}

artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
from components.java
}
}

setupRepositories(repositories)
}

// Required as moduleDependencies modifies the pom
loom.disableDeprecatedPomGeneration(publishing.publications.mavenJava)

javadoc.enabled = false

afterEvaluate {
// Disable the gen sources task on sub projects, saves you being here for a year.
// Disable the gen sources task on sub projects
genSourcesWithFernFlower.enabled = false
genSourcesWithCfr.enabled = false
unpickJar.enabled = false
Expand Down Expand Up @@ -306,6 +281,7 @@ publishing {
setupRepositories(repositories)
}

// 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) {
Expand Down Expand Up @@ -340,7 +316,7 @@ def devOnlyModules = [
dependencies {
afterEvaluate {
subprojects.each {
api project(path: ":${it.name}", configuration: "dev")
api project(path: ":${it.name}", configuration: "namedElements")

if (!(it.name in devOnlyModules)) {
include project("${it.name}:")
Expand All @@ -359,12 +335,12 @@ curseforge {
project {
id = "306612"
changelog = ENV.CHANGELOG ?: "No changelog provided"
releaseType = Globals.preRelease ? "beta" : "release"
releaseType = project.prerelease ? "beta" : "release"
addGameVersion "1.18-Snapshot"
addGameVersion "Fabric"

mainArtifact(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")) {
displayName = "[$Globals.mcVersion] Fabric API $Globals.baseVersion"
mainArtifact(remapJar) {
displayName = "[$project.minecraft_version] Fabric API $project.version"
}

afterEvaluate {
Expand All @@ -390,10 +366,10 @@ task github(dependsOn: remapMavenJar) {
def repository = github.getRepository(ENV.GITHUB_REPOSITORY)

def releaseBuilder = new GHReleaseBuilder(repository, version as String)
releaseBuilder.name("[$Globals.mcVersion] Fabric API $Globals.baseVersion")
releaseBuilder.name("[$project.minecraft_version] Fabric API $project.version")
releaseBuilder.body(ENV.CHANGELOG ?: "No changelog provided")
releaseBuilder.commitish(getBranch())
releaseBuilder.prerelease(Globals.preRelease)
releaseBuilder.prerelease(project.prerelease)

def ghRelease = releaseBuilder.create()
ghRelease.uploadAsset(file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"), "application/java-archive");
Expand All @@ -408,13 +384,13 @@ task modrinth(type: com.modrinth.minotaur.TaskModrinthUpload, dependsOn: remapMa
token = ENV.MODRINTH_TOKEN
projectId = "P7dR8mSH"
versionNumber = version
versionName = "[$Globals.mcVersion] Fabric API $Globals.baseVersion"
releaseType = Globals.preRelease ? "beta" : "release"
versionName = "[$project.minecraft_version] Fabric API $project.version"
releaseType = project.prerelease ? "beta" : "release"
changelog = ENV.CHANGELOG ?: "No changelog provided"

uploadFile = file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar")
uploadFile = remapJar

addGameVersion(Globals.mcVersion)
addGameVersion(project.minecraft_version)
addLoader('fabric')
}

Expand Down
6 changes: 3 additions & 3 deletions fabric-api-base/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
archivesBaseName = "fabric-api-base"
version = getSubprojectVersion(project, "0.4.0")
version = getSubprojectVersion(project)

dependencies {
testmodImplementation project(path: ':fabric-command-api-v1', configuration: 'dev')
testmodImplementation project(path: ':fabric-lifecycle-events-v1', configuration: 'dev')
testmodImplementation project(path: ':fabric-command-api-v1', configuration: 'namedElements')
testmodImplementation project(path: ':fabric-lifecycle-events-v1', configuration: 'namedElements')
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2016, 2017, 2018, 2019 FabricMC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package net.fabricmc.fabric.test.base;

import org.spongepowered.asm.mixin.MixinEnvironment;

import net.minecraft.test.GameTest;
import net.minecraft.test.TestContext;

import net.fabricmc.fabric.api.gametest.v1.FabricGameTest;

public class FabricApiBaseGameTest {
@GameTest(structureName = FabricGameTest.EMPTY_STRUCTURE)
public void auditMixins(TestContext context) {
MixinEnvironment.getCurrentEnvironment().audit();

context.complete();
}
}
3 changes: 3 additions & 0 deletions fabric-api-base/src/testmod/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
"entrypoints": {
"main": [
"net.fabricmc.fabric.test.base.FabricApiBaseTestInit"
],
"fabric-gametest" : [
"net.fabricmc.fabric.test.base.FabricApiBaseGameTest"
]
}
}
Loading

0 comments on commit b4f4f6c

Please sign in to comment.