Skip to content

Commit

Permalink
[CORE] Gradle Migration - Better Build System when building against P…
Browse files Browse the repository at this point in the history
…aper

Signed-off-by: Wolfieheart <[email protected]>
  • Loading branch information
Wolfieheart committed Jan 4, 2025
1 parent 1293d28 commit 52eb086
Show file tree
Hide file tree
Showing 10 changed files with 475 additions and 137 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: Java CI with Maven
name: Java CI with Gradle
on: [push, pull_request]

jobs:
Expand All @@ -25,40 +22,33 @@ jobs:
java-version: ${{ matrix.java }}
distribution: 'zulu'

# 3. Setup local Maven package cache to speed up building
- name: Cache SonarCloud packages
uses: actions/cache@v3
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar

- name: Cache Maven packages
# 3. Setup local Gradle cache to speed up building
- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: ~/.m2
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
# 4. Build via Maven
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: ${{ runner.os }}-gradle

# 4. Build and analyze
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: mvn -B verify org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -Dsonar.projectKey=wolfieheart_ArmorStandEditor
run: ./gradlew build sonarqube -Dsonar.projectKey=wolfieheart_ArmorStandEditor

#5: Create a Clean Package - and Verify it
- name: Clean package
run: mvn -B clean package
# 5. Create a Clean Package - and Verify it
- name: Clean and build
run: ./gradlew clean build

- name: Clean Verify
run: mvn -B clean verify
- name: Verify build
run: ./gradlew clean test

#6 Upload Artifacts (Debug Purposes)
# 6. Upload Artifacts (Debug Purposes)
- name: Upload Artifact for Debugging
uses: actions/[email protected]
if: success() && matrix.java == '21'
with:
name: artifact
path: /home/runner/work/ArmorStandEditor/ArmorStandEditor/target/armorstandeditor-*-*.jar
path: build/libs/armorstandeditor-*-*.jar
if-no-files-found: error
25 changes: 20 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
# IntelliJ IDEA
.idea/
target/
*.iml

# Build directories
/bin/
/.project
/.classpath
/.settings/
/build/

# Eclipse IDE
.project
.classpath
.settings/

# Java specific metadata
/src/main/java/META-INF/*.MF
/src/main/java/META-INF/

# Project-specific files
/TODO-LIST.MD
/dependency-reduced-pom.xml

# Gradle
.gradle/
!gradle/wrapper/gradle-wrapper.jar

# Gradle Wrapper
.gradle-wrapper/
70 changes: 70 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
plugins {
id 'java'
id 'maven-publish'
}

group = 'io.github.rypofalem.armorstandeditor'
version = '0.x-Rewrite'

def javaVersion = 21

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

tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}

repositories {
mavenCentral()
maven {
url = 'https://repo.papermc.io/repository/maven-public/'
}
maven {
url = 'https://s01.oss.sonatype.org/content/repositories/snapshots/'
}
}

dependencies {
compileOnly 'io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT'
compileOnly 'org.projectlombok:lombok:1.18.34'

testImplementation 'org.mockito:mockito-core:5.5.0'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.10.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
}

tasks.jar {
manifest {
attributes(
'Implementation-Title': 'armorstandeditor',
'Implementation-Version': version
)
}
}

tasks.register('attachArtifact') {
doLast {
println "Attach optional artifact if needed."
// Gradle doesn't natively support attaching optional artifacts like Maven. Additional logic might be added here.
}
}

testing {
suites {
test(JvmTestSuite) {
useJUnitJupiter()
}
}
}

publishing {
publications {
mavenJava(MavenPublication) {
from components.java
}
}
}
16 changes: 16 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file was generated by the Gradle 'init' task.
# https://docs.gradle.org/current/userguide/platforms.html#sub::toml-dependencies-format

[versions]
io-papermc-paper-paper-api = "1.21.4-R0.1-SNAPSHOT"
org-junit-jupiter-junit-jupiter-api = "5.10.0"
org-junit-jupiter-junit-jupiter-engine = "5.10.0"
org-mockito-mockito-core = "5.5.0"
org-projectlombok-lombok = "1.18.34"

[libraries]
io-papermc-paper-paper-api = { module = "io.papermc.paper:paper-api", version.ref = "io-papermc-paper-paper-api" }
org-junit-jupiter-junit-jupiter-api = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "org-junit-jupiter-junit-jupiter-api" }
org-junit-jupiter-junit-jupiter-engine = { module = "org.junit.jupiter:junit-jupiter-engine", version.ref = "org-junit-jupiter-junit-jupiter-engine" }
org-mockito-mockito-core = { module = "org.mockito:mockito-core", version.ref = "org-mockito-mockito-core" }
org-projectlombok-lombok = { module = "org.projectlombok:lombok", version.ref = "org-projectlombok-lombok" }
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.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 52eb086

Please sign in to comment.