Skip to content

Commit

Permalink
Migrate to gradle (#1429)
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo Herrera <[email protected]>
  • Loading branch information
Pablete1234 authored Nov 18, 2024
1 parent 7397d46 commit a86687f
Show file tree
Hide file tree
Showing 31 changed files with 576 additions and 1,679 deletions.
15 changes: 7 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,18 @@ jobs:
with:
java-version: 21
distribution: temurin
cache: maven
- id: build
name: ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && 'Deploy JAR' || 'Build' }}
run: |
mvn --batch-mode ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') &&
'deploy' ||
'install' }}
# Configures gradle with caching
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
# Run "gradlew publish" for origin/dev and "gradlew build" for PRs or elsewhere
- name: Execute Gradle ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && 'Publish' || 'Build' }}
run: ./gradlew ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && 'publish' || 'build' }}
env:
GITHUB_TOKEN: ${{ (github.repository == 'PGMDev/PGM' && github.ref == 'refs/heads/dev') && secrets.GITHUB_TOKEN || '' }}
- id: artifact
name: Upload Jar
uses: actions/upload-artifact@v4
with:
name: PGM.jar
path: target/PGM.jar
path: build/libs/PGM.jar
if-no-files-found: error
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
target/
dependency-reduced-pom.xml

# Gradle generated files
build/
.gradle

# Mac OSX generated files
.DS_Store

Expand Down
15 changes: 15 additions & 0 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
plugins {
// Support convention plugins written in Kotlin. Convention plugins are build scripts in 'src/main' that automatically become available as plugins in the main build.
`kotlin-dsl`
}

repositories {
// Use the plugin portal to apply community plugins in convention plugins.
gradlePluginPortal()
}

dependencies {
implementation("com.gradleup.shadow:shadow-gradle-plugin:8.3.0")
implementation("com.diffplug.spotless:spotless-plugin-gradle:7.0.0.BETA4")
implementation("de.skuzzle.restrictimports:restrict-imports-gradle-plugin:2.6.0")
}
80 changes: 80 additions & 0 deletions buildSrc/src/main/kotlin/buildlogic.java-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
plugins {
`java-library`
id("com.diffplug.spotless")
id("de.skuzzle.restrictimports")
}

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

repositories {
mavenLocal()
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots/") // Snapshots
maven("https://repo.viaversion.com/") // Viaversion
maven("https://repo.pgm.fyi/snapshots") // Sportpaper & other pgm-specific stuff
maven("https://repo.dmulloy2.net/repository/public/") // ProtocolLib repo
maven("https://repo.papermc.io/repository/maven-public/") // Paper builds & paperweight plugin
}

dependencies {
api("org.jdom:jdom2:2.0.6.1")
api("net.kyori:adventure-api:4.17.0")
api("net.kyori:adventure-text-serializer-plain:4.17.0")
api("net.kyori:adventure-platform-bukkit:4.3.4")
api("org.incendo:cloud-core:2.0.0")
api("org.incendo:cloud-annotations:2.0.0")
api("org.incendo:cloud-paper:2.0.0-beta.10")
api("org.incendo:cloud-minecraft-extras:2.0.0-beta.10")
api("me.lucko:commodore:2.2")
api("fr.mrmicky:fastboard:2.1.3")
api("fr.minuskube.inv:smart-invs:1.2.7") { exclude("*") }
api("org.eclipse.jgit:org.eclipse.jgit:6.7.0.202309050840-r") { exclude("*") }
api("net.objecthunter:exp4j:0.4.9-pgm")
api("org.reflections:reflections:0.10.2")

// Optional plugin deps
compileOnly("com.comphenix.protocol:ProtocolLib:5.1.0")
compileOnly("com.viaversion:viaversion-api:5.0.0")

// Minecraft includes these (or equivalents)
compileOnly("it.unimi.dsi:fastutil:8.1.0")
compileOnly("com.google.guava:guava:17.0")
compileOnly("com.google.code.gson:gson:2.10.1")
compileOnly("commons-lang:commons-lang:2.6")
}

group = "tc.oc.pgm"
version = "0.16-SNAPSHOT"
description = "The original PvP Game Manager for Minecraft"

tasks {
withType<JavaCompile>() {
options.encoding = "UTF-8"
}
withType<Javadoc>() {
options.encoding = "UTF-8"
}
}

spotless {
ratchetFrom = "origin/dev"
java {
removeUnusedImports()
palantirJavaFormat("2.47.0").style("GOOGLE").formatJavadoc(true)
}
}

restrictImports {
group {
reason = "Use org.jetbrains.annotations to add annotations"
bannedImports = listOf("javax.annotation.**")
}
group {
reason = "Use tc.oc.pgm.util.Assert to add assertions"
bannedImports = listOf("com.google.common.base.Preconditions.**", "java.util.Objects.requireNonNull")
}
}
16 changes: 16 additions & 0 deletions buildSrc/src/main/kotlin/extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import org.gradle.api.Project
import java.io.ByteArrayOutputStream


fun Project.latestCommitHash(): String {
return runGitCommand(listOf("rev-parse", "--short", "HEAD"))
}

fun Project.runGitCommand(args: List<String>): String {
val byteOut = ByteArrayOutputStream()
exec {
commandLine = listOf("git") + args
standardOutput = byteOut
}
return byteOut.toString(Charsets.UTF_8.name()).trim()
}
95 changes: 95 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

plugins {
id("buildlogic.java-conventions")
`maven-publish`
id("com.gradleup.shadow")
}

dependencies {
compileOnly("dev.pgm.paper:paper-api:1.8_1.21.1-SNAPSHOT")

implementation(project(":util"))
runtimeOnly(project(":platform-sportpaper")) { exclude("*") }
runtimeOnly(project(":platform-modern")) { exclude("*") }
}


tasks.named<ShadowJar>("shadowJar") {
manifest {
attributes["paperweight-mappings-namespace"] = "mojang"
}
archiveFileName = "PGM.jar"
destinationDirectory = rootProject.projectDir.resolve("build/libs")

minimize {
// Exclude from minimization as they're required at runtime
exclude(project(":platform-sportpaper"))
exclude(project(":platform-modern"))
}

dependencies {
exclude(dependency("com.mojang:brigadier")) // Added by commodore
// Several compile-only annotation dependencies
exclude(dependency("org.jetbrains:annotations"))
exclude(dependency("org.checkerframework:checker-qual"))
exclude(dependency("org.apiguardian:apiguardian-api"))
}

fun pgmRelocate(basePckg: String) = relocate(basePckg, "tc.oc.pgm.lib.$basePckg")

pgmRelocate("org.incendo.cloud")
pgmRelocate("io.leangen.geantyref")
pgmRelocate("me.lucko.commodore")
pgmRelocate("fr.mrmicky")
pgmRelocate("org.jdom2")
pgmRelocate("org.eclipse.jgit")
pgmRelocate("org.slf4j")

exclude("META-INF/**")
exclude("**/*.html")
exclude("javax/**") // Unsure why this is even added

// Trim unused parts of javassist
exclude("javassist/bytecode/analysis/**")
exclude("javassist/bytecode/stackmap/**")
exclude("javassist/compiler/**")
}

publishing {
publications.create<MavenPublication>("pgm") {
groupId = rootProject.group as String
artifactId = project.name
version = rootProject.version as String

artifact(tasks["shadowJar"])
}
repositories {
maven {
name = "ghPackages"
url = uri("https://github.com/PGMDev/PGM")
credentials {
username = System.getenv("GITHUB_ACTOR")
password = System.getenv("GITHUB_TOKEN")
}
}
}
}

tasks {
processResources {
filesMatching(listOf("plugin.yml")) {
expand(
"name" to project.name,
"description" to project.description,
"mainClass" to "tc.oc.pgm.PGMPlugin",
"version" to project.version,
"commitHash" to project.latestCommitHash(),
"url" to "https://pgm.dev/")
}
}

named("build") {
dependsOn(shadowJar)
}
}
Loading

0 comments on commit a86687f

Please sign in to comment.