Skip to content

Commit e0725ed

Browse files
Szczepan Fabermockitoguy
authored andcommitted
Enabled releases to Central
1 parent afc0822 commit e0725ed

File tree

3 files changed

+95
-42
lines changed

3 files changed

+95
-42
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,13 @@ jobs:
7272
java-version: 8
7373

7474
- name: Build and publish to Bintray/MavenCentral
75-
run: ./gradlew # TODO fix the release build
75+
run: ./gradlew writeActualVersion
76+
&& export PROJECT_VERSION=`cat version.actual`
77+
&& ./build.sh
78+
&& ./gradlew publishToSonatype githubRelease # closeAndReleaseStagingRepository releaseSummary
7679
env:
80+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
7781
NEXUS_TOKEN_USER: ${{secrets.NEXUS_TOKEN_USER}}
7882
NEXUS_TOKEN_PWD: ${{secrets.NEXUS_TOKEN_PWD}}
83+
PGP_KEY: ${{secrets.PGP_KEY}}
84+
PGP_PWD: ${{secrets.PGP_PWD}}

build.gradle

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,99 @@ buildscript {
88
//Using buildscript.classpath so that we can resolve plugins from maven local, during local testing
99
classpath "org.shipkit:shipkit-auto-version:1.+"
1010
classpath "org.shipkit:shipkit-changelog:1.+"
11-
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.+"
11+
classpath "io.github.gradle-nexus:publish-plugin:1.1.0"
1212
}
1313
}
1414

15+
group = 'org.mockito'
16+
1517
apply from: "gradle/shipkit.gradle"
1618

17-
task build(type: Exec) {
18-
commandLine "./build.sh"
19-
environment "PROJECT_VERSION", version
19+
apply plugin: "maven-publish"
20+
21+
def pubNames = []
22+
publishing {
23+
publications {
24+
int i = 1
25+
[
26+
"mockito-scala_2.11", "mockito-scala_2.12", "mockito-scala_2.13",
27+
"mockito-scala-cats_2.11", "mockito-scala-cats_2.12", "mockito-scala-cats_2.13",
28+
"mockito-scala-scalatest_2.11", "mockito-scala-scalatest_2.12", "mockito-scala-scalatest_2.13",
29+
"mockito-scala-scalaz_2.11", "mockito-scala-scalaz_2.12", "mockito-scala-scalaz_2.13",
30+
"mockito-scala-specs2_2.11", "mockito-scala-specs2_2.12", "mockito-scala-specs2_2.13",
31+
].each {pub ->
32+
String pubName = "publication${i++}"
33+
pubNames << pubName
34+
"$pubName"(MavenPublication) {
35+
groupId = 'org.mockito'
36+
artifactId = pub
37+
38+
def jarFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}.jar")
39+
artifact jarFile
40+
41+
def srcFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}-sources.jar")
42+
artifact source: srcFile, classifier: "sources"
43+
44+
def jFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}-javadoc.jar")
45+
artifact source: jFile, classifier: "javadoc"
46+
47+
pom {
48+
withXml {
49+
def xml = asString()
50+
xml.setLength(0)
51+
def pomFile = file("target/dist/org/mockito/${pub}/${version}/${pub}-${version}.pom")
52+
assert pomFile.file
53+
xml.append(pomFile.text)
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
61+
apply plugin: 'signing' //https://docs.gradle.org/current/userguide/signing_plugin.html
62+
signing {
63+
if (System.getenv("PGP_KEY")) {
64+
useInMemoryPgpKeys(System.getenv("PGP_KEY"), System.getenv("PGP_PWD"))
65+
pubNames.each {
66+
sign publishing.publications."$it"
67+
}
68+
}
69+
}
70+
71+
apply plugin: "io.github.gradle-nexus.publish-plugin"
72+
73+
nexusPublishing {
74+
repositories {
75+
if (System.getenv("NEXUS_TOKEN_PWD")) {
76+
sonatype {
77+
// Publishing to: https://s01.oss.sonatype.org (faster instance)
78+
nexusUrl = uri("https://s01.oss.sonatype.org/service/local/")
79+
snapshotRepositoryUrl = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
80+
81+
username = System.getenv("NEXUS_TOKEN_USER")
82+
password = System.getenv("NEXUS_TOKEN_PWD")
83+
}
84+
}
85+
}
2086
}
2187

22-
task clean(type: Exec) {
23-
commandLine "./clean.sh"
24-
environment "PROJECT_VERSION", version
88+
def isSnapshot = version.endsWith("-SNAPSHOT")
89+
90+
if (isSnapshot) {
91+
println "Building a -SNAPSHOT version (Github release and Maven Central tasks are skipped)"
92+
tasks.named("githubRelease") {
93+
//snapshot versions do not produce changelog / Github releases
94+
enabled = false
95+
}
96+
tasks.named("closeAndReleaseStagingRepository") {
97+
//snapshot binaries are available in Sonatype without the need to close the staging repo
98+
enabled = false
99+
}
25100
}
101+
102+
task writeActualVersion {
103+
doLast {
104+
file("version.actual") << "$version"
105+
}
106+
}

gradle/shipkit.gradle

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,37 +16,3 @@ tasks.named("githubRelease") {
1616
githubToken = System.getenv("GITHUB_TOKEN")
1717
newTagRevision = System.getenv("GITHUB_SHA")
1818
}
19-
20-
apply plugin: 'com.jfrog.bintray'
21-
22-
//Bintray configuration is handled by JFrog Bintray Gradle Plugin
23-
//For reference see the official documentation: https://github.com/bintray/gradle-bintray-plugin
24-
bintray {
25-
26-
key = System.getenv("BINTRAY_API_KEY")
27-
28-
pkg {
29-
repo = 'maven'
30-
user = 'szczepiq'
31-
name = 'mockito-scala'
32-
userOrg = 'mockito'
33-
licenses = ['MIT']
34-
labels = ['mocks', 'tdd', 'unit tests']
35-
publish = true // can be changed to 'false' for testing
36-
dryRun = project.hasProperty("bintrayDryRun")
37-
38-
filesSpec {
39-
// all contents of this directory will be uploaded to Bintray
40-
from fileTree("target/dist")
41-
into '.'
42-
}
43-
44-
version {
45-
mavenCentralSync {
46-
//sync = true // enable after #351 is fixed. In the meantime, we will publish to Maven Central from Bintray UI
47-
user = System.env.NEXUS_TOKEN_USER
48-
password = System.env.NEXUS_TOKEN_PWD
49-
}
50-
}
51-
}
52-
}

0 commit comments

Comments
 (0)