Skip to content

Commit

Permalink
Include commit and build number in snapshot versions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim203 committed Feb 14, 2022
1 parent 51c828d commit 866a297
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 16 deletions.
7 changes: 6 additions & 1 deletion build-logic/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ repositories {
}

dependencies {
implementation("net.kyori", "indra-common", "2.0.6")
implementation("net.kyori", "indra-common", "2.1.1")
implementation("org.jfrog.buildinfo", "build-info-extractor-gradle", "4.26.1")
implementation("gradle.plugin.com.github.johnrengelman", "shadow", "7.1.1")
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
Expand Down
11 changes: 11 additions & 0 deletions build-logic/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ import org.gradle.api.artifacts.ProjectDependency
import org.gradle.kotlin.dsl.named
import org.gradle.kotlin.dsl.the

fun Project.fullVersion(): String {
var version = version.toString()
if (version.endsWith("-SNAPSHOT")) {
version += " (${lastCommitHash()}-b${buildNumberAsString()}"
}
return version
}

fun Project.lastCommitHash(): String? =
the<IndraGitExtension>().commit()?.name?.substring(0, 7)

Expand All @@ -40,6 +48,9 @@ fun Project.branchName(): String =
fun Project.buildNumber(): Int =
Integer.parseInt(System.getProperty("BUILD_NUMBER", "-1"))

fun Project.buildNumberAsString(): String =
buildNumber().takeIf { it != -1 }?.toString() ?: "unknown"

fun Project.relocate(pattern: String) {
tasks.named<ShadowJar>("shadowJar") {
relocate(pattern, "org.geysermc.floodgate.shaded.$pattern")
Expand Down
25 changes: 14 additions & 11 deletions build-logic/src/main/kotlin/floodgate.base-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,36 +1,39 @@
plugins {
`java-library`
`maven-publish`
id("net.kyori.indra")
id("net.kyori.indra.git")
// id("net.ltgt.errorprone")
}

dependencies {
compileOnly("org.checkerframework", "checker-qual", Versions.checkerQual)
}

indra {
mitLicense()

javaVersions {
target(8)
minimumToolchain(8)
}

github("GeyserMC", "Floodgate")
}

tasks {
processResources {
filesMatching(listOf("plugin.yml", "bungee.yml", "velocity-plugin.json")) {
expand(
"id" to "floodgate",
"name" to "floodgate",
"version" to project.version,
"version" to fullVersion(),
"description" to project.description,
"url" to "https://geysermc.org",
"author" to "GeyserMC"
)
}
}
compileJava {
options.encoding = Charsets.UTF_8.name()
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

withSourcesJar()
}

publishing {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ public static Object getValue(Object instance, String fieldName) {
}

/**
* Get the value of a field and cast it to <T>.
* Get the value of a field and cast it to T.
*
* @param instance the instance to get the value from
* @param field the field to get the value from
Expand All @@ -256,7 +256,7 @@ public static <T> T getCastedValue(Object instance, Field field) {
}

/**
* Get the value of a field and cast it to <T>.
* Get the value of a field and cast it to T.
*
* @param instance the instance to get the value from
* @param fieldName the field to get the value from
Expand Down
2 changes: 0 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ pluginManagement {
}
plugins {
id("net.kyori.blossom") version "1.2.0"
id("net.kyori.indra")
id("net.kyori.indra.git")
}
includeBuild("build-logic")
}
Expand Down

0 comments on commit 866a297

Please sign in to comment.