Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
tajobe committed May 22, 2022
0 parents commit 91a8ca2
Show file tree
Hide file tree
Showing 17 changed files with 721 additions and 0 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/build-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Build
on:
workflow_call:
outputs:
version:
description: Built version
value: ${{ jobs.build.outputs.version }}

jobs:
build:
name: Gradle Build
runs-on: ubuntu-latest
outputs:
version: ${{ steps.version.outputs.version }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-java@v2
with:
java-version: 17
distribution: temurin
- uses: gradle/gradle-build-action@v2
- name: Gradle Build
run: ./gradlew build
- name: Get Version
id: version
run: echo ::set-output name=version::"$(./gradlew --console plain --quiet currentVersion -Prelease.quiet)"
- name: Upload build
uses: actions/upload-artifact@v3
with:
name: build
path: build/libs/*.jar
retention-days: 7
6 changes: 6 additions & 0 deletions .github/workflows/pr-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: PR
on: pull_request

jobs:
build:
uses: ./.github/workflows/build-workflow.yml
32 changes: 32 additions & 0 deletions .github/workflows/release-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Release
on:
push:
branches: ['master', 'main'] # TODO: master/main
tags:
- "v[0-9]+.[0-9]+.[0-9]+"

jobs:
build:
uses: ./.github/workflows/build-workflow.yml
release:
needs: build
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Download build
uses: actions/download-artifact@v3
with:
name: build
path: build
- name: Release
uses: docker://antonyurchenko/git-release:v4
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_NAME: ${{ needs.build.outputs.version }}
PRE_RELEASE: ${{ github.ref_type == 'branch' }}
UNRELEASED: ${{ github.ref_type == 'branch' && 'update' || '' }}
UNRELEASED_TAG: latest-snapshot
with:
args: |
build/*.jar
105 changes: 105 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@

# Created by https://www.gitignore.io/api/gradle,intellij+all
# Edit at https://www.gitignore.io/?templates=gradle,intellij+all

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

### Gradle ###
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

### Gradle Patch ###
**/build/

# End of https://www.gitignore.io/api/gradle,intellij+all
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Changelog

## [Unreleased]
### Added
- Initial Release

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

[Unreleased]: https://github.com/SimpleMC/mc-kotlin-plugin-template/compare/5cb23facc562f7ddb9662a59a3162979599a348f...HEAD
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 SimpleMC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# mc-kotlin-plugin-template
Opinionated template/starter for creating Minecraft plugins in Kotlin using the Spigot API

## Features

- 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
- [`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
`plugin.yml` and an "offline"/shadowed jar containing necessary dependencies
132 changes: 132 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
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 pl.allegro.tech.build.axion.release.domain.hooks.HooksConfig
import java.time.OffsetDateTime
import java.time.ZoneOffset
import java.time.format.DateTimeFormatter

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

plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "7.1.2"
id("pl.allegro.tech.build.axion-release") version "1.13.7"
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
}

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

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

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

hooks(
closureOf<HooksConfig> {
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 ->
"""
\[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
""".trimIndent()
})
)
)
pre("commit")
}
)
}

fun currentDateString() = OffsetDateTime.now(ZoneOffset.UTC).toLocalDate().format(DateTimeFormatter.ISO_DATE)

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(17))
}
}

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

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

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

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

filesMatching("plugin.yml") {
expand(placeholders)
}

// create an "offline" copy/variant of the plugin.yml with `libraries` omitted
doLast {
val resourcesDir = sourceSets.main.get().output.resourcesDir
val yamlDumpOptions =
// make it pretty for the people
DumperOptions().also {
it.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK)
it.setPrettyFlow(true)
}
val yaml = Yaml(yamlDumpOptions)
val pluginYml: Map<String, Any> = yaml.load(file("$resourcesDir/plugin.yml").inputStream())
yaml.dump(pluginYml.filterKeys { it != "libraries" }, file("$resourcesDir/offline-plugin.yml").writer())
}
}

jar {
exclude("offline-plugin.yml")
}

// offline jar should be ready to go with all dependencies
shadowJar {
minimize()
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.toLowerCase()}.libraries"
}

build {
dependsOn(shadowJar).dependsOn(configureShadowRelocation)
}
}
5 changes: 5 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
kotlin.code.style=official

kotlinVersion=1.6.21
mcApiVersion=1.18
repoRef=SimpleMC/mc-kotlin-plugin-template
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 91a8ca2

Please sign in to comment.