Skip to content

Commit

Permalink
Migrate to Gradle
Browse files Browse the repository at this point in the history
Signed-off-by: BT (calcastor/mame) <[email protected]>
  • Loading branch information
calcastor committed Dec 29, 2024
1 parent 7624b3a commit 679e045
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 237 deletions.
20 changes: 12 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
name: Events CI
on:
pull_request:
branches: ['*']
workflow_dispatch:
push:
branches: ['*']
branches:
- master
jobs:
build:
runs-on: ubuntu-latest
Expand All @@ -16,11 +17,14 @@ jobs:
with:
java-version: 21
distribution: temurin
cache: maven
- name: Build jar
run: mvn --batch-mode --update-snapshots verify
- name: Move generated jar file
run: mv target/Events*.jar Events.jar
# 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 || '' }}
- name: Create Release
id: create_release
if: github.event_name != 'pull_request' && (github.ref == 'refs/heads/master')
Expand All @@ -40,6 +44,6 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./Events.jar
asset_path: ./build/libs/Events.jar
asset_name: Events.jar
asset_content_type: application/java-archive
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.

53 changes: 53 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
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"
destinationDirectory = rootProject.projectDir.resolve("build/libs")

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"])
}
}

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")
}
61 changes: 61 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,61 @@
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 {
implementation("org.incendo:cloud-annotations:2.0.0")
implementation("org.jetbrains:annotations:22.0.0")

compileOnly("net.md-5:bungeecord-chat:1.20-R0.2-deprecated+build.18")
compileOnly("dev.pgm.paper:paper-api:1.8_1.21.1-SNAPSHOT")
compileOnly("tc.oc.pgm:core:0.16-SNAPSHOT")
}

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 679e045

Please sign in to comment.