Skip to content

Commit

Permalink
feat: Greatly simplified the template
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Jun 3, 2024
1 parent 47079a5 commit b38bf7f
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 104 deletions.
37 changes: 21 additions & 16 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,41 +30,46 @@ jobs:
uses: actions/setup-java@v4
with:
java-version: 17
distribution: "temurin"
cache: "gradle"
distribution: 'temurin'

- name: Build Artifact
run: ./gradlew build
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Set up Artifact Upload
id: upload
run: echo "ARTIFACT_PATH=$(./gradlew getArtifactPath -q)" >> $GITHUB_ENV
- name: Build Artifact
run: ./gradlew release

- name: Upload Artifact to Actions
uses: actions/upload-artifact@v4
with:
name: ${{ github.event.repository.name }}
path: ${{ env.ARTIFACT_PATH }}
if-no-files-found: error
name: "${{ github.event.repository.name }}-artifacts"
path: build/tmp/release/*.jar

- name: Determine Status
run: |
if [ "$(./gradlew properties | awk '/^version:/ { print $2; }' | grep '\-SNAPSHOT')" ]; then
echo "STATUS=snapshot" >> $GITHUB_ENV
else
echo "STATUS=release" >> $GITHUB_ENV
fi
- name: Upload Artifact to Release
if: ${{ github.event_name == 'release' }}
- name: Upload Artifacts to Release
if: ${{ env.STATUS == 'release' && github.event_name == 'release' }}
uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
asset_name: ${{ github.event.repository.name }}.jar
file: ${{ env.ARTIFACT_PATH }}
file: build/tmp/release/*.jar
file_glob: true
tag: ${{ github.ref }}

- name: Update Changelog
if: ${{ github.event_name == 'release' }}
if: ${{ env.STATUS == 'release' && github.event_name == 'release' }}
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.tag_name }}
release-notes: ${{ github.event.release.body }}

- name: Commit Updated Changelog
if: ${{ github.event_name == 'release' }}
if: ${{ env.STATUS == 'release' && github.event_name == 'release' }}
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ github.event.release.target_commitish }}
Expand Down
3 changes: 0 additions & 3 deletions .spotless/project.importorder

This file was deleted.

23 changes: 0 additions & 23 deletions HEADER.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 Xpdustry
Copyright (c) 2024 Xpdustry

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 4 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
[![Build status](https://github.com/xpdustry/template-plugin/actions/workflows/build.yml/badge.svg?branch=master&event=push)](https://github.com/xpdustry/template-plugin/actions/workflows/build.yml)
[![Mindustry 7.0 ](https://img.shields.io/badge/Mindustry-7.0-ffd37f)](https://github.com/Anuken/Mindustry/releases)

Get your Mindustry plugin started with this awesome template repository, it features :
Get your Mindustry plugin started with this awesome template repository, it features:

- GitHub actions for easier testing (the plugin is built for each commit and pull request).

- [Toxopid](https://plugins.gradle.org/plugin/fr.xpdustry.toxopid) Gradle plugin for faster Mindustry plugin
- [Toxopid](https://plugins.gradle.org/plugin/com.xpdustry.toxopid) Gradle plugin for faster Mindustry plugin
development and testing.

- [Indra](https://plugins.gradle.org/plugin/net.kyori.indra) Gradle plugin for easier java development.
Expand All @@ -17,15 +17,13 @@ Get your Mindustry plugin started with this awesome template repository, it feat

- Unused classes are removed from the final jar.

- The build script contains a lot of comments to help you understand what is going on.

- A `CHANGELOG.md` file that will be updated automatically when you create a release on GitHub.

## How to use

1. Update the `build.gradle.kts`, `settings.gradle.kts` and `plugin.json` files with your plugin data.

2. Clear `CHANGELOG.md` and update `LICENSE.md` with your name.
2. Clear `CHANGELOG.md` and update `LICENSE.md` with your name (or completely changing the license if needed)

3. Start **K O D I N G**.

Expand All @@ -44,8 +42,6 @@ This plugin requires :
- `./gradlew shadowJar` to compile the plugin into a usable jar (will be located
at `builds/libs/(plugin-name).jar`).

- `./gradlew jar` for a plain jar that contains only the plugin code.

- `./gradlew runMindustryServer` to run the plugin in a local Mindustry server.

- `./gradlew runMindustryClient` to start a local Mindustry client that will let you test the plugin.
- `./gradlew runMindustryDesktop` to start a local Mindustry client that will let you test the plugin.
75 changes: 26 additions & 49 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,52 +1,45 @@
import fr.xpdustry.toxopid.dsl.mindustryDependencies
import fr.xpdustry.toxopid.spec.ModMetadata
import fr.xpdustry.toxopid.spec.ModPlatform
import com.xpdustry.toxopid.extension.anukeXpdustry
import com.xpdustry.toxopid.spec.ModMetadata
import com.xpdustry.toxopid.spec.ModPlatform

plugins {
id("net.kyori.indra") version "3.1.3"
id("net.kyori.indra.git") version "3.1.3"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("fr.xpdustry.toxopid") version "3.2.0"
alias(libs.plugins.indra.common)
alias(libs.plugins.indra.git)
alias(libs.plugins.shadow)
alias(libs.plugins.toxopid)
}

val metadata = ModMetadata.fromJson(rootProject.file("plugin.json"))

group = "com.xpdustry"
val rootPackage = "com.xpdustry.template"
version = metadata.version
description = metadata.description

toxopid {
compileVersion.set("v${metadata.minGameVersion}")
platforms.set(setOf(ModPlatform.HEADLESS))
platforms.set(setOf(ModPlatform.SERVER))
}

repositories {
mavenCentral()
// This repository provides mindustry artifacts built by xpdustry
maven("https://maven.xpdustry.com/mindustry")
// This repository provides xpdustry libraries, such as the distributor-api
maven("https://maven.xpdustry.com/releases")
anukeXpdustry()
}

dependencies {
mindustryDependencies()
compileOnly(toxopid.dependencies.arcCore)
compileOnly(toxopid.dependencies.mindustryCore)
}

// Indra will set up a lot of boilerplate for you, only leaving the important parts to configure
indra {
javaVersions {
target(17)
minimumToolchain(17)
}

// The license of your project, kyori has already functions for the most common licenses
// such as gpl3OnlyLicense() for GPLv3, apache2License() for Apache 2.0, etc.
// You can still specify your own license using the license { } builder function.
mitLicense()

if (metadata.repo.isNotBlank()) {
val repo = metadata.repo.split("/")
if (metadata.repository.isNotBlank()) {
val repo = metadata.repository.split("/")
github(repo[0], repo[1]) {
ci(true)
issues(true)
Expand All @@ -65,41 +58,25 @@ indra {
}
}

// Required for the GitHub actions
tasks.register("getArtifactPath") {
doLast { println(tasks.shadowJar.get().archiveFile.get().toString()) }
val generateResources by tasks.registering {
outputs.files(fileTree(temporaryDir))
doLast {
temporaryDir.resolve("plugin.json").writeText(ModMetadata.toJson(metadata))
}
}

tasks.shadowJar {
// Makes sure the name of the final jar is (plugin-name).jar
archiveFileName.set("${metadata.name}.jar")
// Set the classifier to "plugin" since it's the final artifact
archiveClassifier.set("plugin")
// Configure the dependencies shading.
// WARNING: SQL drivers do not play well with shading,
// the best solution would be to load them in an isolated classloader.
// If it's too difficult, you can disable relocation but be aware this can conflict with other plugins.
isEnableRelocation = true
relocationPrefix = "$rootPackage.shadow"
// Reduce shadow jar size by removing unused classes.
// Warning, if one of your dependencies use service loaders or reflection, add it to the exclude list
// such as "minimize { exclude(dependency("some.group:some-dependency:.*")) }"
from(generateResources)
from(rootProject.file("LICENSE.md")) { into("META-INF") }
minimize()
// Include the plugin.json file with the modified version
from(rootProject.file("plugin.json"))
// Include the license of your project
from(rootProject.file("LICENSE.md")) {
into("META-INF")
}
}

tasks.build {
// Make sure the shadow jar is built during the build task
dependsOn(tasks.shadowJar)
}

tasks.runMindustryClient {
// Little quirk of toxopid, it always includes the final jar in the mod list.
// But we are building a plugin, not a mod. So we need to clear the mod list.
mods.setFrom()
tasks.register("release") {
dependsOn(tasks.build)
project.copy {
from(tasks.shadowJar)
into(temporaryDir)
}
}
13 changes: 13 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[metadata]
version = "1.0"

[versions]
shadow = "8.1.1"
indra = "3.1.3"
toxopid = "4.0.0"

[plugins]
indra-common = { id = "net.kyori.indra", version.ref = "indra" }
indra-git = { id = "net.kyori.indra.git", version.ref = "indra" }
shadow = { id = "com.github.johnrengelman.shadow", version.ref = "shadow" }
toxopid = { id = "com.xpdustry.toxopid", version.ref = "toxopid" }
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down
1 change: 0 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// The project name, used as the name of the final artifact
rootProject.name = "template"
2 changes: 1 addition & 1 deletion src/main/java/com/xpdustry/template/TemplatePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* MIT License
*
* Copyright (c) 2023 Xpdustry
* Copyright (c) 2024 Xpdustry
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand Down

0 comments on commit b38bf7f

Please sign in to comment.