Skip to content

Commit 106b5ba

Browse files
authored
Use latest standards in gradle build and bump java/mc/gradle (#10)
1 parent 9aa5a0d commit 106b5ba

14 files changed

+164
-122
lines changed

.editorconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_size = 4
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.{kt,kts}]
10+
ktlint_code_style = intellij_idea
11+
12+
[*{.yml,yaml}]
13+
indent_style = space
14+
indent_size = 2

.github/workflows/build-workflow.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,27 @@ on:
99
jobs:
1010
build:
1111
name: Gradle Build
12-
runs-on: ubuntu-22.04
12+
runs-on: ubuntu-24.04
1313
outputs:
1414
version: ${{ steps.version.outputs.version }}
1515
steps:
16-
- uses: actions/checkout@v3
16+
- uses: actions/checkout@v4
1717
with:
1818
fetch-depth: 0
19-
- uses: gradle/gradle-build-action@v2
19+
- name: Setup Java
20+
uses: actions/setup-java@v4
21+
with:
22+
distribution: 'temurin'
23+
java-version: 21
24+
- name: Setup Gradle
25+
uses: gradle/actions/setup-gradle@v4
2026
- name: Gradle Build
21-
run: ./gradlew build
27+
run: ./gradlew build shadowJar
2228
- name: Get Version
2329
id: version
2430
run: echo "version=$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)" >> $GITHUB_OUTPUT
2531
- name: Upload build
26-
uses: actions/upload-artifact@v3
32+
uses: actions/upload-artifact@v4
2733
with:
2834
name: build
2935
path: build/libs/*.jar
Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Create Release
1+
name: Create Version
22

33
on:
44
workflow_dispatch:
@@ -17,22 +17,26 @@ on:
1717
jobs:
1818
release:
1919
name: Gradle Release
20-
runs-on: ubuntu-22.04
20+
runs-on: ubuntu-24.04
2121
outputs:
2222
version: ${{ steps.version.outputs.version }}
2323
steps:
24-
- uses: actions/checkout@v3
24+
- uses: actions/checkout@v4
2525
with:
26-
token: "${{ secrets.PAT }}"
26+
ssh-key: "${{ secrets.COMMIT_KEY }}"
2727
fetch-depth: 0
28-
- uses: gradle/gradle-build-action@v2
28+
- uses: webfactory/[email protected]
29+
with:
30+
ssh-private-key: ${{ secrets.COMMIT_KEY }}
31+
- name: Setup Java
32+
uses: actions/setup-java@v4
33+
with:
34+
distribution: 'temurin'
35+
java-version: 21
36+
- uses: gradle/actions/setup-gradle@v4
2937
- name: Gradle Release
3038
if: ${{ inputs.versionIncrementer == 'default' }}
31-
env:
32-
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
3339
run: ./gradlew release
3440
- name: Gradle Release w/ Increment Override
3541
if: ${{ inputs.versionIncrementer != 'default' }}
36-
env:
37-
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
3842
run: ./gradlew release -Prelease.versionIncrementer=${{ inputs.versionIncrementer }}

.github/workflows/publish-workflow.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,16 @@ jobs:
1111
release:
1212
needs: build
1313
name: Create Release
14-
runs-on: ubuntu-22.04
14+
runs-on: ubuntu-24.04
1515
steps:
16-
- uses: actions/checkout@v3
17-
with:
18-
fetch-depth: 0
19-
- uses: gradle/gradle-build-action@v2
16+
- uses: actions/checkout@v4
2017
- name: Download build
21-
uses: actions/download-artifact@v3
18+
uses: actions/download-artifact@v4
2219
with:
2320
name: build
2421
path: build
2522
- name: Release
26-
uses: docker://antonyurchenko/git-release:v5
23+
uses: docker://antonyurchenko/git-release:v6
2724
env:
2825
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2926
RELEASE_NAME: ${{ needs.build.outputs.version }}
@@ -32,5 +29,4 @@ jobs:
3229
UNRELEASED_TAG: latest-snapshot
3330
ALLOW_EMPTY_CHANGELOG: ${{ github.ref_type == 'branch' && 'true' || 'false' }}
3431
with:
35-
args: |
36-
build/*.jar
32+
args: build/*.jar

README.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Opinionated template/starter for creating Minecraft plugins in Kotlin using the
66
- Gradle axion-release-plugin for managing semver
77
- automatic updating of `CHANGELOG.md` and `main/resources/plugin.yml` when a release is made
88
- Github Actions to build PRs and automatically create Github releases when a release tag is pushed
9-
- Manual Create Release pipeline to increment semver tag and trigger publishing a new version
10-
- Requires a secret named `PAT` with a GitHub PAT with code read/write permission to the repository
9+
- Manual Create Version pipeline to increment semver tag and trigger publishing a new version
10+
- Requires a configured deploy key with write permission to the repository (see usage below)
1111
- [`ktlint`](https://github.com/JLLeitschuh/ktlint-gradle) Gradle plugin
1212
- Gradle build generates a standard plugin jar which will download dependencies declared as
1313
[`libraries`](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/PluginDescriptionFile.html#getLibraries()) in
@@ -24,19 +24,19 @@ Opinionated template/starter for creating Minecraft plugins in Kotlin using the
2424
- `src/main/resources/plugin.yml` -> set `name`, `main`, `website`, `author`
2525
- `src/main/kotlin/org/simplemc/plugintemplate/KotlinPluginTemplate.kt` -> Move packages/rename for your plugin
2626
- `README.md` -> Update
27-
3. To use the Create Release automation, add PAT secret
28-
1. Create a Personal Access Token: https://github.com/settings/personal-access-tokens/new
29-
- Repository Access: "Only select repositories" and pick the plugin template fork
30-
- Repository Permissions: Contents Read & write
31-
- This is so the automation can create release commits
32-
2. Add the PAT as an Actions secret to your new repository: `https://github.com/<repo slug>/settings/secrets/actions/new`
33-
- Name: `PAT`
34-
- Secret Contents: Paste the Personal Access Token you created in the previous step
27+
3. To use the Create Version automation, add an SSH key
28+
1. Create an SSH key-pair (no password): `ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/<name_your_key>deploy`
29+
2. Add the Public Key as a Deploy Key (**Important! Enable `Allow write access`**): https://docs.github.com/en/authentication/connecting-to-github-with-ssh/managing-deploy-keys#set-up-deploy-keys an Actions secret to your new repository: `https://github.com/<repo slug>/settings/secrets/actions/new`
30+
3. Add the Private Key as an Actions secret: `https://github.com/<repo slug>/settings/secrets/actions/new`
31+
- Name: `COMMIT_KEY`
32+
- Secret Contents: Paste the Private key
33+
4. The GitHub Actions are configured to use this key to publish tags and release commits (see `.github/workflows/create-version.yml`)
34+
- See [axion-release-plugin Authorization](https://axion-release-plugin.readthedocs.io/en/latest/configuration/authorization/) for alternative Auth options
3535

3636
## Examples
3737

3838
Several SimpleMC plugins are built off of this template or were the impetus for it:
3939

4040
- [SimpleNPCs](https://github.com/SimpleMC/SimpleNPCs) - Simple command-based NPC interactions
4141
- [SimpleHealthbars2](https://github.com/SimpleMC/SimpleHealthbars2) - Simple, easy-to-use healthbar plugin with optional player and mob healthbars
42-
- [SimpleAnnounce](https://github.com/SimpleMC/SimpleAnnounce) - SimpleAnnounce is a simple and easy to use, yet powerful automated announcement plugin for the Bukkit Minecraft API.
42+
- [SimpleAnnounce](https://github.com/SimpleMC/SimpleAnnounce) - SimpleAnnounce is a simple and easy to use, yet powerful automated announcement plugin for the Bukkit Minecraft API.

build.gradle.kts

Lines changed: 34 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,78 @@
1-
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
21
import org.yaml.snakeyaml.DumperOptions
32
import org.yaml.snakeyaml.Yaml
43
import pl.allegro.tech.build.axion.release.domain.hooks.HookContext
54
import java.time.OffsetDateTime
65
import java.time.ZoneOffset
76
import java.time.format.DateTimeFormatter
87

9-
buildscript {
10-
repositories {
11-
mavenCentral()
12-
}
13-
dependencies {
14-
classpath("org.yaml:snakeyaml:2.0")
15-
}
16-
}
17-
188
plugins {
19-
kotlin("jvm")
20-
id("com.github.johnrengelman.shadow") version "8.0.0"
21-
id("pl.allegro.tech.build.axion-release") version "1.14.4"
22-
id("org.jlleitschuh.gradle.ktlint") version "11.2.0"
9+
alias(libs.plugins.axionRelease)
10+
alias(libs.plugins.kotlin)
11+
alias(libs.plugins.ktlint)
12+
alias(libs.plugins.shadow)
2313
}
2414

25-
group = "org.simplemc"
26-
version = scmVersion.version
27-
28-
val mcApiVersion: String by project
29-
val repoRef: String by project
30-
3115
scmVersion {
3216
versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+"))
17+
unshallowRepoOnCI.set(true)
3318

3419
hooks {
20+
// Automate moving `[Unreleased]` changelog entries into `[<version>]` on release
3521
// FIXME - workaround for Kotlin DSL issue https://github.com/allegro/axion-release-plugin/issues/500
22+
val changelogPattern =
23+
"\\[Unreleased\\]([\\s\\S]+?)\\n" +
24+
"(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/(\\S+\\/\\S+)\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
3625
pre(
3726
"fileUpdate",
3827
mapOf(
3928
"file" to "CHANGELOG.md",
40-
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
41-
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
42-
}),
43-
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
29+
"pattern" to KotlinClosure2<String, HookContext, String>({ _, _ -> changelogPattern }),
30+
"replacement" to KotlinClosure2<String, HookContext, String>({ version, context ->
31+
// github "diff" for previous version
32+
val previousVersionDiffLink =
33+
when (context.previousVersion == version) {
34+
true -> "releases/tag/v$version" // no previous, just link to the version
35+
false -> "compare/v${context.previousVersion}...v$version"
36+
}
4437
"""
4538
\[Unreleased\]
4639
47-
## \[$v\] - ${currentDateString()}$1
48-
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD
49-
\[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2
40+
## \[$version\] - $currentDateString$1
41+
\[Unreleased\]: https:\/\/github\.com\/$2\/compare\/v$version...HEAD
42+
\[$version\]: https:\/\/github\.com\/$2\/$previousVersionDiffLink$3
5043
""".trimIndent()
51-
})
52-
)
44+
}),
45+
),
5346
)
5447

5548
pre("commit")
5649
}
5750
}
5851

59-
fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)
52+
group = "org.simplemc"
53+
version = scmVersion.version
6054

61-
java {
62-
toolchain {
63-
languageVersion.set(JavaLanguageVersion.of(17))
64-
}
65-
}
55+
val currentDateString: String
56+
get() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)
6657

67-
repositories {
68-
mavenCentral()
69-
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
70-
maven("https://oss.sonatype.org/content/repositories/snapshots")
58+
kotlin {
59+
jvmToolchain(21)
7160
}
7261

7362
dependencies {
74-
implementation(kotlin("stdlib-jdk8"))
75-
compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+")
63+
compileOnly(libs.spigot)
7664
}
7765

7866
tasks {
7967
wrapper {
80-
gradleVersion = "8.0.1"
8168
distributionType = Wrapper.DistributionType.ALL
8269
}
8370

8471
processResources {
8572
val placeholders = mapOf(
8673
"version" to version,
87-
"apiVersion" to mcApiVersion,
88-
"kotlinVersion" to project.properties["kotlinVersion"]
74+
"apiVersion" to libs.versions.mcApi.get(),
75+
"kotlinVersion" to libs.versions.kotlin.get(),
8976
)
9077

9178
filesMatching("plugin.yml") {
@@ -117,15 +104,9 @@ tasks {
117104
archiveClassifier.set("offline")
118105
exclude("plugin.yml")
119106
rename("offline-plugin.yml", "plugin.yml")
120-
}
121-
122-
// avoid classpath conflicts/pollution via relocation
123-
val configureShadowRelocation by registering(ConfigureShadowRelocation::class) {
124-
target = shadowJar.get()
125-
prefix = "${project.group}.${project.name.lowercase()}.libraries"
126-
}
127107

128-
build {
129-
dependsOn(shadowJar).dependsOn(configureShadowRelocation)
108+
// avoid classpath conflicts/pollution via relocation
109+
isEnableRelocation = true
110+
relocationPrefix = "${project.group}.${project.name.lowercase()}.libraries"
130111
}
131112
}

gradle.properties

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
11
kotlin.code.style=official
2-
3-
kotlinVersion=1.8.10
4-
mcApiVersion=1.19
5-
repoRef=SimpleMC/mc-kotlin-plugin-template
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
#This file is generated by updateDaemonJvm
2+
toolchainVersion=21

gradle/libs.versions.toml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[versions]
2+
axionRelease = "1.18.18"
3+
kotlin = "2.1.20"
4+
ktlintGradle = "12.2.0"
5+
mcApi = "1.21"
6+
shadow = "8.3.6"
7+
spigot = "1.21.+"
8+
9+
[plugins]
10+
axionRelease = { id = "pl.allegro.tech.build.axion-release", version.ref = "axionRelease"}
11+
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"}
12+
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"}
13+
shadow = { id = "com.gradleup.shadow", version.ref = "shadow"}
14+
15+
[libraries]
16+
spigot = { group = "org.spigotmc", name = "spigot-api", version.ref = "spigot" }

gradle/wrapper/gradle-wrapper.jar

-17.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)