Skip to content

Commit

Permalink
Migrate to Gradle (#36)
Browse files Browse the repository at this point in the history
Signed-off-by: BT (calcastor/mame) <[email protected]>
  • Loading branch information
calcastor authored Jan 7, 2025
1 parent 7624b3a commit f9691d0
Show file tree
Hide file tree
Showing 16 changed files with 477 additions and 274 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Build
on:
pull_request:
workflow_dispatch:
push:
branches:
- master
jobs:
build:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:
- id: checkout
name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- id: setup-java
name: Setup Java
uses: actions/setup-java@v4
with:
java-version: 21
distribution: temurin
# Configures gradle with caching
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4
# Run "gradlew publish" for origin/master and "gradlew build" for PRs or elsewhere
- name: Execute Gradle ${{ (github.repository == 'PGMDev/Events' && github.ref == 'refs/heads/master') && 'Publish' || 'Build' }}
run: ./gradlew ${{ (github.repository == 'PGMDev/Events' && github.ref == 'refs/heads/master') && 'publish' || 'build' }}
env:
GITHUB_TOKEN: ${{ (github.repository == 'PGMDev/Events' && github.ref == 'refs/heads/master') && secrets.GITHUB_TOKEN || '' }}
- id: artifact
name: Upload Jar
uses: actions/upload-artifact@v4
with:
name: Events.jar
path: build/libs/Events.jar
if-no-files-found: error
45 changes: 0 additions & 45 deletions .github/workflows/ci.yml

This file was deleted.

4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
*.class

# Package Files #
*.jar
*.war
*.ear

Expand Down Expand Up @@ -95,3 +94,6 @@ application.linux64
application.windows32
application.windows64
application.macosx

# Gradle
build/
14 changes: 0 additions & 14 deletions .pre-commit-config.yaml

This file was deleted.

63 changes: 63 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
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 = "Events.jar"
archiveClassifier.set("")

minimize()

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

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

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

artifact(tasks["shadowJar"])
}
repositories {
maven {
name = "ghPackages"
url = uri("https://maven.pkg.github.com/PGMDev/Events")
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.events.EventsPlugin",
"version" to project.version,
"commitHash" to project.latestCommitHash(),
"url" to "https://pgm.dev/"
)
}
}

named("jar") {
enabled = false
}

named("build") {
dependsOn(shadowJar)
}
}
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")
}
60 changes: 60 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,60 @@
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.pgm.fyi/snapshots/") // PGM-specific depdencies
maven("https://repo.papermc.io/repository/maven-public/") // Needed for bungeecord-chat
}

dependencies {
compileOnly("dev.pgm.paper:paper-api:1.8_1.21.1-SNAPSHOT")
compileOnly("tc.oc.pgm:core:0.16-SNAPSHOT")
compileOnly("net.md-5:bungeecord-chat:1.20-R0.2-deprecated+build.18")
compileOnly("org.incendo:cloud-annotations:2.0.0")
compileOnly("org.jetbrains:annotations:22.0.0")
}

group = "dev.pgm"
version = "1.0.0-SNAPSHOT"
description = "Manage PvP tournament events"

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

spotless {
ratchetFrom = "origin/master"
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()
}
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.10-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit f9691d0

Please sign in to comment.