Skip to content

Add a simple JReleaser configuration #2223

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,3 @@ bin
# Vim
*.swp
*.swo

# Release scripts downloaded from hibernate/hibernate-release-scripts
.release
3 changes: 3 additions & 0 deletions .release/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# The folder into which we checkout our release scripts into
*
!.gitignore
7 changes: 0 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ ext {
logger.lifecycle "Vert.x SQL Client Version: " + project.vertxSqlClientVersion
}

// Publishing to Sonatype (Maven Central):
nexusPublishing {
repositories {
sonatype()
}
}

subprojects {
apply plugin: 'java-library'
apply plugin: 'com.diffplug.spotless'
Expand Down
28 changes: 18 additions & 10 deletions ci/release/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,10 @@ pipeline {
echo "Release was triggered automatically"

// Avoid doing an automatic release for commits from a release
def lastCommitter = sh(script: 'git show -s --format=\'%an\'', returnStdout: true)
def secondLastCommitter = sh(script: 'git show -s --format=\'%an\' HEAD~1', returnStdout: true)
def lastCommitter = sh(script: 'git show -s --format=\'%an\'', returnStdout: true).trim()
def secondLastCommitter = sh(script: 'git show -s --format=\'%an\' HEAD~1', returnStdout: true).trim()
echo "Last two commits were performed by '${lastCommitter}'/'${secondLastCommitter}'."

if (lastCommitter == 'Hibernate-CI' && secondLastCommitter == 'Hibernate-CI') {
print "INFO: Automatic release skipped because last commits were for the previous release"
currentBuild.result = 'ABORTED'
Expand Down Expand Up @@ -149,6 +151,7 @@ pipeline {
env.DEVELOPMENT_VERSION = developmentVersion.toString()
// Dry run is not supported at the moment
env.SCRIPT_OPTIONS = params.RELEASE_DRY_RUN ? "-d" : ""
env.JRELEASER_DRY_RUN = true

// Determine version id to check if Jira version exists
// This step doesn't work for Hibernate Reactive (the project has been created with a different type on JIRA)
Expand All @@ -172,11 +175,10 @@ pipeline {
// tags the version
// changes the version to the provided development version
withEnv([
"BRANCH=${env.GIT_BRANCH}",
// Increase the amount of memory for this part since asciidoctor doc rendering consumes a lot of metaspace
"GRADLE_OPTS=-Dorg.gradle.jvmargs='-Dlog4j2.disableJmx -Xmx4g -XX:MaxMetaspaceSize=768m -XX:+HeapDumpOnOutOfMemoryError -Duser.language=en -Duser.country=US -Duser.timezone=UTC -Dfile.encoding=UTF-8'"
]) {
sh ".release/scripts/prepare-release.sh ${env.PROJECT} ${env.RELEASE_VERSION} ${env.DEVELOPMENT_VERSION}"
sh ".release/scripts/prepare-release.sh -b ${env.GIT_BRANCH} -d ${env.DEVELOPMENT_VERSION} ${env.PROJECT} ${env.RELEASE_VERSION}"
}
}
}
Expand All @@ -193,11 +195,17 @@ pipeline {
configFile(fileId: 'release.config.ssh.knownhosts', targetLocation: "${env.HOME}/.ssh/known_hosts")
]) {
withCredentials([
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'ORG_GRADLE_PROJECT_sonatypePassword', usernameVariable: 'ORG_GRADLE_PROJECT_sonatypeUsername'),
file(credentialsId: 'release.gpg.private-key', variable: 'SIGNING_GPG_PRIVATE_KEY_PATH'),
string(credentialsId: 'release.gpg.passphrase', variable: 'SIGNING_GPG_PASSPHRASE'),
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default')
// TODO: Once we switch to maven-central publishing (from nexus2) we need to add a new credentials
// to use the following env variable names to set the user/password:
// - JRELEASER_MAVENCENTRAL_USERNAME
// - JRELEASER_MAVENCENTRAL_TOKEN
// Also use the new `credentialsId` for Maven Central, e.g.:
// usernamePassword(credentialsId: '???????', passwordVariable: 'JRELEASER_MAVENCENTRAL_TOKEN', usernameVariable: 'JRELEASER_MAVENCENTRAL_USERNAME'),
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'JRELEASER_NEXUS2_PASSWORD', usernameVariable: 'JRELEASER_NEXUS2_USERNAME'),
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default'),
file(credentialsId: 'release.gpg.private-key', variable: 'RELEASE_GPG_PRIVATE_KEY_PATH'),
string(credentialsId: 'release.gpg.passphrase', variable: 'JRELEASER_GPG_PASSPHRASE'),
string(credentialsId: 'Hibernate-CI.github.com', variable: 'JRELEASER_GITHUB_TOKEN')
]) {
sshagent(['ed25519.Hibernate-CI.github.com', 'hibernate.filemgmt.jboss.org', 'hibernate-ci.frs.sourceforge.net']) {
// performs documentation upload and Sonatype release
Expand All @@ -217,4 +225,4 @@ pipeline {
}
}
}
}
}
38 changes: 30 additions & 8 deletions ci/snapshot-publish.Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ if (currentBuild.getBuildCauses().toString().contains('BranchIndexingCause')) {
return
}

def checkoutReleaseScripts() {
dir('.release/scripts') {
checkout scmGit(branches: [[name: '*/main']], extensions: [],
userRemoteConfigs: [[credentialsId: 'ed25519.Hibernate-CI.github.com',
url: 'https://github.com/hibernate/hibernate-release-scripts.git']])
}
}

pipeline {
agent {
label 'Release'
Expand All @@ -30,13 +38,27 @@ pipeline {
}
stage('Publish') {
steps {
withCredentials([
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
usernamePassword(credentialsId: 'ossrh.sonatype.org', usernameVariable: 'ORG_GRADLE_PROJECT_sonatypeUsername', passwordVariable: 'ORG_GRADLE_PROJECT_sonatypePassword'),
file(credentialsId: 'release.gpg.private-key', variable: 'SIGNING_GPG_PRIVATE_KEY_PATH'),
string(credentialsId: 'release.gpg.passphrase', variable: 'SIGNING_GPG_PASSPHRASE')
]) {
sh "./gradlew clean publish --no-scan"
script {
withCredentials([
// https://github.com/gradle-nexus/publish-plugin#publishing-to-maven-central-via-sonatype-ossrh
// TODO: Once we switch to maven-central publishing (from nexus2) we need to add a new credentials
// to use the following env variable names to set the user/password:
// - JRELEASER_MAVENCENTRAL_USERNAME
// - JRELEASER_MAVENCENTRAL_TOKEN
// Also use the new `credentialsId` for Maven Central, e.g.:
// usernamePassword(credentialsId: '???????', passwordVariable: 'JRELEASER_MAVENCENTRAL_TOKEN', usernameVariable: 'JRELEASER_MAVENCENTRAL_USERNAME'),
usernamePassword(credentialsId: 'ossrh.sonatype.org', passwordVariable: 'JRELEASER_NEXUS2_PASSWORD', usernameVariable: 'JRELEASER_NEXUS2_USERNAME'),
gitUsernamePassword(credentialsId: 'username-and-token.Hibernate-CI.github.com', gitToolName: 'Default'),
string(credentialsId: 'Hibernate-CI.github.com', variable: 'JRELEASER_GITHUB_TOKEN')
]) {
checkoutReleaseScripts()
def version = sh(
script: ".release/scripts/determine-current-version.sh orm",
returnStdout: true
).trim()
echo "Current version: '${version}'"
sh "bash -xe .release/scripts/snapshot-deploy.sh reactive ${version}"
}
}
}
}
Expand All @@ -48,4 +70,4 @@ pipeline {
}
}
}
}
}
59 changes: 59 additions & 0 deletions jreleaser.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
project:
languages:
java:
groupId: org.hibernate.reactive

release:
github:
skipTag: true
skipRelease: true
tagName: '{{projectVersion}}'

# File signing is always active
signing:
mode: COMMAND
active: RELEASE
armored: true

deploy:
maven:
# TODO: Remove the entire nexus2 section when switching to maven central publishing (see below):
nexus2:
maven-central:
active: RELEASE
url: https://oss.sonatype.org/service/local
snapshotUrl: https://oss.sonatype.org/content/repositories/snapshots/
closeRepository: true
releaseRepository: false
stagingRepositories:
- build/staging-deploy/maven
maven-central-snapshot:
active: SNAPSHOT
url: https://oss.sonatype.org/service/local
snapshotUrl: https://oss.sonatype.org/content/repositories/snapshots/
closeRepository: true
releaseRepository: true
javadocJar: false
sign: false
stagingRepositories:
- build/staging-deploy/maven
mavenCentral:
maven-central:
# TODO: Change to RELEASE once switching to Maven-Central:
# Note, this is an untested configuration, hence might need further adjustments
active: NEVER
url: https://central.sonatype.com/api/v1/publisher
snapshotSupported: false
applyMavenCentralRules: true
stagingRepositories:
- build/staging-deploy/maven
maven-central-snapshot:
# TODO: Change to SNAPSHOT once switching to Maven-Central:
active: NEVER
url: https://central.sonatype.com/api/v1/publisher
snapshotSupported: true
applyMavenCentralRules: true
javadocJar: false
sign: false
stagingRepositories:
- build/staging-deploy/maven
96 changes: 4 additions & 92 deletions publish.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'java'
apply plugin: 'maven-publish'
apply plugin: 'signing'

// Java / publishing

Expand Down Expand Up @@ -75,97 +74,10 @@ publishing {
}
}
}
}


// Signing

var signingExtension = project.getExtensions().getByType(SigningExtension) as SigningExtension

var publishingExtension = project.getExtensions().getByType(PublishingExtension) as PublishingExtension
signingExtension.sign publishingExtension.publications.publishedArtifacts

var signingKey = resolveSigningKey()
var signingPassphrase = resolveSigningPassphrase()
signingExtension.useInMemoryPgpKeys(signingKey, signingPassphrase)

gradle.taskGraph.whenReady { TaskExecutionGraph graph ->
boolean wasPublishingRequested = false

graph.allTasks.each {task ->
if ( task instanceof PublishToMavenRepository ) {
logger.lifecycle( "Found PublishToMavenRepository task : {}", task.path )
wasPublishingRequested = true
repositories {
maven {
name = "staging"
url = rootProject.layout.buildDirectory.dir("staging-deploy${File.separator}maven")
}
}

if ( wasPublishingRequested ) {
def publishUser = resolvePublishUser()
def publishPass = resolvePublishPass()
if ( publishUser == null || publishPass == null ) {
throw new RuntimeException( "Cannot perform publishing to OSSRH without credentials." )
}

logger.lifecycle "Publishing {} : {} : {}", project.group, project.name, project.version

// require signing if publishing to OSSRH
signingExtension.required = true
}
else if ( signingKey == null || signingPassphrase == null ) {
tasks.withType( Sign ).each { t-> t.enabled = false }
}
}


static String resolveSigningKey() {
var key = System.getenv().get( "SIGNING_GPG_PRIVATE_KEY" )
if ( key != null ) {
return key
}

var keyFile = System.getenv().get( "SIGNING_GPG_PRIVATE_KEY_PATH" )
if ( keyFile != null ) {
return new File( keyFile ).text
}

return null
}

static String resolveSigningPassphrase() {
return System.getenv().get( "SIGNING_GPG_PASSPHRASE" )
}

String resolvePublishUser() {
var envVar = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypeUsername" )
if ( envVar != null ) {
return envVar
}

def projectProp = projectPropOrNull( "sonatypeUsername" )
if ( projectProp != null ) {
return projectProp
}

return null
}

String resolvePublishPass() {
var envVar = System.getenv().get( "ORG_GRADLE_PROJECT_sonatypePassword" )
if ( envVar != null ) {
return envVar
}

def projectProp = projectPropOrNull( "sonatypePassword" )
if ( projectProp != null ) {
return projectProp
}

return null
}

String projectPropOrNull(String name) {
if ( project.hasProperty( name ) ) {
return project.findProperty( name )
}
return null;
}
1 change: 0 additions & 1 deletion release/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ void updateVersionFile(var version) {

def publishReleaseArtifactsTask = tasks.register( 'publishReleaseArtifacts' ) {
dependsOn uploadDocumentationTask
dependsOn ":hibernate-reactive-core:publishToSonatype"

mustRunAfter gitPreparationForReleaseTask
}
Expand Down
Loading