Skip to content

Commit

Permalink
Convert to Gradle.
Browse files Browse the repository at this point in the history
This commit converts the project from Maven to Gradle by removing the
old Maven-related files such as `pom.xml` and the Maven Wrapper, and
replacing them with their Gradle counterparts (more or less).

Comparing the artifacts from Maven and Gradle indicates no significant
differences in the resulting jar-files, and a quick test of the plugin
shows that things are still working as expected.

Bits of `build.gradle.kts` may need a bit of a tune-up later down the
road, e.g. the test sources "hack" put in place. It may be cleaner to
omit this hack and just suck up having to repeat dependencies, but in
that case, it might be better to embrace the "libs" file instead of
having to repeat dependencies in full.

Note that this commit changes the caching mechanism used in the GitHub
Actions build workflow, opting for the one built into `setup-java`.
  • Loading branch information
garbagemule committed Dec 9, 2023
1 parent 511d16f commit f57f10e
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 763 deletions.
12 changes: 3 additions & 9 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@ jobs:
with:
java-version: '11'
distribution: 'adopt'

- name: 'Cache dependencies'
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
cache: 'gradle'

- name: 'Build, test, and package'
run: mvn -B package --file pom.xml
run: ./gradlew build --no-daemon

- name: 'Upload artifact'
uses: actions/upload-artifact@v3
with:
name: MobArena.jar
path: target/MobArena.jar
path: build/libs/MobArena.jar
9 changes: 3 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Java
*.class

# Maven
target/

# Artifacts
*.jar
*.zip
# Gradle
.gradle/
build/

# IntelliJ
.idea/
Expand Down
117 changes: 0 additions & 117 deletions .mvn/wrapper/MavenWrapperDownloader.java

This file was deleted.

Binary file removed .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
2 changes: 0 additions & 2 deletions .mvn/wrapper/maven-wrapper.properties

This file was deleted.

69 changes: 69 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
plugins {
id("java-library")
id("com.github.johnrengelman.shadow") version "8.1.1"
}

group = "com.garbagemule"
version = "0.107.1-SNAPSHOT"

repositories {
mavenLocal()
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/")
maven("https://jitpack.io")
maven("https://repo.maven.apache.org/maven2/")
}

dependencies {
compileOnly("org.spigotmc:spigot-api:1.19-R0.1-SNAPSHOT")
compileOnly("com.github.MilkBowl:VaultAPI:1.7.1")
api("org.bstats:bstats-bukkit:2.2.1")

testImplementation("junit:junit:4.13.2")
testImplementation("org.hamcrest:hamcrest-all:1.3")
testImplementation("org.mockito:mockito-core:3.12.4")
}

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

sourceSets {
test {
// This is a bit of a hack. It ensures that the dependencies for the
// "main" source set are available to the test suite. Without it, the
// dependencies would have to be listed twice, and even that doesn't
// seem to work with the currently used version of Mockito.
configurations.testImplementation.configure {
extendsFrom(configurations.compileOnly.get())
}
}
}

tasks {
processResources {
filesMatching("plugin.yml") {
expand("project" to mapOf(
"name" to "MobArena",
"version" to version,
))
}
}

shadowJar {
minimize()

relocate("org.bstats", "com.garbagemule.MobArena.metrics")

archiveBaseName = "MobArena"
archiveClassifier = ""
archiveVersion = ""
}

// We're using shadowJar, so we can skip the regular jar task.
jar { enabled = false }

// Let the build task produce the final artifact.
build { dependsOn(shadowJar) }
}
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit f57f10e

Please sign in to comment.