Skip to content
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

Gradle 7.6 to 8.2 (conventions to extensions migration, mostly) #3051

Merged
merged 34 commits into from Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5f18ae0
Fix CollectionUtils deprecation nagging by migrating from
TWiStErRob Jun 30, 2023
10ac81b
Fix warning during test by only setting the flag when applicable.
TWiStErRob Jun 30, 2023
ed8718c
Use the official method for pulling dependencies from Gradle repo.
TWiStErRob Jun 30, 2023
6b00559
AbstractArchiveTask.setClassifier(String) was deprecated and removed …
TWiStErRob Jun 30, 2023
c00a56e
Migrate from BasePluginConvention to BasePluginExtension in rootProje…
TWiStErRob Jun 30, 2023
95226dd
Migrate from BasePluginConvention to BasePluginExtension in rootProject
TWiStErRob Jun 30, 2023
672c32e
Upgrade Gradle wrapper to 8.2 RC3
TWiStErRob Jun 30, 2023
025c6b4
Migrate from JavaPluginConvention to JavaPluginExtension: sourceCompa…
TWiStErRob Jul 4, 2023
50142bd
Migrate from JavaPluginConvention to JavaPluginExtension: sourceCompa…
TWiStErRob Jul 4, 2023
1d76b7d
Migrate from JavaPluginConvention to JavaPluginExtension: sourceCompa…
TWiStErRob Jul 4, 2023
b3262fa
Migrate from JavaPluginConvention to JavaPluginExtension: sourceCompa…
TWiStErRob Jul 4, 2023
199f8e9
Migrate from JavaPluginConvention to JavaPluginExtension: sourceCompa…
TWiStErRob Jul 4, 2023
088ba37
Migrate from JavaPluginConvention to JavaPluginExtension: sourceCompa…
TWiStErRob Jul 4, 2023
86e2883
Migrate from BasePluginConvention to BasePluginExtension in :bom
TWiStErRob Jul 4, 2023
0be5302
Migrate from BasePluginConvention to BasePluginExtension in rootProje…
TWiStErRob Jul 4, 2023
24630b7
Report.destination(File) was deprecated and removed in favor of Repor…
TWiStErRob Jul 4, 2023
ae13260
Jar.classpath property doesn't exist, it's a magical property defined…
TWiStErRob Jul 4, 2023
dde6bd6
Bundle.bnd property doesn't exist, it's a magical property defined at…
TWiStErRob Jul 4, 2023
9d06229
Help future maintainer figure out what non-standard bundle { } closur…
TWiStErRob Jul 4, 2023
78fa7f1
Suppress unchecked warning, it's as safe as Groovy accessing the same.
TWiStErRob Jul 4, 2023
95eb0dd
Upgrade AGP 7.3.1 to 7.4.2 to get updates for Gradle deprecations.
TWiStErRob Jul 4, 2023
f8c83c5
Groovy needed to move groovy.util.XmlSlurper to groovy.xml, see
TWiStErRob Jul 4, 2023
6adcf6c
Migrate from BasePluginConvention to BasePluginExtension in java-library
TWiStErRob Jul 4, 2023
e1e2656
Migrate from BasePluginExtension.getArchivesBaseName(): String to Bas…
TWiStErRob Jul 4, 2023
886d391
WriteProperties.setOutputFile(File) was deprecated in Gradle 8.1 in f…
TWiStErRob Jul 4, 2023
35d3bfb
Syntax cleanup: ProjectLayout.getBuildDirectory is a property, access…
TWiStErRob Jul 4, 2023
c6d05b5
Migrate from JavaPluginConvention to JavaPluginExtension: targetCompa…
TWiStErRob Jul 4, 2023
941bbfd
Bump Gradle Enterprise plugin to latest to remove deprecated usage:
TWiStErRob Jul 4, 2023
badc994
Bump Gradle 8.2 to stable
TWiStErRob Jul 4, 2023
433668e
Add implicit test dependency to fix Gradle classpath.
TWiStErRob Jul 4, 2023
bd4318d
Suppress known and accepted license header problems:
TWiStErRob Jul 4, 2023
de0e384
Downgrade to Gradle 8.1 to prevent triggering https://github.com/bndt…
TWiStErRob Jul 4, 2023
e1fec73
Remove outdated hack, it seems to do nothing (verified with `gradlew …
TWiStErRob Jul 4, 2023
0a56409
Revert "Downgrade to Gradle 8.1 to prevent triggering https://github.…
TWiStErRob Jul 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 3 additions & 21 deletions build.gradle
Expand Up @@ -2,7 +2,7 @@ buildscript {
repositories {
mavenLocal() //for local testing of mockito-release-tools
google()
maven { url 'https://plugins.gradle.org/m2/' }
gradlePluginPortal()
}

dependencies {
Expand All @@ -14,7 +14,7 @@ buildscript {
classpath 'org.shipkit:shipkit-auto-version:1.2.2'

classpath 'com.google.googlejavaformat:google-java-format:1.17.0'
classpath 'com.android.tools.build:gradle:7.3.1'
classpath 'com.android.tools.build:gradle:7.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.22"
}
}
Expand All @@ -30,7 +30,7 @@ plugins {
description = 'Mockito mock objects library core API and implementation'

apply plugin: 'base'
archivesBaseName = 'mockito-core'
base.archivesName = 'mockito-core'

apply from: 'gradle/shipkit.gradle'

Expand Down Expand Up @@ -136,21 +136,3 @@ spotless {
targetExclude 'src/test/java/org/mockitousage/internal/junit/UnusedStubbingsFinderTest.java'
}
}


//workaround for #1444, delete when Shipkit bug is fixed
subprojects {
eclipse {
project {
name = rootProject.name + '-' + project.name
}
}

afterEvaluate {
def lib = publishing.publications.javaLibrary
if(lib && !lib.artifactId.startsWith("mockito-")) {
lib.artifactId = "mockito-" + lib.artifactId
}
}
}
//end workaround
16 changes: 9 additions & 7 deletions gradle/java-library.gradle
@@ -1,21 +1,23 @@
apply plugin: "java"
apply plugin: "java-library"

if (!archivesBaseName.startsWith("mockito-")) {
archivesBaseName = "mockito-" + project.name
if (!base.archivesName.get().startsWith("mockito-")) {
base.archivesName = "mockito-" + project.name
}

apply from: "$rootDir/gradle/java-publication.gradle"

generatePomFileForJavaLibraryPublication.doLast {
//validates the the pom has correct artifact id to avoid issues like #1444
def pom = new XmlSlurper().parse(destination)
assert pom.artifactId == archivesBaseName
assert pom.name == archivesBaseName
def pom = new groovy.xml.XmlSlurper().parse(destination)
assert pom.artifactId == base.archivesName.get()
assert pom.name == base.archivesName.get()
}

sourceCompatibility = 11
targetCompatibility = 11
java {
sourceCompatibility = 11
targetCompatibility = 11
}

test {
include "**/*Test.class"
Expand Down
6 changes: 3 additions & 3 deletions gradle/java-publication.gradle
Expand Up @@ -8,13 +8,13 @@ plugins.withId("java") {
}

task sourcesJar(type: Jar, dependsOn: classes) {
classifier = 'sources'
archiveClassifier = 'sources'
from sourceSets.main.allSource
with licenseSpec
}

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
archiveClassifier = 'javadoc'
from tasks.javadoc
with licenseSpec
}
Expand Down Expand Up @@ -48,7 +48,7 @@ publishing {
from components.javaPlatform
}

artifactId = project.archivesBaseName
artifactId = project.base.archivesName.get()

pom {
name = artifactId
Expand Down
6 changes: 6 additions & 0 deletions gradle/license.gradle
Expand Up @@ -11,6 +11,12 @@ allprojects {
java = 'SLASHSTAR_STYLE'
groovy = 'SLASHSTAR_STYLE'
}

exclude "junit-platform.properties"
exclude "mockito-extensions/org.mockito.plugins.*"
exclude "META-INF/services/org.junit.jupiter.api.extension.Extension"
exclude "org/mockito/internal/util/concurrent/README.md"
exclude "org/mockito/internal/util/concurrent/LICENSE"
ext.year = Calendar.getInstance().get(Calendar.YEAR)
}
}
4 changes: 2 additions & 2 deletions gradle/mockito-core/osgi.gradle
@@ -1,8 +1,8 @@
apply plugin: 'biz.aQute.bnd.builder'

jar {
classpath = project.configurations.compileClasspath
bundle {
bundle { // this: BundleTaskExtension
classpath = project.configurations.compileClasspath
bnd(
'Bundle-Name': 'Mockito Mock Library for Java. Core bundle requires Byte Buddy and Objenesis.',
'Bundle-SymbolicName': 'org.mockito.mockito-core',
Expand Down
5 changes: 3 additions & 2 deletions gradle/root/coverage.gradle
Expand Up @@ -37,11 +37,12 @@ task mockitoCoverage(type: JacocoReport) {
reports {
xml.required = true
html.required = true
html.destination file("${buildDir}/jacocoHtml")
html.outputLocation = file("${buildDir}/jacocoHtml")
}

doLast {
logger.lifecycle "Jacoco HTML created: file://${new File(reports.html.destination, "index.html").toURI().path}"
def reportFile = new File(reports.html.outputLocation.get().asFile, "index.html")
logger.lifecycle "Jacoco HTML created: file://${reportFile.toURI().path}"
}
}

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 4 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,8 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionSha256Sum=7ba68c54029790ab444b39d7e293d3236b2632631fb5f2e012bb28b4ff669e4b
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
distributionSha256Sum=38f66cd6eef217b4c35855bb11ea4e9fbc53594ccccb5fb82dfd317ef8c2c5a3
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
24 changes: 16 additions & 8 deletions gradlew
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 Down
1 change: 1 addition & 0 deletions gradlew.bat
Expand Up @@ -26,6 +26,7 @@ if "%OS%"=="Windows_NT" setlocal

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

Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
@@ -1,5 +1,5 @@
plugins {
id("com.gradle.enterprise").version("3.3.4")
id("com.gradle.enterprise").version("3.13.4")
}

include("subclass",
Expand Down
4 changes: 2 additions & 2 deletions subprojects/bom/bom.gradle
Expand Up @@ -4,8 +4,8 @@ plugins {

description = "Mockito Bill of Materials (BOM)"

if (!archivesBaseName.startsWith("mockito-")) {
archivesBaseName = "mockito-" + project.name
if (!base.archivesName.get().startsWith("mockito-")) {
base.archivesName = "mockito-" + project.name
}

apply from: "$rootDir/gradle/java-publication.gradle"
Expand Down
17 changes: 14 additions & 3 deletions subprojects/inlineTest/inlineTest.gradle
Expand Up @@ -6,8 +6,10 @@ description = "Mockito preconfigured inline mock maker (intermediate and to be s

apply from: "$rootDir/gradle/dependencies.gradle"

sourceCompatibility = 11
targetCompatibility = 11
java {
sourceCompatibility = 11
targetCompatibility = 11
}

dependencies {
implementation project.rootProject
Expand All @@ -18,7 +20,16 @@ dependencies {
tasks.javadoc.enabled = false

test {
jvmArgs '--illegal-access=deny'
if (JavaVersion.VERSION_17 <= JavaVersion.current()) {
// For Java 17: https://openjdk.org/jeps/403
// > Ignoring option --illegal-access=deny; support was removed in 17.0
} else if (JavaVersion.VERSION_16 <= JavaVersion.current()) {
// For Java 16: https://openjdk.org/jeps/396
// --illegal-access=deny is the default.
} else if (JavaVersion.VERSION_1_9 <= JavaVersion.current()) {
// For Java 9-15: https://openjdk.org/jeps/261#Relaxed-strong-encapsulation
jvmArgs '--illegal-access=deny'
}
//required by the "StressTest.java" and "OneLinerStubStressTest.java"
maxHeapSize '256m'
}
12 changes: 6 additions & 6 deletions subprojects/junit-jupiter/junit-jupiter.gradle
Expand Up @@ -18,8 +18,8 @@ tasks.withType(Test) {
}

jar {
classpath = project.configurations.runtimeClasspath
bundle {
bundle { // this: BundleTaskExtension
classpath = project.configurations.runtimeClasspath
bnd(
'Bundle-Name': 'Mockito Extension Library for JUnit 5.',
'Bundle-SymbolicName': 'org.mockito.junit-jupiter',
Expand All @@ -38,18 +38,18 @@ jar {
// task writes out the properties necessary for it to verify the OSGi
// metadata.
def osgiProperties = tasks.register('osgiProperties', WriteProperties) {
outputFile = layout.getBuildDirectory().file("verifyOSGiProperties.bndrun")
destinationFile = layout.buildDirectory.file("verifyOSGiProperties.bndrun")
property('-standalone', true)
property('-runee', "JavaSE-${targetCompatibility}")
property('-runee', "JavaSE-${java.targetCompatibility}")
property('-runrequires', 'osgi.identity;filter:="(osgi.identity=org.mockito.junit-jupiter)"')
}

// Bnd's Resolve task is what verifies that a jar can be used in OSGi and
// that its metadata is valid. If the metadata is invalid this task will
// fail.
def verifyOSGi = tasks.register('verifyOSGi', Resolve) {
getBndrun().fileProvider(osgiProperties.map { it.outputFile })
getOutputBndrun().set(layout.getBuildDirectory().file("resolvedOSGiProperties.bndrun"))
getBndrun().value(osgiProperties.flatMap { it.destinationFile })
getOutputBndrun().set(layout.buildDirectory.file("resolvedOSGiProperties.bndrun"))
reportOptional = false
}

Expand Down
Expand Up @@ -9,17 +9,17 @@ description = "End-to-end tests for automatic registration of MockitoExtension."
dependencies {
testImplementation(project(":junit-jupiter"))
testImplementation(library("assertj"))
testImplementation(library("junitPlatformLauncher"))
testImplementation(library("junitJupiterApi"))
testRuntimeOnly(library("junitJupiterEngine"))
testRuntimeOnly(library("junitPlatformLauncher"))
}

tasks.named<Test>("test") {
useJUnitPlatform()
}

val Project.libraries
get() = rootProject.extra["libraries"] as Map<String, Any>
get() = @Suppress("UNCHECKED_CAST") (rootProject.extra["libraries"] as Map<String, Any>)

fun Project.library(name: String) =
libraries[name]!!
Expand Up @@ -9,17 +9,17 @@ description = "End-to-end tests for automatic registration of MockitoExtension w
dependencies {
testImplementation(project(":junit-jupiter"))
testImplementation(library("assertj"))
testImplementation(library("junitPlatformLauncher"))
testImplementation(library("junitJupiterApi"))
testRuntimeOnly(library("junitJupiterEngine"))
testRuntimeOnly(library("junitPlatformLauncher"))
}

tasks.named<Test>("test") {
useJUnitPlatform()
}

val Project.libraries
get() = rootProject.extra["libraries"] as Map<String, Any>
get() = @Suppress("UNCHECKED_CAST") (rootProject.extra["libraries"] as Map<String, Any>)

fun Project.library(name: String) =
libraries[name]!!
Expand Up @@ -8,6 +8,7 @@ dependencies {
testImplementation libraries.junitJupiterApi
testImplementation project(":junit-jupiter")
testRuntimeOnly libraries.junitJupiterEngine
testRuntimeOnly libraries.junitPlatformLauncher
}

test {
Expand Down
Expand Up @@ -20,8 +20,10 @@ repositories {
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}

sourceCompatibility = 11
targetCompatibility = 11
java {
sourceCompatibility = 11
targetCompatibility = 11
}

tasks.withType(KotlinCompile).configureEach {
compilerOptions {
Expand Down
6 changes: 4 additions & 2 deletions subprojects/kotlinTest/kotlinTest.gradle
Expand Up @@ -10,8 +10,10 @@ description = "Kotlin tests for Mockito."

apply from: "$rootDir/gradle/dependencies.gradle"

sourceCompatibility = 11
targetCompatibility = 11
java {
sourceCompatibility = 11
targetCompatibility = 11
}

tasks.withType(KotlinCompile).configureEach {
compilerOptions {
Expand Down
6 changes: 4 additions & 2 deletions subprojects/module-test/module-test.gradle
Expand Up @@ -14,5 +14,7 @@ dependencies {

tasks.javadoc.enabled = false

sourceCompatibility = 11
targetCompatibility = 11
java {
sourceCompatibility = 11
targetCompatibility = 11
}