Skip to content

Commit

Permalink
Merge pull request #671 from ancho/feature/maven-central-publishing
Browse files Browse the repository at this point in the history
publish to sonatype nexus instead of bintray
  • Loading branch information
jonbullock authored Apr 12, 2021
2 parents 8b08d4b + 332aae2 commit 1985eda
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 132 deletions.
54 changes: 40 additions & 14 deletions BUILD.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -161,36 +161,62 @@ plugin:: https://docs.gradle.org/current/userguide/application_plugin.html

WARNING: Never add credentials to the repository

=== publish to bintray
=== github release

You can publish to bintray with
Bump desired project version in the projects `gradle.properties` file.

Like

----
./gradlew bintrayUpload
version = 2.7.0
----

If you want to see what's going on without publishing
Commit and push to origin at github.

----
./gradlew -PbintrayDryRun=true bU --info
./gradlew signArchives
./gradlew githubRelease
----

You need to add two properties to your local gradle.properties file (_~/.gradle/gradle.properties_).
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.

[NOTE]
====
You need to add some properties to your local gradle.properties file (_~/.gradle/gradle.properties_)
----
github.token=<access token>
github.release.owner=jbake-org
github.release.repo=jbake
----
bintrayUsername=username
bintrayKey=secret
It's also possible to dry-run this task. Execute `export GITHUB_RELEASE_DRY_RUN=true` in your terminal.
====

plugin:: https://github.com/BreadMoirai/github-release-gradle-plugin

It's possible to change the organization and repository too.
The properties are called _bintrayOrg_ and _bintrayRepo_.
To publish to your private repository in an example repository run
=== publish to nexus sonatype

You can publish to nexus with

----
gradle -PbintrayOrg='' -PbintrayRepo=example bU
./gradlew publishToSonatype
----

The default values can be found in the _gradle.properties_ file at the root of this repository.
The task will create a staging repository. You need to close and publish it manually.
You can automate this process with the other tasks like `closeSonatypeStagingRepository` and `closeAndReleaseSonatypeStagingRepository`.

For more information see:

* https://github.com/gradle-nexus/publish-plugin
* https://central.sonatype.org/pages/ossrh-guide.html

You need to add two properties to your local gradle.properties file (_~/.gradle/gradle.properties_).

sonatypeUsername=username
sonatypePassword=secret

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

=== publish to sdkman

Expand Down
23 changes: 14 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
plugins {
id "eclipse"
id "idea"
id "io.sdkman.vendors" version "2.0.0" apply false
id "com.jfrog.bintray" version "1.8.5" apply false
id "com.github.kt3k.coveralls" version "2.10.2" apply false
id "org.sonarqube" version "3.1.1" apply false
id 'com.github.ben-manes.versions' version '0.38.0'
id "nebula.optional-base" version "5.0.3" apply false
id "io.sdkman.vendors" version "2.0.0" apply false
id "com.github.kt3k.coveralls" version "2.10.2" apply false
id "org.sonarqube" version "3.1.1" apply false
id 'com.github.ben-manes.versions' version '0.38.0'
id "nebula.optional-base" version "5.0.3" apply false
id "io.github.gradle-nexus.publish-plugin" version "1.0.0"
id "com.github.breadmoirai.github-release" version "2.2.12"
}

// common variables
Expand Down Expand Up @@ -68,9 +69,13 @@ subprojects {

// We do not publish any jars from the jbake-dist project
if ( project.name != "jbake-dist" ) {
apply from: "$rootDir/gradle/maven-publishing.gradle"
apply from: "$rootDir/gradle/signing.gradle"
apply from: "$rootDir/gradle/publishing.gradle"
apply from: "$rootDir/gradle/maven-publishing.gradle"
apply from: "$rootDir/gradle/publishing.gradle"
apply from: "$rootDir/gradle/signing.gradle"
}
else {
apply from: "$rootDir/gradle/signing.gradle"
apply from: "$rootDir/gradle/github-releases.gradle"
}

// add source and target compatibility for all JavaCompile tasks
Expand Down
5 changes: 0 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,5 @@ mockitoVersion = 3.8.0
jacocoVersion = 0.8.6
grgitVersion = 1.6.0

bintrayDryRun = false
bintrayOrg = jbake
bintrayRepo = maven
bintrayBinaryRepo = binary

org.gradle.caching=true
org.gradle.parallel=true
29 changes: 29 additions & 0 deletions gradle/github-releases.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
rootProject.ext {
githubToken = project.hasProperty("github.token") ? project.getProperty("github.token") : System.getenv("GITHUBTOKEN")
githubReleaseOwner = project.hasProperty("github.release.owner") ? getProperty("github.release.owner") : System.getenv("GITHUB_RELEASE_OWNER")
githubReleaseRepo = project.hasProperty("github.release.repo") ? getProperty("github.release.repo") : System.getenv("GITHUB_RELEASE_REPO")
githubReleaseDryRun = System.getenv("GITHUB_RELEASE_DRY_RUN") ?: false
}

afterEvaluate {
def name = project(':jbake-dist').tasks.getByName("distZip").archiveName
def files = project(':jbake-dist').tasks.getByName("distZip").outputs.files.files
if (!project.hasProperty('skipSigning')) {
def signatureFile = project(':jbake-dist').tasks.getByName("signArchives").outputs.files.files.find { it.name.contains(name) }
files << signatureFile
}

githubRelease {
token "$rootProject.githubToken" // This is your personal access token with Repo permissions
// You get this from your user settings > developer settings > Personal Access Tokens
owner "$rootProject.githubReleaseOwner"
// default is the last part of your group. Eg group: "com.github.breadmoirai" => owner: "breadmoirai"
repo "$rootProject.githubReleaseRepo" // by default this is set to your project name
targetCommitish "master" // by default this is set to "master"
draft false // by default this is false
releaseAssets files
// this points to which files you want to upload as assets with your release
dryRun rootProject.githubReleaseDryRun as boolean
// by default false; you can use this to see what actions would be taken without making a release
}
}
103 changes: 3 additions & 100 deletions gradle/publishing.gradle
Original file line number Diff line number Diff line change
@@ -1,103 +1,6 @@
apply plugin: 'com.jfrog.bintray'

ext.bintrayUsername = project.hasProperty('bintrayUsername') ? bintrayUsername : ''
ext.bintrayKey = project.hasProperty('bintrayKey') ? bintrayKey : ''

/*
UGLY HACK to workaround gradle-bintray-plugin compatibility with Gradle 5+
https://github.com/asciidoctor/asciidoctorj/issues/861
https://github.com/bintray/gradle-bintray-plugin/issues/300
WARNING: since the Groovy Gradle API is modified, this breaks build isolation when sharing a common Gradle daemon instance
This works because gradle-bintray-plugin is using Groovy dynamic compilation hence it is affected by Groovy runtime meta-programming
Tested with: Gradle 5.6.3 / gradle-bintray-plugin 1.8.4
TODO: remove as soon as bintray/gradle-bintray-plugin#300 is fixed and integrated
*/
Signature.metaClass.getToSignArtifact = { ->
return (delegate as Signature).source
}

if (project.name == "jbake-dist") {

/**
* jbake-dist specific bintray configuration.
*
* We just need the distribution packages from the project with signatures if they are present.
* Notice the repository. It's a generic one. You can configure it with -PbintrayBinaryRepo=whatever
*/
bintray {
user = bintrayUsername
key = bintrayKey

if (!project.hasProperty('skipSigning')) {
filesSpec {
from distZip
from distTar
from signArchives.signatureFiles.filter { !it.name.endsWith(".jar.asc") }

into "."
}

_bintrayRecordingCopy.dependsOn signArchives

} else {
filesSpec {
from distZip
from distTar

into "."
}
}

dryRun = bintrayDryRun.toBoolean()

pkg {
userOrg = bintrayOrg
repo = bintrayBinaryRepo
name = applicationName
desc = project.description
licenses = ['MIT']
labels = ['jbake', 'site-generator']
websiteUrl = project.website
issueTrackerUrl = project.issues
vcsUrl = project.vcs
publicDownloadNumbers = true
}
nexusPublishing {
repositories {
sonatype()
}

} else {

bintray {
user = bintrayUsername
key = bintrayKey
publications = ['mavenJava']

if (!project.hasProperty('skipSigning')) {
filesSpec {
from("${buildDir}/libs") {
include '*.jar.asc'
}
from("${buildDir}/publications/mavenJava") {
include 'pom-default.xml.asc'
rename 'pom-default.xml.asc', "${project.name}-${project.version}.pom.asc"
}
into "."
}
}

dryRun = bintrayDryRun.toBoolean()
pkg {
userOrg = bintrayOrg
repo = bintrayRepo
name = project.name
desc = project.description
licenses = ['MIT']
labels = ['jbake', 'site-generator']
websiteUrl = project.website
issueTrackerUrl = project.issues
vcsUrl = project.vcs
publicDownloadNumbers = true
}
}

}

4 changes: 2 additions & 2 deletions gradle/sdkman.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ sdkman {
candidate = "jbake"
version = rootProject.version
hashtag = "#JBake"
url = "https://dl.bintray.com/jbake/binary/${distZip.archiveName}"
url = "https://github.com/jbake-org/jbake/releases/download/v${project.version}/${distZip.archiveFileName.get()}"
}

task distributionAvailable() {
Expand All @@ -31,4 +31,4 @@ task distributionAvailable() {

tasks.findAll{ it.name ==~ /sdk.*(Release|Version)/ }.each {
it.dependsOn distributionAvailable
}
}
2 changes: 0 additions & 2 deletions jbake-dist/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
apply from: "$rootDir/gradle/application.gradle"
apply from: "$rootDir/gradle/sdkman.gradle"
apply from: "$rootDir/gradle/signing.gradle"
apply from: "$rootDir/gradle/publishing.gradle"

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

Expand Down

0 comments on commit 1985eda

Please sign in to comment.