Skip to content

Commit 1985eda

Browse files
authored
Merge pull request #671 from ancho/feature/maven-central-publishing
publish to sonatype nexus instead of bintray
2 parents 8b08d4b + 332aae2 commit 1985eda

File tree

7 files changed

+88
-132
lines changed

7 files changed

+88
-132
lines changed

BUILD.adoc

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -161,36 +161,62 @@ plugin:: https://docs.gradle.org/current/userguide/application_plugin.html
161161

162162
WARNING: Never add credentials to the repository
163163

164-
=== publish to bintray
164+
=== github release
165165

166-
You can publish to bintray with
166+
Bump desired project version in the projects `gradle.properties` file.
167+
168+
Like
167169

168170
----
169-
./gradlew bintrayUpload
171+
version = 2.7.0
170172
----
171173

172-
If you want to see what's going on without publishing
174+
Commit and push to origin at github.
173175

174176
----
175-
./gradlew -PbintrayDryRun=true bU --info
177+
./gradlew signArchives
178+
./gradlew githubRelease
176179
----
177180

178-
You need to add two properties to your local gradle.properties file (_~/.gradle/gradle.properties_).
181+
The task will create a tag for you and create a release. Additionaly it uploads the binary distribution and the corresponding signature to the release.
182+
183+
[NOTE]
184+
====
185+
You need to add some properties to your local gradle.properties file (_~/.gradle/gradle.properties_)
186+
187+
----
188+
github.token=<access token>
189+
github.release.owner=jbake-org
190+
github.release.repo=jbake
191+
----
179192
180-
bintrayUsername=username
181-
bintrayKey=secret
193+
It's also possible to dry-run this task. Execute `export GITHUB_RELEASE_DRY_RUN=true` in your terminal.
194+
====
195+
196+
plugin:: https://github.com/BreadMoirai/github-release-gradle-plugin
182197

183-
It's possible to change the organization and repository too.
184-
The properties are called _bintrayOrg_ and _bintrayRepo_.
185-
To publish to your private repository in an example repository run
198+
=== publish to nexus sonatype
199+
200+
You can publish to nexus with
186201

187202
----
188-
gradle -PbintrayOrg='' -PbintrayRepo=example bU
203+
./gradlew publishToSonatype
189204
----
190205

191-
The default values can be found in the _gradle.properties_ file at the root of this repository.
206+
The task will create a staging repository. You need to close and publish it manually.
207+
You can automate this process with the other tasks like `closeSonatypeStagingRepository` and `closeAndReleaseSonatypeStagingRepository`.
208+
209+
For more information see:
210+
211+
* https://github.com/gradle-nexus/publish-plugin
212+
* https://central.sonatype.org/pages/ossrh-guide.html
213+
214+
You need to add two properties to your local gradle.properties file (_~/.gradle/gradle.properties_).
215+
216+
sonatypeUsername=username
217+
sonatypePassword=secret
192218

193-
plugin:: https://plugins.gradle.org/plugin/com.jfrog.bintray
219+
plugin:: https://plugins.gradle.org/plugin/io.github.gradle-nexus.publish-plugin
194220

195221
=== publish to sdkman
196222

build.gradle

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
plugins {
22
id "eclipse"
33
id "idea"
4-
id "io.sdkman.vendors" version "2.0.0" apply false
5-
id "com.jfrog.bintray" version "1.8.5" apply false
6-
id "com.github.kt3k.coveralls" version "2.10.2" apply false
7-
id "org.sonarqube" version "3.1.1" apply false
8-
id 'com.github.ben-manes.versions' version '0.38.0'
9-
id "nebula.optional-base" version "5.0.3" apply false
4+
id "io.sdkman.vendors" version "2.0.0" apply false
5+
id "com.github.kt3k.coveralls" version "2.10.2" apply false
6+
id "org.sonarqube" version "3.1.1" apply false
7+
id 'com.github.ben-manes.versions' version '0.38.0'
8+
id "nebula.optional-base" version "5.0.3" apply false
9+
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
10+
id "com.github.breadmoirai.github-release" version "2.2.12"
1011
}
1112

1213
// common variables
@@ -68,9 +69,13 @@ subprojects {
6869

6970
// We do not publish any jars from the jbake-dist project
7071
if ( project.name != "jbake-dist" ) {
71-
apply from: "$rootDir/gradle/maven-publishing.gradle"
72-
apply from: "$rootDir/gradle/signing.gradle"
73-
apply from: "$rootDir/gradle/publishing.gradle"
72+
apply from: "$rootDir/gradle/maven-publishing.gradle"
73+
apply from: "$rootDir/gradle/publishing.gradle"
74+
apply from: "$rootDir/gradle/signing.gradle"
75+
}
76+
else {
77+
apply from: "$rootDir/gradle/signing.gradle"
78+
apply from: "$rootDir/gradle/github-releases.gradle"
7479
}
7580

7681
// add source and target compatibility for all JavaCompile tasks

gradle.properties

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,5 @@ mockitoVersion = 3.8.0
3939
jacocoVersion = 0.8.6
4040
grgitVersion = 1.6.0
4141

42-
bintrayDryRun = false
43-
bintrayOrg = jbake
44-
bintrayRepo = maven
45-
bintrayBinaryRepo = binary
46-
4742
org.gradle.caching=true
4843
org.gradle.parallel=true

gradle/github-releases.gradle

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
rootProject.ext {
2+
githubToken = project.hasProperty("github.token") ? project.getProperty("github.token") : System.getenv("GITHUBTOKEN")
3+
githubReleaseOwner = project.hasProperty("github.release.owner") ? getProperty("github.release.owner") : System.getenv("GITHUB_RELEASE_OWNER")
4+
githubReleaseRepo = project.hasProperty("github.release.repo") ? getProperty("github.release.repo") : System.getenv("GITHUB_RELEASE_REPO")
5+
githubReleaseDryRun = System.getenv("GITHUB_RELEASE_DRY_RUN") ?: false
6+
}
7+
8+
afterEvaluate {
9+
def name = project(':jbake-dist').tasks.getByName("distZip").archiveName
10+
def files = project(':jbake-dist').tasks.getByName("distZip").outputs.files.files
11+
if (!project.hasProperty('skipSigning')) {
12+
def signatureFile = project(':jbake-dist').tasks.getByName("signArchives").outputs.files.files.find { it.name.contains(name) }
13+
files << signatureFile
14+
}
15+
16+
githubRelease {
17+
token "$rootProject.githubToken" // This is your personal access token with Repo permissions
18+
// You get this from your user settings > developer settings > Personal Access Tokens
19+
owner "$rootProject.githubReleaseOwner"
20+
// default is the last part of your group. Eg group: "com.github.breadmoirai" => owner: "breadmoirai"
21+
repo "$rootProject.githubReleaseRepo" // by default this is set to your project name
22+
targetCommitish "master" // by default this is set to "master"
23+
draft false // by default this is false
24+
releaseAssets files
25+
// this points to which files you want to upload as assets with your release
26+
dryRun rootProject.githubReleaseDryRun as boolean
27+
// by default false; you can use this to see what actions would be taken without making a release
28+
}
29+
}

gradle/publishing.gradle

Lines changed: 3 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,103 +1,6 @@
1-
apply plugin: 'com.jfrog.bintray'
2-
3-
ext.bintrayUsername = project.hasProperty('bintrayUsername') ? bintrayUsername : ''
4-
ext.bintrayKey = project.hasProperty('bintrayKey') ? bintrayKey : ''
5-
6-
/*
7-
UGLY HACK to workaround gradle-bintray-plugin compatibility with Gradle 5+
8-
https://github.com/asciidoctor/asciidoctorj/issues/861
9-
https://github.com/bintray/gradle-bintray-plugin/issues/300
10-
WARNING: since the Groovy Gradle API is modified, this breaks build isolation when sharing a common Gradle daemon instance
11-
This works because gradle-bintray-plugin is using Groovy dynamic compilation hence it is affected by Groovy runtime meta-programming
12-
Tested with: Gradle 5.6.3 / gradle-bintray-plugin 1.8.4
13-
TODO: remove as soon as bintray/gradle-bintray-plugin#300 is fixed and integrated
14-
*/
15-
Signature.metaClass.getToSignArtifact = { ->
16-
return (delegate as Signature).source
17-
}
18-
19-
if (project.name == "jbake-dist") {
20-
21-
/**
22-
* jbake-dist specific bintray configuration.
23-
*
24-
* We just need the distribution packages from the project with signatures if they are present.
25-
* Notice the repository. It's a generic one. You can configure it with -PbintrayBinaryRepo=whatever
26-
*/
27-
bintray {
28-
user = bintrayUsername
29-
key = bintrayKey
30-
31-
if (!project.hasProperty('skipSigning')) {
32-
filesSpec {
33-
from distZip
34-
from distTar
35-
from signArchives.signatureFiles.filter { !it.name.endsWith(".jar.asc") }
36-
37-
into "."
38-
}
39-
40-
_bintrayRecordingCopy.dependsOn signArchives
41-
42-
} else {
43-
filesSpec {
44-
from distZip
45-
from distTar
46-
47-
into "."
48-
}
49-
}
50-
51-
dryRun = bintrayDryRun.toBoolean()
52-
53-
pkg {
54-
userOrg = bintrayOrg
55-
repo = bintrayBinaryRepo
56-
name = applicationName
57-
desc = project.description
58-
licenses = ['MIT']
59-
labels = ['jbake', 'site-generator']
60-
websiteUrl = project.website
61-
issueTrackerUrl = project.issues
62-
vcsUrl = project.vcs
63-
publicDownloadNumbers = true
64-
}
1+
nexusPublishing {
2+
repositories {
3+
sonatype()
654
}
66-
67-
} else {
68-
69-
bintray {
70-
user = bintrayUsername
71-
key = bintrayKey
72-
publications = ['mavenJava']
73-
74-
if (!project.hasProperty('skipSigning')) {
75-
filesSpec {
76-
from("${buildDir}/libs") {
77-
include '*.jar.asc'
78-
}
79-
from("${buildDir}/publications/mavenJava") {
80-
include 'pom-default.xml.asc'
81-
rename 'pom-default.xml.asc', "${project.name}-${project.version}.pom.asc"
82-
}
83-
into "."
84-
}
85-
}
86-
87-
dryRun = bintrayDryRun.toBoolean()
88-
pkg {
89-
userOrg = bintrayOrg
90-
repo = bintrayRepo
91-
name = project.name
92-
desc = project.description
93-
licenses = ['MIT']
94-
labels = ['jbake', 'site-generator']
95-
websiteUrl = project.website
96-
issueTrackerUrl = project.issues
97-
vcsUrl = project.vcs
98-
publicDownloadNumbers = true
99-
}
100-
}
101-
1025
}
1036

gradle/sdkman.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ sdkman {
99
candidate = "jbake"
1010
version = rootProject.version
1111
hashtag = "#JBake"
12-
url = "https://dl.bintray.com/jbake/binary/${distZip.archiveName}"
12+
url = "https://github.com/jbake-org/jbake/releases/download/v${project.version}/${distZip.archiveFileName.get()}"
1313
}
1414

1515
task distributionAvailable() {
@@ -31,4 +31,4 @@ task distributionAvailable() {
3131

3232
tasks.findAll{ it.name ==~ /sdk.*(Release|Version)/ }.each {
3333
it.dependsOn distributionAvailable
34-
}
34+
}

jbake-dist/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
apply from: "$rootDir/gradle/application.gradle"
22
apply from: "$rootDir/gradle/sdkman.gradle"
3-
apply from: "$rootDir/gradle/signing.gradle"
4-
apply from: "$rootDir/gradle/publishing.gradle"
53

64
description = "The binary distribution package that bundles JBake cli"
75

0 commit comments

Comments
 (0)