Skip to content

Bump Gradle #2510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
99 changes: 51 additions & 48 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
//to build everything: "gradlew build"
//to build and upload everything: "gradlew release"

import Build_gradle.Pom
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
import de.marcphilipp.gradle.nexus.InitializeNexusStagingRepository
import de.marcphilipp.gradle.nexus.NexusPublishExtension
Expand All @@ -33,10 +32,11 @@ plugins {
signing
`java-library`
`maven-publish`
`jvm-test-suite`

id("io.codearte.nexus-staging") version "0.30.0"
id("de.marcphilipp.nexus-publish") version "0.4.0"
id("com.github.johnrengelman.shadow") version "7.1.2"
id("com.github.johnrengelman.shadow") version "8.1.1"
}

val javaVersion = JavaVersion.current()
Expand All @@ -53,7 +53,7 @@ val commitHash: String by lazy {
val commit = System.getenv("GIT_COMMIT") ?: System.getProperty("GIT_COMMIT") ?: System.getenv("GITHUB_SHA")
// We only set the commit hash on CI builds since we don't want dirty local repos to set a wrong commit
if (isCI && commit != null)
commit.substring(0, 7)
commit.take(7)
else
"DEV"
}
Expand All @@ -72,7 +72,9 @@ project.version = "$versionObj" + if (isNewVersion) "" else "_$commitHash"

project.group = "net.dv8tion"

val archivesBaseName = "JDA"
base {
archivesName = "JDA"
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
Expand Down Expand Up @@ -145,14 +147,14 @@ val clean: Task by tasks
val test: Test by tasks
val check: Task by tasks

shadowJar.archiveClassifier.set("withDependencies")
shadowJar.archiveClassifier = "withDependencies"

fun nullable(string: String?): String {
return if (string == null) "null"
else "\"$string\""
}

val sourcesForRelease = task<Copy>("sourcesForRelease") {
val sourcesForRelease by tasks.creating(Copy::class) {
from("src/main/java") {
include("**/JDAInfo.java")
val tokens = mapOf(
Expand All @@ -166,14 +168,14 @@ val sourcesForRelease = task<Copy>("sourcesForRelease") {
// for this, we have special tokens marked with "!@...@!" which are replaced to @...@
filter { it.replace(Regex("\"!@|@!\""), "@") }
// Then we can replace the @...@ with the respective values here
filter<ReplaceTokens>(mapOf("tokens" to tokens))
filter<ReplaceTokens>("tokens" to tokens)
}
into("build/filteredSrc")

includeEmptyDirs = false
}

val generateJavaSources = task<SourceTask>("generateJavaSources") {
val generateJavaSources by tasks.creating(SourceTask::class) {
val javaSources = sourceSets["main"].allJava.filter {
it.name != "JDAInfo.java"
}.asFileTree
Expand All @@ -182,9 +184,9 @@ val generateJavaSources = task<SourceTask>("generateJavaSources") {
dependsOn(sourcesForRelease)
}

val noOpusJar = task<ShadowJar>("noOpusJar") {
val noOpusJar by tasks.creating(ShadowJar::class) {
dependsOn(shadowJar)
archiveClassifier.set(shadowJar.archiveClassifier.get() + "-no-opus")
archiveClassifier = shadowJar.archiveClassifier.map { "$it-no-opus" }

configurations = shadowJar.configurations
from(sourceSets["main"].output)
Expand All @@ -196,10 +198,10 @@ val noOpusJar = task<ShadowJar>("noOpusJar") {
manifest.inheritFrom(jar.manifest)
}

val minimalJar = task<ShadowJar>("minimalJar") {
val minimalJar by tasks.creating(ShadowJar::class) {
dependsOn(shadowJar)
minimize()
archiveClassifier.set(shadowJar.archiveClassifier.get() + "-min")
archiveClassifier = shadowJar.archiveClassifier.map { "$it-min" }

configurations = shadowJar.configurations
from(sourceSets["main"].output)
Expand All @@ -210,8 +212,8 @@ val minimalJar = task<ShadowJar>("minimalJar") {
manifest.inheritFrom(jar.manifest)
}

val sourcesJar = task<Jar>("sourcesJar") {
archiveClassifier.set("sources")
val sourcesJar by tasks.creating(Jar::class) {
archiveClassifier = "sources"
from("src/main/java") {
exclude("**/JDAInfo.java")
}
Expand All @@ -220,9 +222,9 @@ val sourcesJar = task<Jar>("sourcesJar") {
dependsOn(sourcesForRelease)
}

val javadocJar = task<Jar>("javadocJar") {
val javadocJar by tasks.creating(ShadowJar::class){
dependsOn(javadoc)
archiveClassifier.set("javadoc")
archiveClassifier = "javadoc"
from(javadoc.destinationDir)
}

Expand All @@ -249,10 +251,9 @@ compileJava.apply {
}

jar.apply {
archiveBaseName.set(project.name)
manifest.attributes(mapOf(
manifest.attributes(
"Implementation-Version" to project.version,
"Automatic-Module-Name" to "net.dv8tion.jda"))
"Automatic-Module-Name" to "net.dv8tion.jda")
}

javadoc.apply {
Expand Down Expand Up @@ -311,12 +312,14 @@ build.apply {
shadowJar.mustRunAfter(sourcesJar)
}

test.apply {
useJUnitPlatform()
failFast = true
testing {
suites {
named<JvmTestSuite>("test") {
useJUnitJupiter()
}
}
}


fun getProjectProperty(name: String) = project.properties[name] as? String

class Version(
Expand Down Expand Up @@ -360,31 +363,31 @@ class Version(

fun generatePom(pom: Pom) {
pom.packaging = "jar"
pom.name.set(project.name)
pom.description.set("Java wrapper for the popular chat & VOIP service: Discord https://discord.com")
pom.url.set("https://github.com/discord-jda/JDA")
pom.name = project.name
pom.description = "Java wrapper for the popular chat & VOIP service: Discord https://discord.com"
pom.url = "https://github.com/discord-jda/JDA"
pom.scm {
url.set("https://github.com/discord-jda/JDA")
connection.set("scm:git:git://github.com/discord-jda/JDA")
developerConnection.set("scm:git:ssh:[email protected]:discord-jda/JDA")
url = "https://github.com/discord-jda/JDA"
connection = "scm:git:git://github.com/discord-jda/JDA"
developerConnection = "scm:git:ssh:[email protected]:discord-jda/JDA"
}
pom.licenses {
license {
name.set("The Apache Software License, Version 2.0")
url.set("http://www.apache.org/licenses/LICENSE-2.0.txt")
distribution.set("repo")
name = "The Apache Software License, Version 2.0"
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
distribution = "repo"
}
}
pom.developers {
developer {
id.set("Minn")
name.set("Florian Spieß")
email.set("[email protected]")
id = "Minn"
name = "Florian Spieß"
email = "[email protected]"
}
developer {
id.set("DV8FromTheWorld")
name.set("Austin Keener")
email.set("[email protected]")
id ="DV8FromTheWorld"
name ="Austin Keener"
email ="[email protected]"
}
}
}
Expand All @@ -395,11 +398,11 @@ fun generatePom(pom: Pom) {
// Skip fat jar publication (See https://github.com/johnrengelman/shadow/issues/586)
components.java.withVariantsFromConfiguration(configurations.shadowRuntimeElements.get()) { skip() }
val SoftwareComponentContainer.java
get() = components.getByName("java") as AdhocComponentWithVariants
get() = getByName<AdhocComponentWithVariants>("java")

publishing {
publications {
register("Release", MavenPublication::class) {
register<MavenPublication>("Release") {
from(components["java"])

artifactId = project.name
Expand Down Expand Up @@ -434,13 +437,13 @@ configure<NexusStagingExtension> {
configure<NexusPublishExtension> {
nexusPublishing {
repositories.sonatype {
username.set(getProjectProperty("ossrhUser") ?: "")
password.set(getProjectProperty("ossrhPassword") ?: "")
stagingProfileId.set(getProjectProperty("stagingProfileId") ?: "")
username = getProjectProperty("ossrhUser") ?: ""
password = getProjectProperty("ossrhPassword") ?: ""
stagingProfileId = getProjectProperty("stagingProfileId") ?: ""
}
// Sonatype is very slow :)
connectTimeout.set(Duration.ofMinutes(1))
clientTimeout.set(Duration.ofMinutes(10))
connectTimeout = Duration.ofMinutes(1)
clientTimeout = Duration.ofMinutes(10)
}
}

Expand Down Expand Up @@ -471,15 +474,14 @@ tasks.create("release") {
dependsOn(tasks.withType<PublishToMavenRepository>())

// Closes the sonatype repository and publishes to maven central
val closeAndReleaseRepository: Task by tasks
dependsOn(closeAndReleaseRepository)
dependsOn(tasks.closeAndReleaseRepository)

// Builds all jars for publications
dependsOn(build)
enabled = shouldPublish

doLast { // Only runs when shouldPublish = true
println("Saving version $versionObj to .version")
logger.lifecycle("Saving version $versionObj to .version")
val file = File(".version")
file.createNewFile()
file.writeText(versionObj.toString())
Expand All @@ -494,3 +496,4 @@ tasks.withType<PublishToMavenRepository> {
tasks.withType<Copy> {
duplicatesStrategy = DuplicatesStrategy.INCLUDE
}

Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 3 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2.1-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
30 changes: 22 additions & 8 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand All @@ -80,13 +80,10 @@ do
esac
done

APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

APP_NAME="Gradle"
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}

# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down Expand Up @@ -133,22 +130,29 @@ location of your Java installation."
fi
else
JAVACMD=java
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
if ! command -v java >/dev/null 2>&1
then
die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.

Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
fi

# Increase the maximum file descriptors if we can.
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
case $MAX_FD in #(
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
Expand Down Expand Up @@ -193,6 +197,10 @@ if "$cygwin" || "$msys" ; then
done
fi


# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
Expand All @@ -205,6 +213,12 @@ set -- \
org.gradle.wrapper.GradleWrapperMain \
"$@"

# Stop when "xargs" is not available.
if ! command -v xargs >/dev/null 2>&1
then
die "xargs is not available"
fi

# Use "xargs" to parse quoted args.
#
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
Expand Down
15 changes: 9 additions & 6 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@rem
@rem Gradle startup script for Windows
Expand All @@ -25,7 +25,8 @@
if "%OS%"=="Windows_NT" setlocal

set DIRNAME=%~dp0
if "%DIRNAME%" == "" set DIRNAME=.
if "%DIRNAME%"=="" set DIRNAME=.
@rem This is normally unused
set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

Expand All @@ -40,7 +41,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome

set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if "%ERRORLEVEL%" == "0" goto execute
if %ERRORLEVEL% equ 0 goto execute

echo.
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Expand Down Expand Up @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar

:end
@rem End local scope for the variables with windows NT shell
if "%ERRORLEVEL%"=="0" goto mainEnd
if %ERRORLEVEL% equ 0 goto mainEnd

:fail
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
rem the _cmd.exe /c_ return code!
if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
exit /b 1
set EXIT_CODE=%ERRORLEVEL%
if %EXIT_CODE% equ 0 set EXIT_CODE=1
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
exit /b %EXIT_CODE%

:mainEnd
if "%OS%"=="Windows_NT" endlocal
Expand Down