hibernate-orm/gradle/published-java-module.gradle

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

257 lines
7.1 KiB
Groovy
Raw Normal View History

/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later
* See the lgpl.txt file in the root directory or http://www.gnu.org/licenses/lgpl-2.1.html
*/
apply from: rootProject.file( 'gradle/releasable.gradle' )
apply from: rootProject.file( 'gradle/java-module.gradle' )
apply from: rootProject.file( 'gradle/publishing-pom.gradle' )
apply plugin: 'signing'
// Make sure that the publishReleaseArtifacts task of the release module runs the release task of this sub module
tasks.getByPath( ':release:publishReleaseArtifacts' ).dependsOn tasks.release
configurations {
javadocSources {
description 'Used to aggregate javadocs for the whole project'
}
}
dependencies {
javadocSources sourceSets.main.allJava
}
2022-02-07 09:02:13 -05:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Publishing
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
2022-02-07 09:02:13 -05:00
// main publication
2018-02-01 15:00:37 -05:00
publishedArtifacts {
from components.java
}
2019-05-21 17:29:57 -04:00
2022-02-07 09:02:13 -05:00
// relocation for the published artifacts based on the old groupId
2021-10-13 04:24:56 -04:00
relocationPom( MavenPublication ) {
2019-05-21 17:29:57 -04:00
pom {
name = project.name + ' - relocation'
groupId = 'org.hibernate'
artifactId = project.name
version = project.version
description = project.description
url = 'https://hibernate.org/orm'
2019-05-21 17:29:57 -04:00
organization {
name = 'Hibernate.org'
url = 'https://hibernate.org'
2019-05-21 17:29:57 -04:00
}
licenses {
license {
name = 'GNU Library General Public License v2.1 or later'
url = 'https://www.opensource.org/licenses/LGPL-2.1'
comments = 'See discussion at https://hibernate.org/community/license/ for more details.'
2019-05-21 17:29:57 -04:00
distribution = 'repo'
}
}
scm {
url = 'https://github.com/hibernate/hibernate-orm'
connection = 'scm:git:https://github.com/hibernate/hibernate-orm.git'
2019-05-21 17:29:57 -04:00
developerConnection = 'scm:git:git@github.com:hibernate/hibernate-orm.git'
}
developers {
developer {
id = 'hibernate-team'
name = 'The Hibernate Development Team'
organization = 'Hibernate.org'
organizationUrl = 'https://hibernate.org'
2019-05-21 17:29:57 -04:00
}
}
issueManagement {
system = 'jira'
url = 'https://hibernate.atlassian.net/browse/HHH'
}
distributionManagement {
relocation {
groupId = 'org.hibernate.orm'
artifactId = project.name
version = project.version
}
}
}
}
}
}
var signingKey = resolveSigningKey()
var signingPassword = findSigningProperty( "signingPassword" )
2022-02-07 09:02:13 -05:00
signing {
useInMemoryPgpKeys( signingKey, signingPassword )
sign publishing.publications.publishedArtifacts
}
String resolveSigningKey() {
var key = findSigningProperty( "signingKey" )
if ( key != null ) {
return key
}
var keyFile = findSigningProperty( "signingKeyFile" )
if ( keyFile != null ) {
return new File( keyFile ).text
}
2022-02-07 09:02:13 -05:00
return null
}
String findSigningProperty(String propName) {
if ( System.getProperty( propName ) != null ) {
logger.debug "Found `{}` as a system property", propName
return System.getProperty(propName )
}
else if ( System.getenv().get( propName ) != null ) {
logger.debug "Found `{}` as an env-var property", propName
return System.getenv().get( propName )
}
else if ( project.hasProperty( propName ) ) {
logger.debug "Found `{}` as a project property", propName
return project.hasProperty( propName )
}
else {
logger.debug "Did not find `{}`", propName
return null
}
}
var signingTask = project.tasks.getByName( "signPublishedArtifactsPublication" ) as Sign
var signingExtension = project.getExtensions().getByType(SigningExtension) as SigningExtension
task sign {
dependsOn "signPublications"
}
task signPublications { t ->
tasks.withType( Sign ).all { s ->
t.dependsOn s
}
}
signingTask.doFirst {
if ( signingKey == null || signingPassword == null ) {
throw new GradleException(
"Cannot perform signing without GPG details. Please set the `signingKey` and `signingKeyFile` properties"
)
}
}
boolean wasSigningExplicitlyRequested() {
// check whether signing task was explicitly requested when running the build
//
// NOTE: due to https://discuss.gradle.org/t/how-to-tell-if-a-task-was-explicitly-asked-for-on-the-command-line/42853/3
// we cannot definitively know whether the task was requested. Gradle really just does not expose this information.
// so we make a convention - we check the "start parameters" object to see which task-names were requested;
// the problem is that these are the raw names directly from the command line. e.g. it is perfectly legal to
// say `gradlew signPubArtPub` in place of `gradlew signPublishedArtifactsPublication` - Gradle will simply
// "expand" the name it finds. However, it does not make that available.
//
// so the convention is that we will check for the following task names
//
// for each of:
// 1. `sign`
// 2. `signPublications`
// 3. `signPublishedArtifactsPublication`
//
// and we check both forms:
// 1. "${taskName}"
// 2. project.path + ":${taskName}"
//
// we need to check both again because of the "start parameters" discussion
def signingTaskNames = ["sign", "signPublications", "signPublishedArtifactsPublication"]
for ( String taskName : signingTaskNames ) {
if ( gradle.startParameter.taskNames.contains( taskName )
|| gradle.startParameter.taskNames.contains( "${project.path}:${taskName}" ) ) {
return true
}
}
return false
}
if ( wasSigningExplicitlyRequested() ) {
// signing was explicitly requested
signingExtension.required = true
}
else {
gradle.taskGraph.whenReady { graph ->
if ( graph.hasTask( signingTask ) ) {
// signing is scheduled to happen.
//
// we know, from above if-check, that it was not explicitly requested -
// so it is triggered via task dependency. make sure we want it to happen
var publishingTask = project.tasks.getByName( "publishPublishedArtifactsPublicationToSonatypeRepository" ) as PublishToMavenRepository
if ( graph.hasTask( publishingTask ) ) {
// we are publishing to Sonatype OSSRH - we need the signing to happen
signingExtension.required = true
}
else {
// signing was not explicitly requested and we are not publishing to OSSRH,
// so do not sign.
signingTask.enabled = false
}
}
}
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Release / publishing tasks
task ciBuild {
dependsOn test, tasks.publishToSonatype
}
2018-02-01 14:19:08 -05:00
tasks.release.dependsOn tasks.test, tasks.publishToSonatype
2022-05-16 06:11:48 -04:00
tasks.preVerifyRelease.dependsOn build
tasks.preVerifyRelease.dependsOn generateMetadataFileForPublishedArtifactsPublication
tasks.preVerifyRelease.dependsOn generatePomFileForPublishedArtifactsPublication
tasks.preVerifyRelease.dependsOn generatePomFileForRelocationPomPublication
tasks.publishToSonatype.mustRunAfter test
2018-02-01 14:19:08 -05:00
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Ancillary tasks
task showPublications {
doFirst {
project.publishing.publications.each { publication ->
println "Publication (${publication.name}): ${publication.groupId}:${publication.artifactId}:${publication.version}"
publication.artifacts.each { artifact ->
println " > ${artifact}"
}
}
}
}