Skip to content

Commit

Permalink
Switch to gradle
Browse files Browse the repository at this point in the history
Signed-off-by: Christopher White <18whitechristop@gmail.com>
  • Loading branch information
cswhite2000 authored and calcastor committed Dec 29, 2024
1 parent b632f4f commit 45e9545
Show file tree
Hide file tree
Showing 16 changed files with 476 additions and 459 deletions.
16 changes: 11 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
name: build
name: Build
on:
pull_request:
workflow_dispatch:
push:
branches:
- dev
Expand All @@ -17,13 +18,18 @@ jobs:
with:
java-version: 21
distribution: temurin
cache: maven
- name: build
run: mvn 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/Community' && github.ref == 'refs/heads/dev') && 'Publish' || 'Build' }}
run: ./gradlew ${{ (github.repository == 'PGMDev/Community' && github.ref == 'refs/heads/dev') && 'publish' || 'build' }}
env:
GITHUB_TOKEN: ${{ (github.repository == 'PGMDev/Community' && github.ref == 'refs/heads/dev') && secrets.GITHUB_TOKEN || '' }}
- name: artifact
uses: actions/upload-artifact@v4
with:
name: Community.jar
path: target/Community.jar
path: build/libs/Community.jar
if-no-files-found: error

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ bin/
*.class
*.log
*.ctxt
*.jar
*.war
*.nar
*.ear
Expand All @@ -29,3 +28,6 @@ hs_err_pid*
.classpath
.project
.settings
build
.gradle
.DS_Store
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")
}
69 changes: 69 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,69 @@
plugins {
`java-library`
id("com.diffplug.spotless")
id("de.skuzzle.restrictimports")
}

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

repositories {
mavenLocal()
mavenCentral()
maven("https://repo.pgm.fyi/snapshots") // Sportpaper & other pgm-specific stuff
maven("https://hub.spigotmc.org/nexus/content/repositories/snapshots/") // Spigot repo
maven("https://repo.aikar.co/content/groups/aikar/") // aikar repo
}

dependencies {
implementation("tc.oc.pgm:util:0.16-SNAPSHOT") { isTransitive = false }
implementation("com.zaxxer:HikariCP:2.4.1") { isTransitive = false }
implementation("fr.minuskube.inv:smart-invs:1.2.7") { isTransitive = false }

implementation("redis.clients:jedis:3.5.1")
implementation("co.aikar:idb-core:1.0.0-SNAPSHOT")
implementation("co.aikar:idb-bukkit:1.0.0-SNAPSHOT")
implementation("net.kyori:adventure-api:4.17.0")
implementation("net.kyori:adventure-text-serializer-plain:4.17.0")
implementation("net.kyori:adventure-platform-bukkit:4.3.4")

compileOnly("app.ashcon:sportpaper:1.8.8-R0.1-SNAPSHOT")
compileOnly("tc.oc.pgm:core:0.16-SNAPSHOT")
compileOnly("tc.oc.occ:AFK:1.0.0-SNAPSHOT")
compileOnly("tc.oc.occ:Environment:1.0.0-SNAPSHOT")
}

group = "dev.pgm"
version = "0.2-SNAPSHOT"
description = "A plugin for managing a Minecraft community"

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()
}
60 changes: 60 additions & 0 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar

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

tasks.named<ShadowJar>("shadowJar") {
archiveFileName = "Community.jar"
archiveClassifier.set("")
destinationDirectory = rootProject.projectDir.resolve("build/libs")

minimize()

dependencies {
exclude(dependency("org.jetbrains:annotations"))
}

exclude("META-INF/**")
}

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

artifact(tasks["shadowJar"])
}
repositories {
maven {
name = "pgm-repo-snapshots"
url = uri("https://repo.pgm.fyi/snapshots")
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 "dev.pgm.community.Community",
"version" to project.version,
"commitHash" to project.latestCommitHash(),
"author" to "applenick",
"url" to "https://pgm.dev/")
}
}

named("build") {
dependsOn(shadowJar)
}
}
171 changes: 0 additions & 171 deletions core/pom.xml

This file was deleted.

Loading

0 comments on commit 45e9545

Please sign in to comment.