Skip to content

Commit

Permalink
Update to gradle 6 (mockito#1948)
Browse files Browse the repository at this point in the history
* Upgrade to Gradle 6

This included a couple of breaking changes:
- The build plugin is now part of the Gradle Enterprise plugin
- The osgi plugin was removed, for which we have to use the bndtools
plugin instead
- Kotlin version has to be updated, including their coroutine
library versions

Gradle 6 is required for us to build on Java 14.

Supersedes and closes mockito#1923

* Remove commented plugin

* Move checksum computation out of Gradle

Gradle 6 does not like that we run a build twice, as part of a Gradle
task. Therefore, we have to move the checksum computation out of
the gradle task in a separate Bash script.

* Run reproducibility check as a separate Travis build

Otherwise we lose the code coverage, as we run a `gradle clean`
in the reproducibility check.

* Fix code coverage

This now also makes use of the build cache, which should significantly
speed up Travis builds.

* Fix disabling of projects for the coverage task

* Fix exclusion of errorprone subproject

* Reverse logic in coverage.gradle
  • Loading branch information
TimvdLippe authored and epeee committed Jun 22, 2020
1 parent ccb0006 commit 9df2012
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 151 deletions.
3 changes: 3 additions & 0 deletions .gitignore
@@ -1,3 +1,6 @@
# Mac
.DS_Store

# Intellij
*.iml
*.ipr
Expand Down
7 changes: 5 additions & 2 deletions .travis.yml
Expand Up @@ -34,6 +34,9 @@ matrix:
env: SKIP_RELEASE=true
- jdk: openjdk11
env: SKIP_RELEASE=true MOCK_MAKER=mock-maker-inline
- jdk: openjdk8
script: ./check_reproducibility.sh
after_success: true

branches:
#Don't build tags
Expand All @@ -50,9 +53,9 @@ script:
# We are using && below on purpose
# ciPerformRelease must run only when the entire build has completed
# This guarantees that no release steps are executed when the build or tests fail
- ./gradlew spotlessCheck && ./gradlew build idea -s && ./gradlew checkReproducibility && ./gradlew ciPerformRelease
- ./gradlew spotlessCheck && ./gradlew build idea -s && ./gradlew ciPerformRelease

after_success:
#Generates coverage report:
- ./gradlew coverageReport -Pjacoco -s --scan && cp build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml jacoco.xml || echo "Code coverage failed"
- ./gradlew coverageReport -s --scan && cp build/reports/jacoco/mockitoCoverage/mockitoCoverage.xml jacoco.xml || echo "Code coverage failed"
- bash <(curl -s https://codecov.io/bash) || echo "Codecov did not collect coverage reports"
9 changes: 1 addition & 8 deletions build.gradle
Expand Up @@ -15,10 +15,10 @@ buildscript {
}

plugins {
id 'com.gradle.build-scan' version '2.2.1'
id "com.diffplug.gradle.spotless" version "3.24.3"
id 'eclipse'
id 'com.github.ben-manes.versions' version '0.28.0'
id 'biz.aQute.bnd.builder' version '5.1.0'
}

description = 'Mockito mock objects library core API and implementation'
Expand All @@ -43,7 +43,6 @@ apply from: 'gradle/root/coverage.gradle'
apply from: 'gradle/mockito-core/inline-mock.gradle'
apply from: 'gradle/mockito-core/osgi.gradle'
apply from: 'gradle/mockito-core/javadoc.gradle'
apply from: 'gradle/mockito-core/reproducible-build.gradle'
apply from: 'gradle/mockito-core/testing.gradle'

apply from: 'gradle/dependencies.gradle'
Expand Down Expand Up @@ -104,12 +103,6 @@ wrapper {
distributionSha256Sum = 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'
}

//Posting Build scans to https://scans.gradle.com
buildScan {
termsOfServiceUrl = 'https://gradle.com/terms-of-service'
termsOfServiceAgree = 'yes'
}

spotless {
java {
licenseHeaderFile rootProject.file('config/spotless/spotless.header')
Expand Down
26 changes: 26 additions & 0 deletions check_reproducibility.sh
@@ -0,0 +1,26 @@
#!/bin/bash -e

# This script is taken from https://github.com/junit-team/junit5/pull/2217

rm -rf checksums/
mkdir checksums/

export SOURCE_DATE_EPOCH=$(date +%s)

function calculate_checksums() {
OUTPUT=checksums/$1

./gradlew --no-build-cache clean assemble --parallel

find ./build -name '*.jar' \
| grep '/build/libs/' \
| grep --invert-match 'javadoc' \
| sort \
| xargs sha256sum > ${OUTPUT}
}


calculate_checksums checksums-1.txt
calculate_checksums checksums-2.txt

diff checksums/checksums-1.txt checksums/checksums-2.txt
9 changes: 2 additions & 7 deletions gradle/dependencies.gradle
Expand Up @@ -34,15 +34,10 @@ libraries.osgi = 'org.osgi:osgi.core:7.0.0'
libraries.equinox = 'org.eclipse.platform:org.eclipse.osgi:3.15.0'
libraries.bndGradle = 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.3.1'

def kotlinVersion = '1.2.10'
def kotlinVersion_1_3 = '1.3.0-rc-57'
def kotlinVersion = '1.3.72'
libraries.kotlin = [
version: kotlinVersion,
version_1_3: kotlinVersion_1_3,

stdlib: "org.jetbrains.kotlin:kotlin-stdlib:${kotlinVersion}",
coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:0.19.3',

stdlib_1_3: "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion_1_3",
releaseCoroutines: "org.jetbrains.kotlinx:kotlinx-coroutines-core:0.26.1-eap13"
coroutines: 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.7',
]
69 changes: 28 additions & 41 deletions gradle/mockito-core/osgi.gradle
Expand Up @@ -7,49 +7,36 @@ import java.util.jar.Manifest

import static java.util.Calendar.FEBRUARY

apply plugin: 'osgi'

afterEvaluate {
tasks.matching { it.name == 'jar' }.all { jar ->
jar.manifest {
classpath = project.configurations.runtime

instruction '-versionpolicy', '[${version;==;${@}},${version;+;${@}})'

name = 'Mockito Mock Library for Java. Core bundle requires Byte Buddy and Objenesis.'
symbolicName = 'org.mockito.mockito-core'
version = project.version.replace('-', '.')

instruction 'Export-Package',
'!org.mockito.internal.*',
"org.mockito.*;version=${version}"

instruction 'Import-Package',
'net.bytebuddy.*;version="[1.6.0,2.0)"',
'junit.*;resolution:=optional',
'org.junit.*;resolution:=optional',
'org.hamcrest;resolution:=optional',
'org.objenesis;version="[2.5,3.0)"',
'org.opentest4j.*;resolution:=optional',
'org.mockito.*'

instruction 'Private-Package',
'org.mockito.*'

instruction '-removeheaders', 'Private-Package'

attributes 'Automatic-Module-Name': 'org.mockito'
}

jar.doLast {
JarFile originalJar = new JarFile(jar.archivePath)
apply plugin: 'biz.aQute.bnd.builder'

jar {
classpath = project.configurations.runtime
bnd(
'Bundle-Name': 'Mockito Mock Library for Java. Core bundle requires Byte Buddy and Objenesis.',
'Bundle-SymbolicName': 'org.mockito.mockito-core',
'Bundl-version': project.version.replace('-', '.'),
'-versionpolicy': '[${version;==;${@}},${version;+;${@}})',
'Export-Package': "!org.mockito.internal.*,org.mockito.*;version=${version}",
'Import-Package': [
'net.bytebuddy.*;version="[1.6.0,2.0)"',
'junit.*;resolution:=optional',
'org.junit.*;resolution:=optional',
'org.hamcrest;resolution:=optional',
'org.objenesis;version="[2.5,3.0)"',
'org.opentest4j.*;resolution:=optional',
'org.mockito.*'
].join(','),
'-removeheaders': 'Private-Package',
'Automatic-Module-Name': 'org.mockito'
)
}

new RemoveOsgiLastModifiedHeader(originalJar)
.transform()
.renameTo jar.archivePath
}
jar.doLast {
JarFile originalJar = new JarFile(jar.archivePath)

}
new RemoveOsgiLastModifiedHeader(originalJar)
.transform()
.renameTo jar.archivePath
}


Expand Down
69 changes: 0 additions & 69 deletions gradle/mockito-core/reproducible-build.gradle

This file was deleted.

22 changes: 12 additions & 10 deletions gradle/root/coverage.gradle
@@ -1,16 +1,18 @@
if (!project.hasProperty("jacoco")) {
//JaCoCo plugin prevents using Build Cache. We will enable jacoco configuration only when specific property is supplied
//TODO remove this workaround when we migrate to Gradle 5.0 (https://github.com/gradle/gradle/issues/5269)
logger.info "JaCoCo code coverage will not be configured because 'jacoco' project property is not present."
return //don't evaluate this Gradle file any further
} else {
logger.lifecycle "Configuring JaCoCo code coverage because 'jacoco' project property is present."
}

//TODO: Standard JaCoCo coverage doesn't work in Android module
task mockitoCoverage(type: JacocoReport) {

allprojects { currentProject ->
// These tests do not have a `test` task.
if (currentProject.name in ['android']) {
return
}
// We only run these tests on Java 9+
if (currentProject.name in ['module-test'] && !JavaVersion.current().isJava9Compatible()) {
return
}
// We only run these tests on Java 8
if (currentProject.name in ['errorprone'] && JavaVersion.current().isJava9Compatible()) {
return
}
plugins.withId("java") {
mockitoCoverage.sourceSets currentProject.sourceSets.main

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,5 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.3.1-bin.zip
distributionSha256Sum=e58cdff0cee6d9b422dcd08ebeb3177bc44eaa09bd9a2e838ff74c408fe1cbcd
distributionUrl=https\://services.gradle.org/distributions/gradle-6.4.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
18 changes: 17 additions & 1 deletion gradlew
@@ -1,5 +1,21 @@
#!/usr/bin/env sh

#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

##############################################################################
##
## Gradle start up script for UN*X
Expand Down Expand Up @@ -28,7 +44,7 @@ APP_NAME="Gradle"
APP_BASE_NAME=`basename "$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=""
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
Expand Down
18 changes: 17 additions & 1 deletion gradlew.bat
@@ -1,3 +1,19 @@
@rem
@rem Copyright 2015 the original author or authors.
@rem
@rem Licensed under the Apache License, Version 2.0 (the "License");
@rem you may not use this file except in compliance with the License.
@rem You may obtain a copy of the License at
@rem
@rem http://www.apache.org/licenses/LICENSE-2.0
@rem
@rem Unless required by applicable law or agreed to in writing, software
@rem distributed under the License is distributed on an "AS IS" BASIS,
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem

@if "%DEBUG%" == "" @echo off
@rem ##########################################################################
@rem
Expand All @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0
set APP_HOME=%DIRNAME%

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

@rem Find java.exe
if defined JAVA_HOME goto findJavaFromJavaHome
Expand Down
12 changes: 12 additions & 0 deletions settings.gradle.kts
Expand Up @@ -34,6 +34,18 @@ rootProject.children.forEach { project ->
}
}

plugins {
id("com.gradle.enterprise").version("3.3.4")
}

//Posting Build scans to https://scans.gradle.com
gradleEnterprise {
buildScan {
termsOfServiceUrl = "https://gradle.com/terms-of-service"
termsOfServiceAgree = "yes"
}
}

buildCache {
local {
isEnabled = !System.getenv().containsKey("CI")
Expand Down
Expand Up @@ -4,7 +4,7 @@ buildscript {
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${libraries.kotlin.version_1_3}"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${libraries.kotlin.version}"
}
}

Expand All @@ -21,6 +21,6 @@ dependencies {
testCompile project(":")
testCompile libraries.junit4

testCompile libraries.kotlin.stdlib_1_3
testCompile libraries.kotlin.releaseCoroutines
testCompile libraries.kotlin.stdlib
testCompile libraries.kotlin.coroutines
}

0 comments on commit 9df2012

Please sign in to comment.