From 23a497abf61dbed1a9080b10fa54c03806f1cbcc Mon Sep 17 00:00:00 2001 From: Josh Roy <10731363+JRoy@users.noreply.github.com> Date: Wed, 19 May 2021 07:34:00 -0400 Subject: [PATCH] Update Gradle to 7.0.2; misc build improvements (#4148) Co-authored-by: MD <1917406+mdcfe@users.noreply.github.com> * Bumped Gradle to 7.0.2 * Now uses Java 16 for compiling to prepare for MC 1.17 * Release target is still set to 8 however * Bumped Actions versions * Bumped indra version(s) * Switched from grgit to indra-git * Fix PR GitHub Actions jars having invalid branch names --- .github/workflows/build-master.yml | 13 +++-- .github/workflows/build-pr.yml | 13 +++-- build.gradle | 60 ++++++++++++++++++------ gradle/wrapper/gradle-wrapper.properties | 2 +- 4 files changed, 67 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build-master.yml b/.github/workflows/build-master.yml index 8540d74cf..d5b1b1309 100644 --- a/.github/workflows/build-master.yml +++ b/.github/workflows/build-master.yml @@ -15,6 +15,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 + - name: Restore Gradle cache uses: actions/cache@v2 with: @@ -22,15 +23,21 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} restore-keys: | ${{ runner.os }}-gradle- - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + + - name: Set up JDK 16 + uses: actions/setup-java@v2 with: - java-version: 1.8 + distribution: 'adopt' + java-version: 16 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 - name: Build with Gradle run: | chmod +x gradlew ./gradlew build --stacktrace + - name: Archive plugin jars on GitHub uses: actions/upload-artifact@master with: diff --git a/.github/workflows/build-pr.yml b/.github/workflows/build-pr.yml index c4938ba42..1ed0c24e7 100644 --- a/.github/workflows/build-pr.yml +++ b/.github/workflows/build-pr.yml @@ -20,6 +20,7 @@ jobs: uses: actions/checkout@v2 with: fetch-depth: 0 + - name: Restore Gradle cache uses: actions/cache@v2 with: @@ -27,15 +28,21 @@ jobs: key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} restore-keys: | ${{ runner.os }}-gradle- - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + + - name: Set up JDK 16 + uses: actions/setup-java@v2 with: - java-version: 1.8 + distribution: 'adopt' + java-version: 16 + + - name: Validate Gradle Wrapper + uses: gradle/wrapper-validation-action@v1 - name: Build with Gradle run: | chmod +x gradlew ./gradlew build --stacktrace + - name: Archive plugin jars on GitHub uses: actions/upload-artifact@master with: diff --git a/build.gradle b/build.gradle index f27955587..7b1e1f80f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,43 +1,71 @@ buildscript { ext { - indraVersion = '1.2.1' + indraVersion = '2.0.4' } } plugins { - id 'org.ajoberstar.grgit' version '4.1.0' id 'net.kyori.indra' version "$indraVersion" apply false + id 'net.kyori.indra.git' version "$indraVersion" id 'net.kyori.indra.checkstyle' version "$indraVersion" apply false id 'net.kyori.indra.publishing' version "$indraVersion" apply false - id 'com.github.johnrengelman.shadow' version '6.1.0' apply false + id 'com.github.johnrengelman.shadow' version '7.0.0' apply false } import org.apache.tools.ant.filters.ReplaceTokens +import org.eclipse.jgit.lib.Ref +import org.eclipse.jgit.lib.Repository +import org.eclipse.jgit.revwalk.RevWalk allprojects { group = 'net.essentialsx' version = '2.19.0-SNAPSHOT' } +@SuppressWarnings('GrMethodMayBeStatic') def commitsSinceLastTag() { - if (grgit == null) { - return 0 + if (indraGit == null || !indraGit.isPresent() || indraGit.tags().isEmpty()) { + return -1 } - def tags = grgit.tag.list().stream().map({it.commit}).toList() - def commit = grgit.head() + def tags = indraGit.tags() def depth = 0 + def walk = new RevWalk(indraGit.git().getRepository()) + def commit = walk.parseCommit(indraGit.commit()) while (true) { - if (tags.contains(commit)) - return depth + for (tag in tags) { + if (walk.parseCommit(tag.getLeaf().getObjectId()) == commit) { + walk.dispose() + indraGit.git().close() + return depth + } + } depth++ - commit = grgit.resolve.toCommit(commit.parentIds.get(0)) + commit = walk.parseCommit(commit.getParents()[0]) } } -ext { - GIT_COMMIT = grgit == null ? "unknown" : grgit.head().abbreviatedId - GIT_BRANCH = grgit == null ? "detached-head" : grgit.branch.current().name +@SuppressWarnings('GrMethodMayBeStatic') +def headBranchName() { + if (System.getenv("GITHUB_HEAD_REF") != null) { + return System.getenv("GITHUB_HEAD_REF") + } + + if (!indraGit.isPresent()) { + return "detached-head" + } + + Ref ref = indraGit.git().getRepository().exactRef('HEAD')?.target + if (ref == null) { + return "detached-head" + } + + return Repository.shortenRefName(ref.name) +} + +project.ext { + GIT_COMMIT = !indraGit.isPresent() ? "unknown" : indraGit.commit().abbreviate(7).name() GIT_DEPTH = commitsSinceLastTag() + GIT_BRANCH = headBranchName() fullVersion = "${version}".replace("-SNAPSHOT", "-dev+${GIT_DEPTH}-${GIT_COMMIT}") @@ -102,7 +130,7 @@ subprojects { } indra { - checkstyle = "$checkstyleVersion" + checkstyle "$checkstyleVersion" github('EssentialsX', 'Essentials') gpl3OnlyLicense() @@ -134,6 +162,10 @@ subprojects { } } } + + javaVersions { + target 8 + } } compileJava { diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4d9ca1649..0f80bbf51 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists