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
This commit is contained in:
Josh Roy 2021-05-19 07:34:00 -04:00 committed by GitHub
parent d00b90cd61
commit 23a497abf6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 67 additions and 21 deletions

View File

@ -15,6 +15,7 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Restore Gradle cache - name: Restore Gradle cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
@ -22,15 +23,21 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: | restore-keys: |
${{ runner.os }}-gradle- ${{ 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: with:
java-version: 1.8 distribution: 'adopt'
java-version: 16
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Build with Gradle - name: Build with Gradle
run: | run: |
chmod +x gradlew chmod +x gradlew
./gradlew build --stacktrace ./gradlew build --stacktrace
- name: Archive plugin jars on GitHub - name: Archive plugin jars on GitHub
uses: actions/upload-artifact@master uses: actions/upload-artifact@master
with: with:

View File

@ -20,6 +20,7 @@ jobs:
uses: actions/checkout@v2 uses: actions/checkout@v2
with: with:
fetch-depth: 0 fetch-depth: 0
- name: Restore Gradle cache - name: Restore Gradle cache
uses: actions/cache@v2 uses: actions/cache@v2
with: with:
@ -27,15 +28,21 @@ jobs:
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }} key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
restore-keys: | restore-keys: |
${{ runner.os }}-gradle- ${{ 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: with:
java-version: 1.8 distribution: 'adopt'
java-version: 16
- name: Validate Gradle Wrapper
uses: gradle/wrapper-validation-action@v1
- name: Build with Gradle - name: Build with Gradle
run: | run: |
chmod +x gradlew chmod +x gradlew
./gradlew build --stacktrace ./gradlew build --stacktrace
- name: Archive plugin jars on GitHub - name: Archive plugin jars on GitHub
uses: actions/upload-artifact@master uses: actions/upload-artifact@master
with: with:

View File

@ -1,43 +1,71 @@
buildscript { buildscript {
ext { ext {
indraVersion = '1.2.1' indraVersion = '2.0.4'
} }
} }
plugins { plugins {
id 'org.ajoberstar.grgit' version '4.1.0'
id 'net.kyori.indra' version "$indraVersion" apply false 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.checkstyle' version "$indraVersion" apply false
id 'net.kyori.indra.publishing' 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.apache.tools.ant.filters.ReplaceTokens
import org.eclipse.jgit.lib.Ref
import org.eclipse.jgit.lib.Repository
import org.eclipse.jgit.revwalk.RevWalk
allprojects { allprojects {
group = 'net.essentialsx' group = 'net.essentialsx'
version = '2.19.0-SNAPSHOT' version = '2.19.0-SNAPSHOT'
} }
@SuppressWarnings('GrMethodMayBeStatic')
def commitsSinceLastTag() { def commitsSinceLastTag() {
if (grgit == null) { if (indraGit == null || !indraGit.isPresent() || indraGit.tags().isEmpty()) {
return 0 return -1
} }
def tags = grgit.tag.list().stream().map({it.commit}).toList() def tags = indraGit.tags()
def commit = grgit.head()
def depth = 0 def depth = 0
def walk = new RevWalk(indraGit.git().getRepository())
def commit = walk.parseCommit(indraGit.commit())
while (true) { while (true) {
if (tags.contains(commit)) for (tag in tags) {
return depth if (walk.parseCommit(tag.getLeaf().getObjectId()) == commit) {
walk.dispose()
indraGit.git().close()
return depth
}
}
depth++ depth++
commit = grgit.resolve.toCommit(commit.parentIds.get(0)) commit = walk.parseCommit(commit.getParents()[0])
} }
} }
ext { @SuppressWarnings('GrMethodMayBeStatic')
GIT_COMMIT = grgit == null ? "unknown" : grgit.head().abbreviatedId def headBranchName() {
GIT_BRANCH = grgit == null ? "detached-head" : grgit.branch.current().name 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_DEPTH = commitsSinceLastTag()
GIT_BRANCH = headBranchName()
fullVersion = "${version}".replace("-SNAPSHOT", "-dev+${GIT_DEPTH}-${GIT_COMMIT}") fullVersion = "${version}".replace("-SNAPSHOT", "-dev+${GIT_DEPTH}-${GIT_COMMIT}")
@ -102,7 +130,7 @@ subprojects {
} }
indra { indra {
checkstyle = "$checkstyleVersion" checkstyle "$checkstyleVersion"
github('EssentialsX', 'Essentials') github('EssentialsX', 'Essentials')
gpl3OnlyLicense() gpl3OnlyLicense()
@ -134,6 +162,10 @@ subprojects {
} }
} }
} }
javaVersions {
target 8
}
} }
compileJava { compileJava {

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists