Skip to content

Commit

Permalink
Merge pull request mockito#2069 from mockito/shipkit
Browse files Browse the repository at this point in the history
Migrated to new Shipkit libraries
  • Loading branch information
mockitoguy authored Oct 28, 2020
2 parents 5570aba + c1a7956 commit 05eef83
Show file tree
Hide file tree
Showing 6 changed files with 160 additions and 85 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ install:
- true

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 build idea -s && ./gradlew ciPerformRelease
# To validate changes, we run building and bintray upload in dry run, and idea task. This happens on every build, even PRs.
# To publish, we perform github release and perform bintray upload (no dry run). This only for main branch builds.
- >
./gradlew build bintrayUpload idea --scan -PbintrayDryRun
&& if [ -z "$SKIP_RELEASE" ] && [ "$TRAVIS_PULL_REQUEST" = "false" ] && [ "$TRAVIS_BRANCH" = "release/3.x" ];
then ./gradlew bintrayUpload githubRelease --scan; fi
after_success:
#Generates coverage report:
Expand Down
14 changes: 5 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ buildscript {
classpath 'gradle.plugin.nl.javadude.gradle.plugins:license-gradle-plugin:0.14.0'
classpath 'net.ltgt.gradle:gradle-errorprone-plugin:1.2.1'

//Using buildscript.classpath so that we can resolve shipkit from maven local, during local testing
classpath 'org.shipkit:shipkit:2.1.6'
//Using buildscript.classpath so that we can resolve plugins from maven local, during local testing
classpath "org.shipkit:shipkit-auto-version:0.0.+"
classpath "org.shipkit:shipkit-changelog:0.0.+"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+"

classpath 'com.google.googlejavaformat:google-java-format:1.8'
}
Expand All @@ -29,13 +31,7 @@ description = 'Mockito mock objects library core API and implementation'
apply plugin: 'base'
archivesBaseName = "mockito-core"

apply plugin: "org.shipkit.java"
allprojects {
plugins.withId("java") {
//Only upload specific modules we select
bintrayUpload.enabled = false
}
}
apply from: 'gradle/shipkit.gradle'

apply from: 'gradle/root/ide.gradle'
apply from: 'gradle/root/gradle-fix.gradle'
Expand Down
4 changes: 2 additions & 2 deletions gradle/java-library.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ if (!archivesBaseName.startsWith("mockito-")) {
archivesBaseName = "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
}

bintrayUpload.enabled = true

sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand Down
126 changes: 126 additions & 0 deletions gradle/java-publication.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
//Sources/javadoc artifacts required by Maven module publications
def licenseSpec = copySpec {
from project.rootDir
include "LICENSE"
}

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

task javadocJar(type: Jar, dependsOn: javadoc) {
classifier = 'javadoc'
from tasks.javadoc
with licenseSpec
}

jar {
with licenseSpec
}

artifacts {
archives sourcesJar
archives javadocJar
}

//Gradle Maven publishing plugin configuration (https://docs.gradle.org/current/userguide/publishing_maven.html)
apply plugin: "maven-publish"
publishing {
publications {
javaLibrary(MavenPublication) { //name of the publication
from components.java
artifact sourcesJar
artifact javadocJar

artifactId = project.archivesBaseName

pom {
name = artifactId
description = project.description

//Gradle does not write 'jar' packaging to the pom (unlike other packaging types).
//This is OK because 'jar' is implicit/default:
// https://maven.apache.org/guides/introduction/introduction-to-the-pom.html#minimal-pom
packaging = project.tasks.jar.extension

url = "https://github.com/mockito/mockito"
licenses {
license {
name = 'The MIT License'
url = 'https://github.com/mockito/mockito/blob/release/3.x/LICENSE'
distribution = 'repo'
}
}
developers {
['mockitoguy:Szczepan Faber', 'bric3:Brice Dutheil', 'raphw:Rafael Winterhalter',
'TimvdLippe:Tim van der Lippe'].each { devData ->
developer {
def devInfo = devData.split(':')
id = devInfo[0]
name = devInfo[1]
url = 'https://github.com/' + devInfo[0]
roles = ["Core developer"]
}
}
}
scm {
url = 'https://github.com/mockito/mockito.git'
}
issueManagement {
url = 'https://github.com/mockito/mockito/issues'
system = 'GitHub issues'
}
ciManagement {
url = 'https://travis-ci.org/mockito/mockito'
system = 'TravisCI'
}
}
}
}

//useful for testing - running "publish" will create artifacts/pom in a local dir
repositories { maven { url = "$buildDir/repo" } }
}

//fleshes out problems with Maven pom generation when building
tasks.build.dependsOn("publishJavaLibraryPublicationToMavenLocal")

//Bintray Gradle plugin configuration (https://github.com/bintray/gradle-bintray-plugin)
//Plugin jars are added to the buildscript classpath in the root build.gradle file
apply plugin: "com.jfrog.bintray"

bintray {
//We need to use some user id here, because the Bintray key is associated with the user
//However, any user id is good, so longer the user has necessary privileges to the repository
user = 'szczepiq' //https://bintray.com/szczepiq
key = System.getenv('BINTRAY_API_KEY')
publish = true //can be changed to 'false' for testing
dryRun = project.hasProperty("bintrayDryRun")
publications = ['javaLibrary']

pkg {
repo = 'maven' //https://bintray.com/mockito/maven
userOrg = 'mockito' //https://bintray.com/mockito

//See our Bintray packages at https://bintray.com/mockito/maven
name = project.rootProject.ext.mavenCentralRelease? "mockito" : "mockito-development"

licenses = ['MIT']
labels = ['mocks', 'tdd', 'unit tests']
vcsUrl = "https://github.com/mockito/mockito.git"

version {
name = project.version
vcsTag = "v$project.version"

//Notable versions are automatically synced to Maven Central repository (https://oss.sonatype.org/)
mavenCentralSync {
sync = project.rootProject.ext.mavenCentralRelease
user = System.env.NEXUS_TOKEN_USER
password = System.env.NEXUS_TOKEN_PWD
}
}
}
}
84 changes: 19 additions & 65 deletions gradle/shipkit.gradle
Original file line number Diff line number Diff line change
@@ -1,73 +1,27 @@
shipkit {
gitHub.repository = "mockito/mockito"
gitHub.readOnlyAuthToken = "a0a4c0f41c200f7c653323014d6a72a127764e17"

releaseNotes.file = "doc/release-notes/official.md"
releaseNotes.labelMapping = [
'1.* incompatible': 'Incompatible changes with previous major version (v1.x)',
'java-9': "Java 9 support",
'java-8': "Java 8 support",
'new feature': "New features",
'BDD': 'Behavior-Driven Development support',
'bug': "Bugfixes",
'enhancement': "Enhancements",
'android': "Android support",
'docs': 'Documentation'
]

git.releasableBranchRegex = "release/.+" // 'release/2.x', 'release/3.x', etc.

def buildNo = System.getenv("TRAVIS_BUILD_NUMBER")
git.commitMessagePostfix = buildNo? "by CI build $buildNo\n\n[ci skip-release]" : "by local build\n\n[ci skip-release]"
apply plugin: "org.shipkit.shipkit-auto-version"
apply plugin: "org.shipkit.shipkit-changelog"
apply plugin: "org.shipkit.shipkit-gh-release"

tasks.named("generateChangelog") {
previousRevision = "v" + project.ext.'shipkit-auto-version.previous-version'
readOnlyToken = "a0a4c0f41c200f7c653323014d6a72a127764e17"
repository = "mockito/mockito"
}

team.developers = ['mockitoguy:Szczepan Faber', 'bric3:Brice Dutheil', 'raphw:Rafael Winterhalter', 'TimvdLippe:Tim van der Lippe']
tasks.named("githubRelease") {
def genTask = tasks.named("generateChangelog").get()
dependsOn genTask
repository = genTask.repository
changelog = genTask.outputFile
writeToken = System.getenv("GH_WRITE_TOKEN")
}

/**
* Mockito team does not publish to Maven Central every release as requested by the community.
* We publish to maven central only some versions. All versions are published to Bintray on every change.
* See https://github.com/mockito/mockito/issues/911
*/
boolean centralRelease = shouldReleaseToCentral(project)

afterEvaluate {
//using afterEvaluate because 'assertReleaseNeeded' task is added after 'shipkit.gradle' file is evaluated by Gradle
[assertReleaseNeeded, releaseNeeded].each {
it.skipComparePublications = centralRelease
}
}

allprojects {
plugins.withId("org.shipkit.bintray") {
bintray {
pkg {
repo = 'maven' //https://bintray.com/mockito/maven

//We need to use some user id here, because the Bintray key is associated with the user
//However, any user id is good, so longer the user has necessary privileges to the repository
user = 'szczepiq' //https://bintray.com/szczepiq

userOrg = 'mockito' //https://bintray.com/mockito
name = 'mockito' //https://bintray.com/mockito/maven/mockito
licenses = ['MIT']
labels = ['mocks', 'tdd', 'unit tests']
publish = true //can be changed to 'false' for testing

//See our Bintray packages at https://bintray.com/mockito/maven
name = centralRelease? "mockito" : "mockito-development"

version {
//Notable versions are automatically synced to Maven Central repository (https://oss.sonatype.org/)
mavenCentralSync {
sync = centralRelease
user = System.env.NEXUS_TOKEN_USER
password = System.env.NEXUS_TOKEN_PWD
}
}
}
}
}
}
ext.mavenCentralRelease = shouldReleaseToCentral(project)

/**
* Finds out if we should release to Maven Central.
Expand All @@ -77,13 +31,13 @@ static boolean shouldReleaseToCentral(project) {
boolean centralReleaseByCommit = System.getenv("TRAVIS_COMMIT_MESSAGE")?.contains("[ci maven-central-release]")
boolean centralReleaseByProjectProperty = project.hasProperty("maven-central-release")
boolean centralRelease = centralReleaseByCommit || centralReleaseByProjectProperty
def message = """Release was using following settings:
def message = """Bintray publish was using following settings:
- commit message contains '[ci maven-central-release]': $centralReleaseByCommit
- project property 'maven-central-release' exists: $centralReleaseByProjectProperty
- Maven Central release is enabled: $centralRelease"""
project.logger.info(message)
project.afterEvaluate {
project.tasks.performRelease.doLast { logger.lifecycle(message) }
project.tasks.bintrayPublish.doLast { logger.lifecycle(message) }
}
return centralRelease
}
}
7 changes: 2 additions & 5 deletions version.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
# Currently building Mockito version
version=3.6.1

# Previous version used to generate release notes delta
previousVersion=3.6.0
//Used by Shipkit Auto Version Gradle plugin: https://github.com/shipkit/shipkit-auto-version
version=3.6.*

0 comments on commit 05eef83

Please sign in to comment.