mirror of
https://github.com/GeyserMC/Geyser.git
synced 2025-12-19 14:59:27 +00:00
Update to Gradle 9 (#5976)
* Update gradle to 9.2.0 * Eclipse doesn't like defining a generic in an instanceof check... Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Fix launching on standalone due to Gradle 9 changes Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Update indra to v4; fix as many gradle deprecation warnings as possible Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Do task order suggestion; remove properties comment line Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Fix fabric runServer rask Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Fix :neoforge:runServer gradle task Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> * Fix libs.versions.toml * Fix dupe runtask def * Update architectury-loom and resolve properties issues --------- Signed-off-by: Joshua Castle <26531652+Kas-tle@users.noreply.github.com> Co-authored-by: onebeastchris <github@onechris.mozmail.com>
This commit is contained in:
@@ -1,9 +1,18 @@
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.revwalk.RevWalk
|
||||
import net.kyori.indra.git.RepositoryValueSource
|
||||
|
||||
import java.util.Properties
|
||||
|
||||
plugins {
|
||||
// Allow blossom to mark sources root of templates
|
||||
idea
|
||||
eclipse
|
||||
alias(libs.plugins.blossom)
|
||||
id("geyser.publish-conventions")
|
||||
id("io.freefair.lombok")
|
||||
// Allows fabric/neoforge runServer gradle tasks to work correctly
|
||||
id("dev.architectury.loom-companion")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
@@ -69,9 +78,11 @@ dependencies {
|
||||
}
|
||||
|
||||
// Test
|
||||
testImplementation(platform("org.junit:junit-bom:6.0.0"))
|
||||
testImplementation(libs.junit)
|
||||
testImplementation(libs.gson.runtime) // Record support
|
||||
testImplementation(libs.mockito)
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
|
||||
// Annotation Processors
|
||||
compileOnly(projects.ap)
|
||||
@@ -83,35 +94,114 @@ dependencies {
|
||||
api(libs.bstats)
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
// This is solely for backwards compatibility for other programs that used this file before the switch to gradle.
|
||||
// It used to be generated by the maven Git-Commit-Id-Plugin
|
||||
filesMatching("git.properties") {
|
||||
val info = GitInfo()
|
||||
expand(
|
||||
"branch" to info.branch,
|
||||
"buildNumber" to info.buildNumber,
|
||||
"projectVersion" to info.version,
|
||||
"commit" to info.commit,
|
||||
"commitAbbrev" to info.commitAbbrev,
|
||||
"commitMessage" to info.commitMessage,
|
||||
"repository" to info.repository
|
||||
)
|
||||
abstract class CommitMessageValueSource : RepositoryValueSource.Parameterless<String>() {
|
||||
override fun obtain(repository: Git): String? {
|
||||
val headCommitId = repository.repository.resolve("HEAD")
|
||||
|
||||
if (headCommitId == null) {
|
||||
return ""
|
||||
}
|
||||
|
||||
RevWalk(repository.repository).use { walk ->
|
||||
val commit = walk.parseCommit(headCommitId)
|
||||
return commit.fullMessage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
abstract class RepositoryUrlValueSource : RepositoryValueSource.Parameterless<String>() {
|
||||
override fun obtain(repository: Git): String? {
|
||||
return repository.repository.config.getString("remote", "origin", "url")
|
||||
}
|
||||
}
|
||||
|
||||
val gitBranch = indraGit.branchName().orElse("DEV")
|
||||
val gitCommit = indraGit.commit()
|
||||
|
||||
val gitCommitName = gitCommit.map { it?.name ?: "0".repeat(40) }
|
||||
val gitCommitAbbrev = gitCommit.map { it?.name?.substring(0, 7) ?: "0".repeat(7) }
|
||||
|
||||
val gitCommitMessage = indraGit.repositoryValue(CommitMessageValueSource::class.java).orElse("")
|
||||
val gitRepositoryUrl = indraGit.repositoryValue(RepositoryUrlValueSource::class.java).orElse("").map {
|
||||
it.replace("git@github.com:", "https://github.com/")
|
||||
}
|
||||
|
||||
val gitRepositoryIsDev = gitBranch.zip(gitRepositoryUrl) { branch, repo ->
|
||||
isDevBuild(branch, repo)
|
||||
}
|
||||
|
||||
val gitVersion = gitBranch.zip(gitCommitAbbrev) { branch, commit ->
|
||||
"git-${branch}-${commit}"
|
||||
}
|
||||
|
||||
val projectVersionProvider = gitRepositoryIsDev.map { isDev ->
|
||||
if (isDev) project.version.toString() else projectVersion(project).toString()
|
||||
}
|
||||
|
||||
val finalVersion = projectVersionProvider.zip(gitVersion) { projVer, gitVer ->
|
||||
"$projVer ($gitVer)"
|
||||
}
|
||||
|
||||
val buildNumber = provider { buildNumber().toString() }
|
||||
|
||||
val gitPropertiesMap = mapOf(
|
||||
"git.branch" to gitBranch,
|
||||
"git.build.number" to buildNumber,
|
||||
"git.build.version" to finalVersion,
|
||||
"git.commit.id" to gitCommitName,
|
||||
"git.commit.id.abbrev" to gitCommitAbbrev,
|
||||
"git.commit.message.full" to gitCommitMessage,
|
||||
"git.remote.origin.url" to gitRepositoryUrl
|
||||
)
|
||||
|
||||
val generateGitProperties = tasks.register("generateGitProperties") {
|
||||
description = "Generates git.properties from Git information."
|
||||
group = "build"
|
||||
|
||||
inputs.properties(gitPropertiesMap)
|
||||
|
||||
val generatedPropsFile = layout.buildDirectory.file("generated/git/git.properties")
|
||||
outputs.file(generatedPropsFile)
|
||||
|
||||
doLast {
|
||||
val props = Properties()
|
||||
gitPropertiesMap.forEach { (key, provider) ->
|
||||
props[key] = provider.get()
|
||||
}
|
||||
|
||||
generatedPropsFile.get().asFile.apply {
|
||||
parentFile.mkdirs()
|
||||
writer().use { props.store(it, null) }
|
||||
// remove comment line
|
||||
val lines = readLines()
|
||||
if (lines.isNotEmpty()) {
|
||||
writeText(lines.drop(1).joinToString("\n", postfix = "\n"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tasks.processResources {
|
||||
from(generateGitProperties) {
|
||||
into(".")
|
||||
}
|
||||
}
|
||||
|
||||
tasks.named("sourcesJar") {
|
||||
dependsOn(tasks.named("processResources"))
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
blossom {
|
||||
val info = GitInfo()
|
||||
javaSources {
|
||||
property("version", info.version)
|
||||
property("gitVersion", info.gitVersion)
|
||||
property("buildNumber", info.buildNumber.toString())
|
||||
property("branch", info.branch)
|
||||
property("commit", info.commit)
|
||||
property("repository", info.repository)
|
||||
property("devVersion", info.isDev.toString())
|
||||
property("version", finalVersion)
|
||||
property("gitVersion", gitVersion)
|
||||
property("buildNumber", buildNumber)
|
||||
property("branch", gitBranch)
|
||||
property("commit", gitCommitName)
|
||||
property("repository", gitRepositoryUrl)
|
||||
property("devVersion", gitRepositoryIsDev.map { it.toString() })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,40 +211,6 @@ fun isDevBuild(branch: String, repository: String): Boolean {
|
||||
return branch != "master" || repository.equals("https://github.com/GeyserMC/Geyser", ignoreCase = true).not()
|
||||
}
|
||||
|
||||
inner class GitInfo {
|
||||
val branch: String
|
||||
val commit: String
|
||||
val commitAbbrev: String
|
||||
|
||||
val gitVersion: String
|
||||
val version: String
|
||||
val buildNumber: Int
|
||||
|
||||
val commitMessage: String
|
||||
val repository: String
|
||||
|
||||
val isDev: Boolean
|
||||
|
||||
init {
|
||||
branch = indraGit.branchName() ?: "DEV"
|
||||
|
||||
val commit = indraGit.commit()
|
||||
this.commit = commit?.name ?: "0".repeat(40)
|
||||
commitAbbrev = commit?.name?.substring(0, 7) ?: "0".repeat(7)
|
||||
|
||||
gitVersion = "git-${branch}-${commitAbbrev}"
|
||||
|
||||
val git = indraGit.git()
|
||||
commitMessage = git?.commit()?.message ?: ""
|
||||
repository = git?.repository?.config?.getString("remote", "origin", "url") ?: ""
|
||||
|
||||
buildNumber = buildNumber()
|
||||
isDev = isDevBuild(branch, repository)
|
||||
val projectVersion = if (isDev) project.version else projectVersion(project)
|
||||
version = "$projectVersion ($gitVersion)"
|
||||
}
|
||||
}
|
||||
|
||||
// Manual task to download the bedrock data files from the CloudburstMC/Data repository
|
||||
// Invoke with ./gradlew :core:downloadBedrockData --suffix=1_20_70
|
||||
// Set suffix to the current Bedrock version
|
||||
|
||||
@@ -797,9 +797,10 @@ public class Entity implements GeyserEntity {
|
||||
@Override
|
||||
public <T> void update(@NonNull GeyserEntityProperty<T> property, @Nullable T value) {
|
||||
Objects.requireNonNull(property, "property must not be null!");
|
||||
if (!(property instanceof PropertyType<T, ? extends EntityProperty> propertyType)) {
|
||||
if (!(property instanceof PropertyType)) {
|
||||
throw new IllegalArgumentException("Invalid property implementation! Got: " + property.getClass().getSimpleName());
|
||||
}
|
||||
PropertyType<T, ? extends EntityProperty> propertyType = (PropertyType<T, ?>) property;
|
||||
int index = propertyDefinitions.getPropertyIndex(property.identifier().toString());
|
||||
if (index < 0) {
|
||||
throw new IllegalArgumentException("No property with the name " + property.identifier() + " has been registered.");
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
git.branch=${branch}
|
||||
git.build.number=${buildNumber}
|
||||
git.build.version=${projectVersion}
|
||||
git.commit.id=${commit}
|
||||
git.commit.id.abbrev=${commitAbbrev}
|
||||
git.commit.message.full=${commitMessage}
|
||||
git.remote.origin.url=${repository}
|
||||
Reference in New Issue
Block a user