Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert to Gradle Kotlin DSL #4175

Draft
wants to merge 25 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8baf55c
Update gitignore in preparation for gradle conversion
md5sha256 Apr 22, 2024
954ebd8
Initial work converting to gradle kotlin dsl
md5sha256 Apr 22, 2024
cd1b846
Add run server
md5sha256 Apr 22, 2024
769e3a3
Update gh actions to build with gradle
md5sha256 Apr 22, 2024
ccbc341
Update more tasks to use gradle
md5sha256 Apr 22, 2024
6e57c35
Add gradle wrapper permission granting
md5sha256 Apr 22, 2024
6f66070
Rename actions and add grant permissions to the wrapper
md5sha256 Apr 22, 2024
705320b
chmod +x instead of chmod x
md5sha256 Apr 22, 2024
3f5c4b1
Replace project.version with version
md5sha256 Apr 22, 2024
7fe7a9c
Fix wrong path in publish-build action
md5sha256 Apr 22, 2024
a1fd6ca
Replace deprecated gradle build action with gradle setup action. Don'…
md5sha256 Apr 22, 2024
498de0f
Fix missing - in output jar name
md5sha256 Apr 22, 2024
5fa3807
Fix sonarcloud task to use gradle. Change publish-build to point to a…
md5sha256 Apr 22, 2024
2e13858
Fix pull request build incorrect artifact path
md5sha256 Apr 22, 2024
f47af06
Change the sed line
md5sha256 Apr 22, 2024
0066f4e
Refactor project setup to allow for dynamic version. Refactor the pul…
md5sha256 Apr 22, 2024
63a12fc
Move the CLI arguments around when building
md5sha256 Apr 22, 2024
703e4a7
Add back missing v in project version
md5sha256 Apr 22, 2024
78413a7
Fix bad path in the pull request-yml
md5sha256 Apr 22, 2024
15562b8
Fail if not artifacts are found
md5sha256 Apr 22, 2024
5729684
Don't do relative pathing
md5sha256 Apr 22, 2024
729d2c3
Fix build path. Fix name of source jar, explicitly declare the junit-…
md5sha256 Apr 22, 2024
dbbd032
Run E2E testing on java 17 for 1.16.5
md5sha256 Apr 22, 2024
419d340
Fix missing hyphen in the preview-builds unzip
md5sha256 Apr 22, 2024
b4e7969
Reformat lines
md5sha256 Apr 22, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/e2e-testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
include:
- mcVersion: '1.16.5'
javaVersion: '16'
javaVersion: '17'
- mcVersion: '1.17.1'
javaVersion: '17'
- mcVersion: '1.18.2'
Expand Down Expand Up @@ -74,4 +74,4 @@ jobs:

- name: Run server
run: |
java -jar paper.jar --nogui
java -DPaper.IgnoreJavaVersion=true -jar paper.jar --nogui
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ permissions:
jobs:
build:

name: Maven build
name: Gradle build
runs-on: ubuntu-latest

steps:
Expand All @@ -34,6 +34,16 @@ jobs:
java-version: '17'
java-package: jdk
architecture: x64
cache: gradle

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3

- name: Grant Wrapper Permission
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we do this locally once (and push) instead of doing it every time in every task we want to invoke gradle

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not entirely sure how the actions work so will need to figure out what you mean by that exactly

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

run: chmod +x gradlew

- name: Cache Maven packages
uses: actions/cache@v4
Expand All @@ -42,5 +52,5 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build with Maven
run: mvn package --file pom.xml
- name: Build With Gradle
run: ./gradlew build
16 changes: 13 additions & 3 deletions .github/workflows/javadocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ permissions:

jobs:
build:
name: Maven build
name: Gradle build
runs-on: ubuntu-latest

steps:
Expand All @@ -25,6 +25,7 @@ jobs:
java-version: '17'
java-package: jdk
architecture: x64
cache: gradle

- name: Cache Maven packages
uses: actions/cache@v4
Expand All @@ -33,5 +34,14 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Build Javadocs
run: mvn javadoc:javadoc
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3

- name: Grant Wrapper Permission
run: chmod +x gradlew

- name: Build With Gradle
run: ./gradlew javadoc
2 changes: 1 addition & 1 deletion .github/workflows/preview-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
run: |
unzip preview.zip
rm preview.zip
mv 'Slimefun vPreview Build #${{ env.PR_NUMBER }}-${{ env.COMMIT_HASH }}.jar' preview.jar
mv 'Slimefun-vPreview Build #${{ env.PR_NUMBER }}-${{ env.COMMIT_HASH }}.jar' preview.jar

- name: Upload to preview service
run: |
Expand Down
16 changes: 13 additions & 3 deletions .github/workflows/publish-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,25 @@ jobs:
java-version: '17'
java-package: jdk
architecture: x64
cache: gradle

- name: Build with Maven
run: mvn clean package
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3

- name: Grant Wrapper Permission
run: chmod +x gradlew

- name: Build with Gradle
run: ./gradlew build

- name: Upload to Blob Builds
uses: WalshyDev/blob-builds/gh-action@f3da5ce7b7e2b70eb963e0c0014677b3d78c10fa
with:
project: Slimefun4
releaseChannel: ${{ github.ref == 'refs/heads/master' && 'Dev' || 'RC' }}
apiToken: ${{ secrets.BLOB_BUILDS_API_TOKEN }}
file: './target/Slimefun v4.9-UNOFFICIAL.jar'
file: 'build/libs/Slimefun-v4.9-UNOFFICIAL.jar'
releaseNotes: ${{ github.event.head_commit.message }}
20 changes: 15 additions & 5 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:
paths:
- '.github/workflows/**'
- 'src/**'
- 'pom.xml'
- 'build.gradle.kts'

permissions:
contents: read
Expand All @@ -28,6 +28,7 @@ jobs:
java-version: '17'
java-package: jdk
architecture: x64
cache: gradle

- name: Cache Maven packages
uses: actions/cache@v4
Expand All @@ -44,16 +45,25 @@ jobs:
echo "SHORT_COMMIT_HASH=$SHORT_COMMIT_HASH" >> "$GITHUB_ENV"
echo "SHORT_COMMIT_HASH=$SHORT_COMMIT_HASH" >> "$GITHUB_OUTPUT"
echo "JAR_VERSION=$JAR_VERSION" >> "$GITHUB_ENV"
sed -i "s/<version>4.9-UNOFFICIAL<\/version>/<version>$JAR_VERSION<\/version>/g" pom.xml

- name: Build with Maven
run: mvn package
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3

- name: Grant Wrapper Permission
run: chmod +x gradlew

- name: Build Custom Version With Gradle
run: ./gradlew build -P"project.version"="${{ env.JAR_VERSION}}"

- name: Upload the artifact
uses: actions/upload-artifact@v4
with:
name: slimefun-${{ github.event.number }}-${{ env.SHORT_COMMIT_HASH }}
path: 'target/Slimefun v${{ env.JAR_VERSION }}.jar'
path: build/libs/Slimefun-v${{ env.JAR_VERSION }}.jar
if-no-files-found: error

call-workflows:
needs: [setup-preview-build]
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ jobs:
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Validate Gradle Wrapper
uses: gradle/actions/wrapper-validation@v3

- name: Grant Wrapper Permission
run: chmod +x gradlew

- name: SonarCloud analysis
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar
run: ./gradlew sonar
if: ${{ env.SONAR_TOKEN != 0 }}
31 changes: 30 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,33 @@ dependency-reduced-pom.xml
.project
*.iml
*.bak
.DS_Store
.DS_Store

# Ignore the run folder for run-server
/run

# Created by https://www.toptal.com/developers/gitignore/api/gradle
# Edit at https://www.toptal.com/developers/gitignore?templates=gradle

### Gradle ###
.gradle
**/build/
!src/**/build/

# Ignore Gradle GUI config
gradle-app.setting

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

# Avoid ignore Gradle wrappper properties
!gradle-wrapper.properties

# Cache of project
.gradletasknamecache

### Gradle Patch ###
# Java heap dump
*.hprof

# End of https://www.toptal.com/developers/gitignore/api/gradle
166 changes: 166 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
import org.gradle.jvm.tasks.Jar

plugins {
`java-library`
`maven-publish`
jacoco
id("com.github.johnrengelman.shadow") version "8.1.1"
id("org.sonarqube") version "5.0.0.4638"
id("xyz.jpenilla.run-paper") version "2.2.3"
}

// Needed for SonarScanner to work properly. 5.x requires java 17

val targetJavaVersion: Int = property("java.version").toString().toInt()
val encoding: String = property("project.encoding").toString()
val minecraftVersion: String = property("minecraft.version").toString()

repositories {
mavenCentral()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots")
maven("https://repo.papermc.io/repository/maven-public/")
maven("https://jitpack.io")
maven("https://maven.enginehub.org/repo/")
maven("https://repo.extendedclip.com/content/repositories/placeholderapi")
maven("https://nexus.neetgames.com/repository/maven-public")
maven("https://repo.walshy.dev/public")
maven("https://repo.codemc.io/repository/maven-public/")
maven("https://libraries.minecraft.net")
}

dependencies {
// Api is similar to "implementation" but that these deps are also exposed transitively
api("com.github.baked-libs.dough:dough-api:baf2d79f62")
api("io.papermc:paperlib:1.0.8")
api("commons-lang:commons-lang:2.6")

compileOnly("org.spigotmc:spigot-api:$minecraftVersion-R0.1-SNAPSHOT")
compileOnly("com.mojang:authlib:6.0.52")
compileOnly("com.google.code.findbugs:jsr305:3.0.2")

// Plugin dependencies
compileOnly("com.sk89q.worldedit:worldedit-core:7.2.19")
compileOnly("com.sk89q.worldedit:worldedit-bukkit:7.2.19")
compileOnly("com.gmail.nossr50.mcMMO:mcMMO:2.1.230")
compileOnly("me.clip:placeholderapi:2.11.5")
compileOnly("me.minebuilders:clearlag-core:3.1.6")
compileOnly("com.github.LoneDev6:itemsadder-api:3.6.1")
compileOnly("net.imprex:orebfuscator-api:5.4.0")


testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation("org.junit.jupiter:junit-jupiter:5.10.2")
testImplementation("org.mockito:mockito-core:5.10.0")
testImplementation("org.slf4j:slf4j-simple:2.0.9")
testImplementation("com.github.seeseemelk:MockBukkit-v1.20:3.65.0")

// Override MockBukkit's Paper to a pinned slightly older version
// This is because MockBukkit currently fails after this PR: https://github.com/PaperMC/Paper/pull/9629
testImplementation("io.papermc.paper:paper-api:1.20.4-R0.1-20240205.114523-90")
}

group = "com.github.slimefun"
version = property("project.version").toString()
description = "Slimefun"


java {
toolchain.languageVersion.set(JavaLanguageVersion.of(targetJavaVersion))
withSourcesJar()
}

tasks {
withType<JavaCompile>().configureEach {
options.release = targetJavaVersion
options.encoding = encoding

// package info files are only important for Javadocs
// We can safely exclude them from the final jar -->
exclude("**/package-info.java")
}
withType<Javadoc>().configureEach {
options.encoding = encoding
}
javadoc {
setDestinationDir(file("javadocs"))
options {
title = "Slimefun4 - Javadocs"
windowTitle = "Slimefun4 - Javadocs"
// doclet = "org.gradle.external.javadoc.StandardJavadocDocletOptions"
// FIXME offline links, groups, and additional options.
}
}
assemble {
dependsOn(shadowJar)
}
jar {
archiveClassifier.set("original")
archiveVersion.set("v${project.version}")
}
shadowJar {
archiveClassifier.set("")
archiveVersion.set("v${project.version}")

// Relocations
val destination = "io.github.thebusybiscuit.slimefun4.libraries"
relocate("io.github.bakedlibs.dough", "$destination.dough")
relocate("io.papermc.lib", "$destination.paperlib")
relocate("org.apache.commons.lang", "$destination.commons.lang")
// Merge the META-INF files
mergeServiceFiles()
}
processResources {

md5sha256 marked this conversation as resolved.
Show resolved Hide resolved
include("plugin.yml")
include("config.yml")
include("item-models.yml")
include("wiki.json")
include("languages/translators.json")
include("tags/*.json")
include("biome-maps/*.json")
include("languages/**/*.yml")
Comment on lines +114 to +121
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this really needed? AFAIK all resources are automatically included

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, I'd have thought so too but I wonder why it was explicitly declared in the pom so I honored that explicit declaration. Can remove if there are no other reasons for it being explicitly declared.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can confirm all stuff is automatically included without that code

filesMatching("plugin.yml") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be replaced with the plugin-yml gradle plugin, tho idk how much others will want it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, haven't gotten to that part yet so I left it as we used to with maven resource filtering.

expand("version" to project.version)
}
}
test {
useJUnitPlatform()
}
runServer {
// Configure the Minecraft version for our task.
// This is the only required configuration besides applying the plugin.
// Your plugin's jar (or shadowJar if present) will be used automatically.
minecraftVersion(minecraftVersion)

downloadPlugins {
// WorldEdit 7.2.19
url("https://mediafilez.forgecdn.net/files/5077/477/worldedit-bukkit-7.2.19.jar")
}
}
named<Jar>("sourcesJar") {
archiveVersion.set("v${project.version}")
}
}

publishing {
publications.create<MavenPublication>("maven") {
from(components["java"])
pom {
scm {
inceptionYear = "2013"
packaging = "jar"
issueManagement {
system = "GitHub Issues"
url = "https://github.com/Slimefun/Slimefun4/issues"
}
licenses {
license {
name = "GNU General Public License v3.0"
url = "https://github.com/Slimefun/Slimefun4/blob/master/LICENSE"
distribution = "repo"
}
}
}
}
}
}
Loading