Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
charset = utf-8
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,kts}]
ktlint_code_style = intellij_idea

[*{.yml,yaml}]
indent_style = space
indent_size = 2
16 changes: 11 additions & 5 deletions .github/workflows/build-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,27 @@ on:
jobs:
build:
name: Gradle Build
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: gradle/gradle-build-action@v2
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
- name: Gradle Build
run: ./gradlew build
run: ./gradlew build shadowJar
- name: Get Version
id: version
run: echo "version=$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)" >> $GITHUB_OUTPUT
- name: Upload build
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: build
path: build/libs/*.jar
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create Release
name: Create Version

on:
workflow_dispatch:
Expand All @@ -17,22 +17,26 @@ on:
jobs:
release:
name: Gradle Release
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
token: "${{ secrets.PAT }}"
ssh-key: "${{ secrets.COMMIT_KEY }}"
fetch-depth: 0
- uses: gradle/gradle-build-action@v2
- uses: webfactory/ssh-agent@v0.9.1
with:
ssh-private-key: ${{ secrets.COMMIT_KEY }}
- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
- uses: gradle/actions/setup-gradle@v4
- name: Gradle Release
if: ${{ inputs.versionIncrementer == 'default' }}
env:
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
run: ./gradlew release
- name: Gradle Release w/ Increment Override
if: ${{ inputs.versionIncrementer != 'default' }}
env:
DEPLOY_KEY: ${{ secrets.COMMIT_KEY }}
run: ./gradlew release -Prelease.versionIncrementer=${{ inputs.versionIncrementer }}
14 changes: 5 additions & 9 deletions .github/workflows/publish-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ jobs:
release:
needs: build
name: Create Release
runs-on: ubuntu-22.04
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: gradle/gradle-build-action@v2
- uses: actions/checkout@v4
- name: Download build
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: build
path: build
- name: Release
uses: docker://antonyurchenko/git-release:v5
uses: docker://antonyurchenko/git-release:v6
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ needs.build.outputs.version }}
Expand All @@ -32,5 +29,4 @@ jobs:
UNRELEASED_TAG: latest-snapshot
ALLOW_EMPTY_CHANGELOG: ${{ github.ref_type == 'branch' && 'true' || 'false' }}
with:
args: |
build/*.jar
args: build/*.jar
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Opinionated template/starter for creating Minecraft plugins in Kotlin using the
- Gradle axion-release-plugin for managing semver
- automatic updating of `CHANGELOG.md` and `main/resources/plugin.yml` when a release is made
- Github Actions to build PRs and automatically create Github releases when a release tag is pushed
- Manual Create Release pipeline to increment semver tag and trigger publishing a new version
- Requires a secret named `PAT` with a GitHub PAT with code read/write permission to the repository
- Manual Create Version pipeline to increment semver tag and trigger publishing a new version
- Requires a configured deploy key with write permission to the repository (see usage below)
- [`ktlint`](https://github.com/JLLeitschuh/ktlint-gradle) Gradle plugin
- Gradle build generates a standard plugin jar which will download dependencies declared as
[`libraries`](https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/plugin/PluginDescriptionFile.html#getLibraries()) in
Expand All @@ -24,19 +24,19 @@ Opinionated template/starter for creating Minecraft plugins in Kotlin using the
- `src/main/resources/plugin.yml` -> set `name`, `main`, `website`, `author`
- `src/main/kotlin/org/simplemc/plugintemplate/KotlinPluginTemplate.kt` -> Move packages/rename for your plugin
- `README.md` -> Update
3. To use the Create Release automation, add PAT secret
1. Create a Personal Access Token: https://github.com/settings/personal-access-tokens/new
- Repository Access: "Only select repositories" and pick the plugin template fork
- Repository Permissions: Contents Read & write
- This is so the automation can create release commits
2. Add the PAT as an Actions secret to your new repository: `https://github.com/<repo slug>/settings/secrets/actions/new`
- Name: `PAT`
- Secret Contents: Paste the Personal Access Token you created in the previous step
3. To use the Create Version automation, add an SSH key
1. Create an SSH key-pair (no password): `ssh-keygen -t ed25519 -C "your_email@example.com" -f ~/.ssh/<name_your_key>deploy`
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`
3. Add the Private Key as an Actions secret: `https://github.com/<repo slug>/settings/secrets/actions/new`
- Name: `COMMIT_KEY`
- Secret Contents: Paste the Private key
4. The GitHub Actions are configured to use this key to publish tags and release commits (see `.github/workflows/create-version.yml`)
- See [axion-release-plugin Authorization](https://axion-release-plugin.readthedocs.io/en/latest/configuration/authorization/) for alternative Auth options

## Examples

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

- [SimpleNPCs](https://github.com/SimpleMC/SimpleNPCs) - Simple command-based NPC interactions
- [SimpleHealthbars2](https://github.com/SimpleMC/SimpleHealthbars2) - Simple, easy-to-use healthbar plugin with optional player and mob healthbars
- [SimpleAnnounce](https://github.com/SimpleMC/SimpleAnnounce) - SimpleAnnounce is a simple and easy to use, yet powerful automated announcement plugin for the Bukkit Minecraft API.
- [SimpleAnnounce](https://github.com/SimpleMC/SimpleAnnounce) - SimpleAnnounce is a simple and easy to use, yet powerful automated announcement plugin for the Bukkit Minecraft API.
87 changes: 34 additions & 53 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,91 +1,78 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ConfigureShadowRelocation
import org.yaml.snakeyaml.DumperOptions
import org.yaml.snakeyaml.Yaml
import pl.allegro.tech.build.axion.release.domain.hooks.HookContext
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.yaml:snakeyaml:2.0")
}
}

plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "8.0.0"
id("pl.allegro.tech.build.axion-release") version "1.14.4"
id("org.jlleitschuh.gradle.ktlint") version "11.2.0"
alias(libs.plugins.axionRelease)
alias(libs.plugins.kotlin)
alias(libs.plugins.ktlint)
alias(libs.plugins.shadow)
}

group = "org.simplemc"
version = scmVersion.version

val mcApiVersion: String by project
val repoRef: String by project

scmVersion {
versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+"))
unshallowRepoOnCI.set(true)

hooks {
// Automate moving `[Unreleased]` changelog entries into `[<version>]` on release
// FIXME - workaround for Kotlin DSL issue https://github.com/allegro/axion-release-plugin/issues/500
val changelogPattern =
"\\[Unreleased\\]([\\s\\S]+?)\\n" +
"(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/(\\S+\\/\\S+)\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
pre(
"fileUpdate",
mapOf(
"file" to "CHANGELOG.md",
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/[^\\n]*\$([\\s\\S]*))?\\z"
}),
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
"pattern" to KotlinClosure2<String, HookContext, String>({ _, _ -> changelogPattern }),
"replacement" to KotlinClosure2<String, HookContext, String>({ version, context ->
// github "diff" for previous version
val previousVersionDiffLink =
when (context.previousVersion == version) {
true -> "releases/tag/v$version" // no previous, just link to the version
false -> "compare/v${context.previousVersion}...v$version"
}
"""
\[Unreleased\]

## \[$v\] - ${currentDateString()}$1
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/v$v...HEAD
\[$v\]: https:\/\/github\.com\/$repoRef\/${if (c.previousVersion == v) "releases/tag/v$v" else "compare/v${c.previousVersion}...v$v"}${'$'}2
## \[$version\] - $currentDateString$1
\[Unreleased\]: https:\/\/github\.com\/$2\/compare\/v$version...HEAD
\[$version\]: https:\/\/github\.com\/$2\/$previousVersionDiffLink$3
""".trimIndent()
})
)
}),
),
)

pre("commit")
}
}

fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)
group = "org.simplemc"
version = scmVersion.version

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}
val currentDateString: String
get() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)

repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://oss.sonatype.org/content/repositories/snapshots")
kotlin {
jvmToolchain(21)
}

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

tasks {
wrapper {
gradleVersion = "8.0.1"
distributionType = Wrapper.DistributionType.ALL
}

processResources {
val placeholders = mapOf(
"version" to version,
"apiVersion" to mcApiVersion,
"kotlinVersion" to project.properties["kotlinVersion"]
"apiVersion" to libs.versions.mcApi.get(),
"kotlinVersion" to libs.versions.kotlin.get(),
)

filesMatching("plugin.yml") {
Expand Down Expand Up @@ -117,15 +104,9 @@ tasks {
archiveClassifier.set("offline")
exclude("plugin.yml")
rename("offline-plugin.yml", "plugin.yml")
}

// avoid classpath conflicts/pollution via relocation
val configureShadowRelocation by registering(ConfigureShadowRelocation::class) {
target = shadowJar.get()
prefix = "${project.group}.${project.name.lowercase()}.libraries"
}

build {
dependsOn(shadowJar).dependsOn(configureShadowRelocation)
// avoid classpath conflicts/pollution via relocation
isEnableRelocation = true
relocationPrefix = "${project.group}.${project.name.lowercase()}.libraries"
}
}
4 changes: 0 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
kotlin.code.style=official

kotlinVersion=1.8.10
mcApiVersion=1.19
repoRef=SimpleMC/mc-kotlin-plugin-template
2 changes: 2 additions & 0 deletions gradle/gradle-daemon-jvm.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#This file is generated by updateDaemonJvm
toolchainVersion=21
16 changes: 16 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[versions]
axionRelease = "1.18.18"
kotlin = "2.1.20"
ktlintGradle = "12.2.0"
mcApi = "1.21"
shadow = "8.3.6"
spigot = "1.21.+"

[plugins]
axionRelease = { id = "pl.allegro.tech.build.axion-release", version.ref = "axionRelease"}
kotlin = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin"}
ktlint = { id = "org.jlleitschuh.gradle.ktlint", version.ref = "ktlintGradle"}
shadow = { id = "com.gradleup.shadow", version.ref = "shadow"}

[libraries]
spigot = { group = "org.spigotmc", name = "spigot-api", version.ref = "spigot" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading