Skip to content

Commit a9afb11

Browse files
authored
Features/plugin template (SimpleMC#2)
* Added basic project template * Make gradle executable again * Fixed typos from templatizing SimpleHealthbars2
1 parent 5cb23fa commit a9afb11

15 files changed

+623
-1
lines changed

Diff for: .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

Diff for: .github/workflows/release-workflow.yml

+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 }}-all.jar

Diff for: .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

Diff for: 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).

Diff for: README.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
11
# mc-kotlin-plugin-template
2-
Template/starter for creating kotlin minecraft plugins
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 both a shadow jar which includes kotlin stdlib and a normal jar without
11+
- Users with the stdlib already on the classpath can use the smaller jar

Diff for: build.gradle.kts

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

Diff for: gradle.properties

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

Diff for: gradle/wrapper/gradle-wrapper.jar

54.3 KB
Binary file not shown.

Diff for: gradle/wrapper/gradle-wrapper.properties

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