Skip to content

Commit a1c591d

Browse files
committed
Initial commit
0 parents  commit a1c591d

16 files changed

+658
-0
lines changed

.github/workflows/pr-workflow.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: PR
2+
on: pull_request
3+
4+
jobs:
5+
build:
6+
name: Gradle Build
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v1
10+
- uses: actions/setup-java@v1
11+
with:
12+
java-version: 11
13+
- uses: actions/cache@v1
14+
with:
15+
path: ~/.gradle/wrapper
16+
key: ${{ runner.os }}-gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
17+
- uses: actions/cache@v1
18+
with:
19+
path: ~/.gradle/caches
20+
key: ${{ runner.os }}-gradle-caches-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
21+
restore-keys: |
22+
${{ runner.os }}-gradle-caches-
23+
- uses: eskatos/gradle-command-action@v1
24+
with:
25+
arguments: build
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- 'release-*'
6+
7+
jobs:
8+
release:
9+
name: Create Release
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v1
13+
- uses: actions/setup-java@v1
14+
with:
15+
java-version: 11
16+
- name: Gradle Build
17+
uses: eskatos/gradle-command-action@v1
18+
with:
19+
arguments: build
20+
- name: Extract version
21+
uses: frabert/replace-string-action@master
22+
id: format-version
23+
with:
24+
pattern: 'refs/tags/release-([0-9]+.[0-9]+.[0-9]+)'
25+
string: ${{ github.ref }}
26+
replace-with: '$1'
27+
- name: Release
28+
uses: docker://antonyurchenko/git-release:v3
29+
env:
30+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
31+
DRAFT_RELEASE: "true"
32+
ALLOW_TAG_PREFIX: "true"
33+
with:
34+
args: |
35+
build/libs/mc-kotlin-plugin-template-${{ steps.format-version.outputs.replaced }}.jar
36+
build/libs/mc-kotlin-plugin-template-${{ steps.format-version.outputs.replaced }}-nokt.jar

.gitignore

+105
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
2+
# Created by https://www.gitignore.io/api/gradle,intellij+all
3+
# Edit at https://www.gitignore.io/?templates=gradle,intellij+all
4+
5+
### Intellij+all ###
6+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
7+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8+
9+
# User-specific stuff
10+
.idea/**/workspace.xml
11+
.idea/**/tasks.xml
12+
.idea/**/usage.statistics.xml
13+
.idea/**/dictionaries
14+
.idea/**/shelf
15+
16+
# Generated files
17+
.idea/**/contentModel.xml
18+
19+
# Sensitive or high-churn files
20+
.idea/**/dataSources/
21+
.idea/**/dataSources.ids
22+
.idea/**/dataSources.local.xml
23+
.idea/**/sqlDataSources.xml
24+
.idea/**/dynamic.xml
25+
.idea/**/uiDesigner.xml
26+
.idea/**/dbnavigator.xml
27+
28+
# Gradle
29+
.idea/**/gradle.xml
30+
.idea/**/libraries
31+
32+
# Gradle and Maven with auto-import
33+
# When using Gradle or Maven with auto-import, you should exclude module files,
34+
# since they will be recreated, and may cause churn. Uncomment if using
35+
# auto-import.
36+
# .idea/modules.xml
37+
# .idea/*.iml
38+
# .idea/modules
39+
40+
# CMake
41+
cmake-build-*/
42+
43+
# Mongo Explorer plugin
44+
.idea/**/mongoSettings.xml
45+
46+
# File-based project format
47+
*.iws
48+
49+
# IntelliJ
50+
out/
51+
52+
# mpeltonen/sbt-idea plugin
53+
.idea_modules/
54+
55+
# JIRA plugin
56+
atlassian-ide-plugin.xml
57+
58+
# Cursive Clojure plugin
59+
.idea/replstate.xml
60+
61+
# Crashlytics plugin (for Android Studio and IntelliJ)
62+
com_crashlytics_export_strings.xml
63+
crashlytics.properties
64+
crashlytics-build.properties
65+
fabric.properties
66+
67+
# Editor-based Rest Client
68+
.idea/httpRequests
69+
70+
# Android studio 3.1+ serialized cache file
71+
.idea/caches/build_file_checksums.ser
72+
73+
### Intellij+all Patch ###
74+
# Ignores the whole .idea folder and all .iml files
75+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
76+
77+
.idea/
78+
79+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
80+
81+
*.iml
82+
modules.xml
83+
.idea/misc.xml
84+
*.ipr
85+
86+
### Gradle ###
87+
.gradle
88+
/build/
89+
90+
# Ignore Gradle GUI config
91+
gradle-app.setting
92+
93+
# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
94+
!gradle-wrapper.jar
95+
96+
# Cache of project
97+
.gradletasknamecache
98+
99+
# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
100+
# gradle/wrapper/gradle-wrapper.properties
101+
102+
### Gradle Patch ###
103+
**/build/
104+
105+
# End of https://www.gitignore.io/api/gradle,intellij+all

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
## Unreleased
4+
### Added
5+
- Initial Release
6+
7+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 SimpleMC
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# mc-kotlin-plugin-template
2+
Opinionated template/starter for creating Minecraft plugins in Kotlin using the Spigot API
3+
4+
## Features
5+
6+
- Gradle axion-release-plugin for managing semver
7+
- automatic updating of `CHANGELOG.md` and `main/resources/plugin.yml` when a release is made
8+
- Github Actions to build PRs and automatically create Github releases when a release tag is pushed
9+
- [`ktlint`](https://github.com/JLLeitschuh/ktlint-gradle) Gradle plugin
10+
- Gradle build generates a shadowed jar which includes kotlin stdlib and a `nokt` jar without
11+
- Users with the stdlib already on the classpath can use the smaller jar

build.gradle.kts

+130
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
2+
import pl.allegro.tech.build.axion.release.domain.hooks.HookContext
3+
import pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig
4+
import java.time.OffsetDateTime
5+
import java.time.ZoneOffset
6+
import java.time.format.DateTimeFormatter
7+
8+
plugins {
9+
kotlin("jvm") version "1.3.61"
10+
id("com.github.johnrengelman.shadow") version "5.2.0"
11+
id("pl.allegro.tech.build.axion-release") version "1.10.3"
12+
id("org.jlleitschuh.gradle.ktlint") version "9.1.1"
13+
}
14+
15+
val repoRef = "SimpleMC\\/mc-kotlin-plugin-template"
16+
val mcApiVersion = "1.15"
17+
18+
group = "org.simplemc"
19+
version = scmVersion.version
20+
21+
scmVersion {
22+
hooks(closureOf<HooksConfig> {
23+
pre(
24+
"fileUpdate",
25+
mapOf(
26+
"file" to "src/main/resources/plugin.yml",
27+
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ -> "version: $v\\napi-version: \".+\"" }),
28+
"replacement" to KotlinClosure2<String, HookContext, String>({ v, _ -> "version: $v\napi-version: \"$mcApiVersion\"" })
29+
)
30+
)
31+
// "normal" changelog update--changelog already contains a history
32+
pre(
33+
"fileUpdate",
34+
mapOf(
35+
"file" to "CHANGELOG.md",
36+
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
37+
"\\[Unreleased\\]([\\s\\S]+?)\\n(?:^\\[Unreleased\\]: https:\\/\\/github\\.com\\/$repoRef\\/compare\\/release-$v\\.\\.\\.HEAD\$([\\s\\S]*))?\\z"
38+
}),
39+
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
40+
"""
41+
\[Unreleased\]
42+
43+
## \[$v\] - ${currentDateString()}$1
44+
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD
45+
\[$v\]: https:\/\/github\.com\/$repoRef\/compare\/release-${c.previousVersion}...release-$v$2
46+
""".trimIndent()
47+
})
48+
)
49+
)
50+
// first-time changelog update--changelog has only unreleased info
51+
pre(
52+
"fileUpdate",
53+
mapOf(
54+
"file" to "CHANGELOG.md",
55+
"pattern" to KotlinClosure2<String, HookContext, String>({ v, _ ->
56+
"Unreleased([\\s\\S]+?\\nand this project adheres to \\[Semantic Versioning\\]\\(https:\\/\\/semver\\.org\\/spec\\/v2\\.0\\.0\\.html\\).)\\s\\z"
57+
}),
58+
"replacement" to KotlinClosure2<String, HookContext, String>({ v, c ->
59+
"""
60+
\[Unreleased\]
61+
62+
## \[$v\] - ${currentDateString()}$1
63+
64+
\[Unreleased\]: https:\/\/github\.com\/$repoRef\/compare\/release-$v...HEAD
65+
\[$v\]: https:\/\/github\.com\/$repoRef\/releases\/tag\/release-$v
66+
""".trimIndent()
67+
})
68+
)
69+
)
70+
pre("commit")
71+
})
72+
}
73+
74+
fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)
75+
76+
java {
77+
sourceCompatibility = JavaVersion.VERSION_11
78+
targetCompatibility = JavaVersion.VERSION_11
79+
}
80+
81+
repositories {
82+
jcenter()
83+
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
84+
maven("https://oss.sonatype.org/content/repositories/snapshots")
85+
}
86+
87+
dependencies {
88+
implementation(kotlin("stdlib-jdk8"))
89+
compileOnly(group = "org.spigotmc", name = "spigot-api", version = "$mcApiVersion+")
90+
}
91+
92+
ktlint {
93+
// FIXME - ktlint bug(?): https://github.com/pinterest/ktlint/issues/527
94+
disabledRules.set(listOf("import-ordering"))
95+
}
96+
97+
tasks {
98+
wrapper {
99+
gradleVersion = "6.1.1"
100+
distributionType = Wrapper.DistributionType.ALL
101+
}
102+
103+
compileKotlin {
104+
kotlinOptions {
105+
jvmTarget = "1.8"
106+
}
107+
}
108+
109+
// standard jar should be ready to go with all dependencies
110+
shadowJar {
111+
minimize()
112+
archiveClassifier.set("")
113+
}
114+
115+
// nokt jar without the kotlin runtime
116+
register<ShadowJar>("nokt") {
117+
minimize()
118+
archiveClassifier.set("nokt")
119+
from(sourceSets.main.get().output)
120+
configurations = listOf(project.configurations.runtimeClasspath.get())
121+
122+
dependencies {
123+
exclude(dependency("org.jetbrains.*:"))
124+
}
125+
}
126+
127+
build {
128+
dependsOn(":shadowJar", ":nokt")
129+
}
130+
}

gradle.properties

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kotlin.code.style=official

gradle/wrapper/gradle-wrapper.jar

54.3 KB
Binary file not shown.
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

0 commit comments

Comments
 (0)