Skip to content

Commit c2292c1

Browse files
authored
Feature/template merge (#5)
* Initial commit * Features/plugin template (#2) * Added basic project template * Make gradle executable again * Fixed typos from templatizing SimpleHealthbars2 * Ensure the base jar is ready for use (#3) * Ensure the base jar is ready for use Standard jar is the full-fat jar with all dependencies (kotlin stdlib included) Added `nokt` task to create a shadowed jar excluding kotlin stdlib * Updated release action jar reference * Fixed nokt task to actually include sources and dependencies (#4) * Update dependencies to latest and improve plugin artifacts (#6) * Update dependencies to latest and improve plugin artifacts Update java, kotlin, gradle, spigot, ktlint, etc Switch to incrementMinorIfNotOnRelease version incrementer Improved packaging/artifacts by providing a plugin jar that will load libs (via spigot's `libraries` in plugin.yml) and an "offline" shadowed/fat jar shadowJar dependency relocation to prevent classpath pollution Simplify automated CHANGELOG update by making the format predictable * \N sequence was not working for changelog regex, replace with negated \n * Use default 'v' tag prefix instead of 'release-' * Fix first tag link * Release version: 0.1.0 * Revert "Release version: 0.1.0" as it was just a test This reverts commit 919b163f1dc009ad4c7cb54e496ced292b201f05. * Add comment explaining the plugin.yml offline copy * Replace jcenter with mavenCentral * New release workflow with automatic latest/snapshot releasing (#7) * Bump dependencies * Chore: Update Action workflows, bump deps, update README (#8) Update Action workflows to include a flow for manual releasing and automated publishing Update Gradle dependencies to latest--Gradle wrapper, kotlin, plugins, spigot-api Update README to include some basic instructions for using the template repo and example plugins * Formatting/linting
1 parent 5806400 commit c2292c1

17 files changed

+306
-172
lines changed

.editorconfig

+14
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

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Build
2+
on:
3+
workflow_call:
4+
outputs:
5+
version:
6+
description: Built version
7+
value: ${{ jobs.build.outputs.version }}
8+
9+
jobs:
10+
build:
11+
name: Gradle Build
12+
runs-on: ubuntu-24.04
13+
outputs:
14+
version: ${{ steps.version.outputs.version }}
15+
steps:
16+
- uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
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
26+
- name: Gradle Build
27+
run: ./gradlew build shadowJar
28+
- name: Get Version
29+
id: version
30+
run: echo "version=$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)" >> $GITHUB_OUTPUT
31+
- name: Upload build
32+
uses: actions/upload-artifact@v4
33+
with:
34+
name: build
35+
path: build/libs/*.jar
36+
retention-days: 7
37+
if-no-files-found: error

.github/workflows/create-version.yml

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Create Version
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
versionIncrementer:
7+
type: choice
8+
description: Override the default version incrementer according to https://axion-release-plugin.readthedocs.io/en/latest/configuration/version/#incrementing
9+
default: default
10+
options:
11+
- default
12+
- incrementPatch
13+
- incrementMinor
14+
- incrementMajor
15+
- incrementPrerelease
16+
17+
jobs:
18+
release:
19+
name: Gradle Release
20+
runs-on: ubuntu-24.04
21+
outputs:
22+
version: ${{ steps.version.outputs.version }}
23+
steps:
24+
- uses: actions/checkout@v4
25+
with:
26+
ssh-key: "${{ secrets.COMMIT_KEY }}"
27+
fetch-depth: 0
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
37+
- name: Gradle Release
38+
if: ${{ inputs.versionIncrementer == 'default' }}
39+
run: ./gradlew release
40+
- name: Gradle Release w/ Increment Override
41+
if: ${{ inputs.versionIncrementer != 'default' }}
42+
run: ./gradlew release -Prelease.versionIncrementer=${{ inputs.versionIncrementer }}

.github/workflows/pr-workflow.yml

+1-11
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,4 @@ on: pull_request
33

44
jobs:
55
build:
6-
name: Gradle Build
7-
runs-on: ubuntu-latest
8-
steps:
9-
- uses: actions/checkout@v3
10-
- uses: actions/setup-java@v2
11-
with:
12-
java-version: 17
13-
distribution: temurin
14-
- uses: gradle/gradle-build-action@v2
15-
with:
16-
arguments: build
6+
uses: ./.github/workflows/build-workflow.yml
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Publish
2+
on:
3+
push:
4+
branches: ['master', 'main']
5+
tags:
6+
- "v[0-9]+.[0-9]+.[0-9]+"
7+
8+
jobs:
9+
build:
10+
uses: ./.github/workflows/build-workflow.yml
11+
release:
12+
needs: build
13+
name: Create Release
14+
runs-on: ubuntu-24.04
15+
steps:
16+
- uses: actions/checkout@v4
17+
- name: Download build
18+
uses: actions/download-artifact@v4
19+
with:
20+
name: build
21+
path: build
22+
- name: Release
23+
uses: docker://antonyurchenko/git-release:v6
24+
env:
25+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
26+
RELEASE_NAME: ${{ needs.build.outputs.version }}
27+
PRE_RELEASE: ${{ github.ref_type == 'branch' }}
28+
UNRELEASED: ${{ github.ref_type == 'branch' && 'update' || '' }}
29+
UNRELEASED_TAG: latest-snapshot
30+
ALLOW_EMPTY_CHANGELOG: ${{ github.ref_type == 'branch' && 'true' || 'false' }}
31+
with:
32+
args: build/*.jar

.github/workflows/release-workflow.yml

-37
This file was deleted.

CHANGELOG.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Changelog
22

33
## [Unreleased]
4+
45
### Changed
5-
- Update gradle to 7.4
6-
- Update to Spigot/MC 1.18
7-
- Update to Java 17
6+
- Merged template SimpleMC/mc-kotlin-plugin-template
7+
- MC 1.21, Kotlin 2.1, Gradle 8
8+
- Release tag prefix changed from `release-` to `v`
89

910
## [0.1.0] - 2020-02-16
11+
1012
### Added
1113
- Initial Release
1214

build.gradle.kts

+71-86
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,112 @@
1-
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
1+
import org.yaml.snakeyaml.DumperOptions
2+
import org.yaml.snakeyaml.Yaml
23
import pl.allegro.tech.build.axion.release.domain.hooks.HookContext
3-
import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig
44
import java.time.OffsetDateTime
55
import java.time.ZoneOffset
66
import java.time.format.DateTimeFormatter
77

88
plugins {
9-
kotlin("jvm") version "1.6.10"
10-
id("com.github.johnrengelman.shadow") version "7.1.2"
11-
id("pl.allegro.tech.build.axion-release") version "1.13.6"
12-
id("org.jlleitschuh.gradle.ktlint") version "10.2.1"
9+
alias(libs.plugins.axionRelease)
10+
alias(libs.plugins.kotlin)
11+
alias(libs.plugins.ktlint)
12+
alias(libs.plugins.shadow)
1313
}
1414

15-
val repoRef = "SimpleMC\\/SimpleNPCs"
16-
val mcApiVersion = "1.18"
17-
18-
group = "org.simplemc"
19-
version = scmVersion.version
20-
2115
scmVersion {
2216
versionIncrementer("incrementMinorIfNotOnRelease", mapOf("releaseBranchPattern" to "release/.+"))
17+
unshallowRepoOnCI.set(true)
18+
19+
hooks {
20+
// Automate moving `[Unreleased]` changelog entries into `[<version>]` on release
21+
// 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"
25+
pre(
26+
"fileUpdate",
27+
mapOf(
28+
"file" to "CHANGELOG.md",
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+
}
37+
"""
38+
\[Unreleased\]
39+
40+
## \[$version\] - $currentDateString$1
41+
\[Unreleased\]: https:\/\/github\.com\/$2\/compare\/v$version...HEAD
42+
\[$version\]: https:\/\/github\.com\/$2\/$previousVersionDiffLink$3
43+
""".trimIndent()
44+
}),
45+
),
46+
)
2347

24-
hooks(
25-
closureOf<HooksConfig> {
26-
// "normal" changelog update--changelog already contains a history
27-
pre(
28-
"fileUpdate",
29-
mapOf(
30-
"file" to "CHANGELOG.md",
31-
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
32-
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/release-$v\\.\\.\\.HEAD\$([\\s\\S]*))?\\z"
33-
}),
34-
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
35-
"""
36-
\[Unreleased\]
37-
38-
## \[$v\] - ${currentDateString()}$1
39-
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD
40-
\[$v\]: https:\/\/github\.com\/$repoRef\/compare\/release-${c.previousVersion}...release-$v$2
41-
""".trimIndent()
42-
})
43-
)
44-
)
45-
// first-time changelog update--changelog has only unreleased info
46-
pre(
47-
"fileUpdate",
48-
mapOf(
49-
"file" to "CHANGELOG.md",
50-
"pattern" to KotlinClosure2<String, HookContext, String>({ _, _ ->
51-
"Unreleased([\\s\\S]+?\\nand this project adheres to \\[Semantic Versioning\\]\\(https:\\/\\/semver\\.org\\/spec\\/v2\\.0\\.0\\.html\\).)\\s\\z"
52-
}),
53-
"replacement" to KotlinClosure2<String, HookContext, String>({ v, _ ->
54-
"""
55-
\[Unreleased\]
56-
57-
## \[$v\] - ${currentDateString()}$1
58-
59-
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD
60-
\[$v\]: https:\/\/github\.com\/$repoRef\/releases\/tag\/release-$v
61-
""".trimIndent()
62-
})
63-
)
64-
)
65-
pre("commit")
66-
}
67-
)
48+
pre("commit")
49+
}
6850
}
6951

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

72-
java {
73-
toolchain {
74-
languageVersion.set(JavaLanguageVersion.of(17))
75-
}
76-
}
55+
val currentDateString: String
56+
get() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)
7757

78-
repositories {
79-
mavenCentral()
80-
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
81-
maven("https://oss.sonatype.org/content/repositories/snapshots")
58+
kotlin {
59+
jvmToolchain(21)
8260
}
8361

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

8966
tasks {
9067
wrapper {
91-
gradleVersion = "7.4.1"
9268
distributionType = Wrapper.DistributionType.ALL
9369
}
9470

9571
processResources {
9672
val placeholders = mapOf(
9773
"version" to version,
98-
"apiVersion" to mcApiVersion
74+
"apiVersion" to libs.versions.mcApi.get(),
75+
"kotlinVersion" to libs.versions.kotlin.get(),
9976
)
10077

10178
filesMatching("plugin.yml") {
10279
expand(placeholders)
10380
}
81+
82+
// create an "offline" copy/variant of the plugin.yml with `libraries` omitted
83+
doLast {
84+
val resourcesDir = sourceSets.main.get().output.resourcesDir
85+
val yamlDumpOptions =
86+
// make it pretty for the people
87+
DumperOptions().also {
88+
it.defaultFlowStyle = DumperOptions.FlowStyle.BLOCK
89+
it.isPrettyFlow = true
90+
}
91+
val yaml = Yaml(yamlDumpOptions)
92+
val pluginYml: Map<String, Any> = yaml.load(file("$resourcesDir/plugin.yml").inputStream())
93+
yaml.dump(pluginYml.filterKeys { it != "libraries" }, file("$resourcesDir/offline-plugin.yml").writer())
94+
}
10495
}
10596

106-
// standard jar should be ready to go with all dependencies
107-
shadowJar {
108-
minimize()
109-
archiveClassifier.set("")
97+
jar {
98+
exclude("offline-plugin.yml")
11099
}
111100

112-
// nokt jar without the kotlin runtime
113-
register<ShadowJar>("nokt") {
101+
// offline jar should be ready to go with all dependencies
102+
shadowJar {
114103
minimize()
115-
archiveClassifier.set("nokt")
116-
from(sourceSets.main.get().output)
117-
configurations = listOf(project.configurations.runtimeClasspath.get())
118-
119-
dependencies {
120-
exclude(dependency("org.jetbrains.*:"))
121-
}
122-
}
104+
archiveClassifier.set("offline")
105+
exclude("plugin.yml")
106+
rename("offline-plugin.yml", "plugin.yml")
123107

124-
build {
125-
dependsOn(":shadowJar", ":nokt")
108+
// avoid classpath conflicts/pollution via relocation
109+
isEnableRelocation = true
110+
relocationPrefix = "${project.group}.${project.name.lowercase()}.libraries"
126111
}
127112
}

0 commit comments

Comments
 (0)