From 7268cf91d37063864c42eb478aec360b18c63e30 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 21 Feb 2023 11:37:16 +0800 Subject: [PATCH 1/7] Revamp build with gradle --- .gitignore | 4 + build.gradle | 166 ++++++++++++ config/mv_checks.xml | 12 +- gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 61574 bytes gradle/wrapper/gradle-wrapper.properties | 6 + gradlew | 244 ++++++++++++++++++ gradlew.bat | 92 +++++++ pom.xml | 310 ----------------------- settings.gradle | 5 + 9 files changed, 522 insertions(+), 317 deletions(-) create mode 100644 build.gradle create mode 100644 gradle/wrapper/gradle-wrapper.jar create mode 100644 gradle/wrapper/gradle-wrapper.properties create mode 100644 gradlew create mode 100644 gradlew.bat delete mode 100644 pom.xml create mode 100644 settings.gradle diff --git a/.gitignore b/.gitignore index 496ae576..dbb9e219 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,7 @@ debug.log # Doxygen /docs/html debug.txt + +# Gradle +.gradle + diff --git a/build.gradle b/build.gradle new file mode 100644 index 00000000..012fa2a8 --- /dev/null +++ b/build.gradle @@ -0,0 +1,166 @@ +plugins { + id 'java-library' + id 'maven-publish' + id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '7.1.2' +} + +version = System.getenv('GITHUB_VERSION') ?: 'local' +group = 'com.onarandombox.multiverseinventories' +description = 'multiverse-inventories' + +java.sourceCompatibility = JavaVersion.VERSION_11 + +repositories { + mavenLocal() + + maven { + name = 'onarandombox' + url = uri('https://repo.onarandombox.com/content/groups/public') + } + + maven { + name ='papermc' + url = uri('https://papermc.io/repo/repository/maven-public/') + } + + maven { + name = 'jitpack.io' + url = uri('https://jitpack.io/') + } +} + +dependencies { + // Spigot + implementation('org.bukkit:bukkit:1.14.4-R0.1-SNAPSHOT') { + exclude group: 'junit', module: 'junit' + } + + // Core + implementation('com.onarandombox.multiversecore:Multiverse-Core:4.2.2') { + exclude(group: 'me.main__.util', module: 'SerializationConfig') + } + + // Config + api 'com.dumptruckman.minecraft:JsonConfiguration:1.1' + api 'com.googlecode.json-simple:json-simple:1.1.1' + + // Utils + api 'io.papermc:paperlib:1.0.7' + api('com.dumptruckman.minecraft:Logging:1.1.1') { + exclude group: 'junit', module: 'junit' + } + + // Other plugins for import + implementation('uk.co:MultiInv:3.0.6') { + exclude group: '*', module: '*' + } + implementation('me.drayshak:WorldInventories:1.0.2') { + exclude group: '*', module: '*' + } + + // Legacy Multiverse-Adventure + implementation('com.onarandombox.multiverseadventure:Multiverse-Adventure:2.5.0-SNAPSHOT') { + exclude group: '*', module: '*' + } + + // Tests + testImplementation 'com.github.MilkBowl:VaultAPI:1.7.1' + testImplementation 'junit:junit:4.13.2' + testImplementation 'org.mockito:mockito-core:3.11.2' +} + + +java { + withSourcesJar() + withJavadocJar() +} + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' +} + +tasks.withType(Javadoc).configureEach { + options.encoding = 'UTF-8' +} + + +configurations { + [apiElements, runtimeElements].each { + it.outgoing.artifacts.removeIf { it.buildDependencies.getDependencies(null).contains(jar) } + it.outgoing.artifact(shadowJar) + } +} + +publishing { + publications { + maven(MavenPublication) { + from components.java + } + } + repositories { + maven { + name = "GitHubPackages" + url = "https://maven.pkg.github.com/Multiverse/Multiverse-Inventories" + credentials { + username = System.getenv("GITHUB_ACTOR") + password = System.getenv("GITHUB_TOKEN") + } + } + } +} + + +task prepareSource(type: Sync) { + from sourceSets.main.java + into "$buildDir/src" +} + + +compileJava { + source = prepareSource.outputs +} + +processResources { + def props = [version: "${project.version}"] + inputs.properties props + filteringCharset 'UTF-8' + filesMatching('plugin.yml') { + expand props + } + + // This task should never be skipped. The tests depend on this having been run but we want the new version number + // that is created after tests are run and before we run again to publish. + outputs.upToDateWhen { false } +} + + +checkstyle { + toolVersion = '6.1.1' + configFile file('config/mv_checks.xml') + ignoreFailures = true +} + + +javadoc { + source = sourceSets.main.allJava + classpath = configurations.compileClasspath +} + + +project.configurations.api.canBeResolved = true + +shadowJar { + relocate 'com.dumptruckman.minecraft.util.Logging', 'com.onarandombox.multiverseinventories.utils.InvLogging' + relocate 'com.dumptruckman.minecraft.util.DebugLog', 'com.onarandombox.multiverseinventories.utils.DebugFileLogger' + relocate 'com.dumptruckman.bukkit.configuration', 'com.onarandombox.multiverseinventories.utils.configuration' + relocate 'io.papermc.lib', 'com.onarandombox.multiverseinventories.utils.paperlib' + relocate 'net.minidev.json', 'com.onarandombox.multiverseinventories.utils.json' + + configurations = [project.configurations.api] + + archiveFileName = "$baseName-$version.$extension" +} + +build.dependsOn shadowJar +jar.enabled = false diff --git a/config/mv_checks.xml b/config/mv_checks.xml index 53db89cd..81bb6b51 100644 --- a/config/mv_checks.xml +++ b/config/mv_checks.xml @@ -13,9 +13,7 @@ - - - + @@ -78,7 +76,10 @@ - + + + + @@ -103,7 +104,6 @@ - @@ -115,7 +115,6 @@ - - - - jenkins - - - env.BUILD_NUMBER - - - - ${env.BUILD_NUMBER} - - - - - - clean package - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.7.0 - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-jar-plugin - 3.0.2 - - - - - - - - - com.google.code.maven-replacer-plugin - maven-replacer-plugin - 1.3.8 - - - prepare-package - - replace - - - - - target/classes/plugin.yml - - - maven-version-number - ${project.version}-b${project.build.number} - - - - - - org.apache.maven.plugins - maven-source-plugin - 3.0.1 - - - attach-sources - package - - jar-no-fork - - - - - - maven-javadoc-plugin - 2.10.4 - - - https://papermc.io/javadocs/paper/1.14/ - - -J-Dhttp.agent=placeholder - - - - javadoc-jar - verify - - jar - - - - - - org.apache.maven.plugins - maven-surefire-plugin - 3.0.0-M3 - - - **/TestInstanceCreator.java - - - - - org.apache.maven.surefire - surefire-junit47 - 3.0.0-M3 - - - - - org.apache.maven.plugins - maven-checkstyle-plugin - 2.8 - - true - ${project.basedir}/config/mv_checks.xml - - - - org.apache.maven.plugins - maven-shade-plugin - 3.1.1 - - - package - - shade - - - - - com.dumptruckman.minecraft.util.Logging - com.onarandombox.multiverseinventories.utils.InvLogging - - - com.dumptruckman.minecraft.util.DebugLog - com.onarandombox.multiverseinventories.utils.DebugFileLogger - - - com.dumptruckman.bukkit.configuration - com.onarandombox.multiverseinventories.utils.configuration - - - net.minidev.json - com.onarandombox.multiverseinventories.utils.json - - - io.papermc.lib - com.onarandombox.multiverseinventories.utils.paperlib - - - - - - - - - - - org.bukkit - bukkit - 1.14.4-R0.1-SNAPSHOT - provided - - - com.onarandombox.multiversecore - Multiverse-Core - 4.2.2 - provided - - - me.main__.util - SerializationConfig - - - - - com.dumptruckman.minecraft - Logging - 1.1.1 - - - org.bukkit - craftbukkit - - - - - io.papermc - paperlib - 1.0.7 - compile - - - com.onarandombox.multiverseadventure - Multiverse-Adventure - 2.5.0-SNAPSHOT - provided - - - * - * - - - - - uk.co - MultiInv - 3.0.6 - provided - - - * - * - - - - - me.drayshak - WorldInventories - 1.0.2 - provided - - - com.dumptruckman.minecraft - JsonConfiguration - 1.1 - compile - - - com.googlecode.json-simple - json-simple - 1.1.1 - - - - - com.github.MilkBowl - VaultAPI - 1.7 - test - - - junit - junit - 4.12 - test - - - org.mockito - mockito-core - 3.11.2 - test - - - - - - OnARandomBox - https://repo.onarandombox.com/content/repositories/multiverse - - - OnARandomBox - https://repo.onarandombox.com/content/repositories/multiverse-snapshots/ - - - diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 00000000..62b418fb --- /dev/null +++ b/settings.gradle @@ -0,0 +1,5 @@ +/* + * This file was generated by the Gradle 'init' task. + */ + +rootProject.name = 'multiverse-inventories' From b0075fad7d27f01681cdb82d55954bb20f117498 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 21 Feb 2023 11:48:09 +0800 Subject: [PATCH 2/7] Implement new github action release --- .github/workflows/build.yml | 22 ------------ .github/workflows/release.yml | 54 +++++++++++++++++++++++++++++ .github/workflows/require_label.yml | 18 ++++++++++ .github/workflows/test.yml | 29 ++++++++++++++++ gradlew | 0 5 files changed, 101 insertions(+), 22 deletions(-) delete mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/require_label.yml create mode 100644 .github/workflows/test.yml mode change 100644 => 100755 gradlew diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 983d12cc..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: Maven CI/CD - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build_and_test: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - name: Set up JDK 8 - uses: actions/setup-java@v1 - with: - java-version: 1.8 - - - name: Build with Maven - run: mvn -B package --file pom.xml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..70ad0a72 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,54 @@ +name: Create Release Version & Publish Package + +on: + push: + branches: [main] + +jobs: + release_on_push: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + cache: gradle + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + + - name: Test & Build + uses: gradle/gradle-build-action@v2 + with: + arguments: clean build -x assemble -x shadowJar + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Create release + id: release + uses: rymndhng/release-on-push-action@v0.27.0 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + bump_version_scheme: norelease + tag_prefix: '' + release_name: "Release " + use_github_release_notes: true + + - name: Publish package + uses: gradle/gradle-build-action@v2 + with: + arguments: publish + env: + GITHUB_VERSION: ${{ steps.release.outputs.tag_name }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - name: Upload release artifact + uses: svenstaro/upload-release-action@v2 + with: + repo_token: ${{ secrets.GITHUB_TOKEN }} + file: build/libs/multiverse-inventories-${{ steps.release.outputs.tag_name }}.jar + asset_name: multiverse-inventories-${{ steps.release.outputs.tag_name }}.jar + tag: ${{ steps.release.outputs.tag_name }} diff --git a/.github/workflows/require_label.yml b/.github/workflows/require_label.yml new file mode 100644 index 00000000..e4f9c293 --- /dev/null +++ b/.github/workflows/require_label.yml @@ -0,0 +1,18 @@ +name: Require PR Labels + +on: + pull_request: + types: [opened, labeled, unlabeled, synchronize] + branches: [main] + +jobs: + require_label: + runs-on: ubuntu-latest + steps: + - uses: mheap/github-action-required-labels@v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + mode: exactly + count: 1 + labels: "release:major, release:minor, release:patch, no release" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 00000000..fe2e3b1d --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,29 @@ +name: Run unit tests against all PRs + +on: + pull_request: + types: [opened, synchronize] + +jobs: + test: + runs-on: ubuntu-latest + permissions: + contents: read + steps: + - uses: actions/checkout@v3 + + - uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'adopt' + cache: gradle + + - name: Validate Gradle wrapper + uses: gradle/wrapper-validation-action@v1 + + - name: Run unit tests + uses: gradle/gradle-build-action@v2 + with: + arguments: build + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 From 749ba7d91d4d27e50509083ef73b967fdb2bffdb Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 21 Feb 2023 11:53:04 +0800 Subject: [PATCH 3/7] Exclude junit for json-simple --- build.gradle | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/build.gradle b/build.gradle index 012fa2a8..7e83903f 100644 --- a/build.gradle +++ b/build.gradle @@ -38,12 +38,14 @@ dependencies { // Core implementation('com.onarandombox.multiversecore:Multiverse-Core:4.2.2') { - exclude(group: 'me.main__.util', module: 'SerializationConfig') + exclude group: 'me.main__.util', module: 'SerializationConfig' } // Config api 'com.dumptruckman.minecraft:JsonConfiguration:1.1' - api 'com.googlecode.json-simple:json-simple:1.1.1' + api ('com.googlecode.json-simple:json-simple:1.1.1') { + exclude group: 'junit', module: 'junit' + } // Utils api 'io.papermc:paperlib:1.0.7' From 95f40d573d829e32a3a3ca43f51df247301e84bc Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 21 Feb 2023 12:34:44 +0800 Subject: [PATCH 4/7] Make description camelcase --- build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.gradle b/build.gradle index 7e83903f..a3da46cf 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { version = System.getenv('GITHUB_VERSION') ?: 'local' group = 'com.onarandombox.multiverseinventories' -description = 'multiverse-inventories' +description = 'Multiverse-Inventories' java.sourceCompatibility = JavaVersion.VERSION_11 From 01c76e8fb7e831be49dc18c1c305992e3118b24d Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 21 Feb 2023 12:35:18 +0800 Subject: [PATCH 5/7] Add maven central to repositories --- build.gradle | 1 + 1 file changed, 1 insertion(+) diff --git a/build.gradle b/build.gradle index a3da46cf..1f240b6c 100644 --- a/build.gradle +++ b/build.gradle @@ -13,6 +13,7 @@ java.sourceCompatibility = JavaVersion.VERSION_11 repositories { mavenLocal() + mavenCentral() maven { name = 'onarandombox' From 2b164b6e47b272efa179031eac23d8fcfa1729f2 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:01:50 +0800 Subject: [PATCH 6/7] Fix version in plugin.yml --- src/main/resources/plugin.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index e33c2744..bf070278 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,6 +1,6 @@ name: Multiverse-Inventories main: com.onarandombox.multiverseinventories.MultiverseInventories -version: maven-version-number +version: ${version} api-version: 1.13 author: dumptruckman depend: ['Multiverse-Core'] @@ -108,4 +108,4 @@ commands: usage: / awareness: -- !@UTF8 \ No newline at end of file +- !@UTF8 From 86fe16abe76c30213e01b0cd86f06c5b868990b0 Mon Sep 17 00:00:00 2001 From: Ben Woo <30431861+benwoo1110@users.noreply.github.com> Date: Tue, 21 Feb 2023 22:51:24 +0800 Subject: [PATCH 7/7] Remove need to prepare source Co-authored-by: Jeremy Wood --- build.gradle | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/build.gradle b/build.gradle index 1f240b6c..2f24bf24 100644 --- a/build.gradle +++ b/build.gradle @@ -114,16 +114,6 @@ publishing { } -task prepareSource(type: Sync) { - from sourceSets.main.java - into "$buildDir/src" -} - - -compileJava { - source = prepareSource.outputs -} - processResources { def props = [version: "${project.version}"] inputs.properties props