From c4acac81018d026c755c348d51d84053a3694575 Mon Sep 17 00:00:00 2001 From: Puneet Behl Date: Fri, 11 Mar 2022 15:32:40 +0530 Subject: [PATCH] Publish artefacts to Sonatype OSSRH (#32) * Clean up root build.gradle * Publish to Sonatype OSSRH Use Gradle maven-publish, signing, and nexus-staging plugin to publish the plugin artifacts to Sonatype OSSRH --- build.gradle | 32 ++++++++- gradle.properties | 12 ++-- gradle/artifactoryPublish.gradle | 13 ---- plugin/build.gradle | 108 ++++++++++++++++++++++++------- 4 files changed, 120 insertions(+), 45 deletions(-) delete mode 100644 gradle/artifactoryPublish.gradle diff --git a/build.gradle b/build.gradle index 0a83fbc..2b49736 100644 --- a/build.gradle +++ b/build.gradle @@ -1,6 +1,32 @@ -project('spring-security-cas') { +buildscript { repositories { - mavenLocal() - mavenCentral() + maven { url "https://plugins.gradle.org/m2/" } + } + dependencies { + classpath "io.github.gradle-nexus:publish-plugin:1.1.0" } } + +version = project.projectVersion + +ext.isSnapshot = project.projectVersion.endsWith('-SNAPSHOT') +ext.isReleaseVersion = !isSnapshot + +if (isReleaseVersion) { + apply plugin: 'maven-publish' + apply plugin: "io.github.gradle-nexus.publish-plugin" + + nexusPublishing { + repositories { + sonatype { + def ossUser = System.getenv("SONATYPE_USERNAME") ?: project.hasProperty("sonatypeOssUsername") ? project.sonatypeOssUsername : '' + def ossPass = System.getenv("SONATYPE_PASSWORD") ?: project.hasProperty("sonatypeOssPassword") ? project.sonatypeOssPassword : '' + def ossStagingProfileId = System.getenv("SONATYPE_STAGING_PROFILE_ID") ?: project.hasProperty("sonatypeOssStagingProfileId") ? project.sonatypeOssStagingProfileId : '' + nexusUrl = uri("https://s01.oss.sonatype.org/service/local/") + username = ossUser + password = ossPass + stagingProfileId = ossStagingProfileId + } + } + } +} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index beb7869..1bcb0fb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ grailsVersion=5.1.1 -projectVersion=5.0.0-SNAPSHOT +projectVersion=4.0.0-TEST threeZeroXProjectVersion=3.0.1 casClientCoreVersion=3.4.1 springSecurityCoreVersion=5.0.0-SNAPSHOT @@ -7,10 +7,10 @@ springSecurityVersion=5.6.1 javaxServletApiVersion=4.0.1 assetPipelineVersion=3.4.3 projectDesc=The CAS plugin adds CAS single sign-on support to a Grails application that uses Spring Security. -projectUrl=https://github.com/grails-plugins/grails-spring-security-cas -githubSlug=grails-plugins/grails-spring-security-cas +projectUrl=https://github.com/grails/grails-spring-security-cas +githubSlug=grails/grails-spring-security-cas githubBranch=master developers=Burt Beckwith -vcsUrl=https://github.com/grails-plugins/grails-spring-security-cas -websiteUrl=https://github.com/grails-plugins/grails-spring-security-cas -issueTrackerUrl=https://github.com/grails-plugins/grails-spring-security-cas/issues +vcsUrl=https://github.com/grails/grails-spring-security-cas +websiteUrl=https://github.com/grails/grails-spring-security-cas +issueTrackerUrl=https://github.com/grails/grails-spring-security-cas/issues diff --git a/gradle/artifactoryPublish.gradle b/gradle/artifactoryPublish.gradle deleted file mode 100644 index 3503228..0000000 --- a/gradle/artifactoryPublish.gradle +++ /dev/null @@ -1,13 +0,0 @@ -artifactory { - contextUrl = 'http://oss.jfrog.org' - publish { - repository { - repoKey = 'oss-snapshot-local' - username = System.getenv("BINTRAY_USER") ?: project.hasProperty("bintrayUser") ? project.bintrayUser : '' - password = System.getenv("BINTRAY_KEY") ?: project.hasProperty("bintrayKey") ? project.bintrayKey : '' - } - defaults { - publications('maven') - } - } -} \ No newline at end of file diff --git a/plugin/build.gradle b/plugin/build.gradle index 7970e0d..34fb97f 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -1,29 +1,57 @@ buildscript { - ext { - grailsVersion = project.grailsVersion - } repositories { - mavenLocal() maven { url 'https://repo.grails.org/grails/core' } - mavenCentral() } dependencies { classpath "org.grails:grails-gradle-plugin:$grailsVersion" - classpath "org.jfrog.buildinfo:build-info-extractor-gradle:latest.release" } } version = projectVersion group = 'org.grails.plugins' -apply plugin: "eclipse" -apply plugin: "idea" -apply plugin: "org.grails.grails-plugin" -apply plugin: 'com.jfrog.artifactory' +apply plugin: 'eclipse' +apply plugin: 'idea' +apply plugin: 'java-library' apply plugin: 'maven-publish' +apply plugin: 'signing' +apply plugin: 'org.grails.grails-plugin' + +ext."signing.keyId" = project.hasProperty("signing.keyId") ? project.getProperty('signing.keyId') : System.getenv('SIGNING_KEY') +ext."signing.secretKeyRingFile" = project.hasProperty("signing.secretKeyRingFile") ? project.getProperty('signing.secretKeyRingFile') : "${System.properties['user.home']}${File.separator}.gnupg${File.separator}secring.gpg" +ext."signing.password" = project.hasProperty("signing.password") ? project.getProperty('signing.password') : System.getenv('SIGNING_PASSPHRASE') +ext.pomInfo = { + delegate.name "Grails Spring Security CAS Plugin" + delegate.description project.projectDesc + delegate.url project.hasProperty('vcsUrl') ? project.vcsUrl : "https://github.com/grails/$project.name" + + delegate.licenses { + delegate.license { + delegate.name 'The Apache Software License, Version 2.0' + delegate.url 'https://www.apache.org/licenses/LICENSE-2.0.txt' + delegate.distribution 'repo' + } + } + + delegate.scm { + delegate.url "scm:git@github.com:${githubSlug}.git" + delegate.connection "scm:git@github.com:${githubSlug}.git" + delegate.developerConnection "scm:git@github.com:${githubSlug}.git" + } + + if (developers) { + delegate.developers { + for (dev in developers.split(',')) { + delegate.developer { + delegate.id dev.toLowerCase().replace(' ', '') + delegate.name dev + } + } + } + } +} repositories { - mavenLocal() maven { url "https://repo.grails.org/grails/core" } } @@ -33,26 +61,60 @@ dependencies { compileOnly "org.grails:grails-web-boot" profile "org.grails.profiles:web-plugin" - compile "org.grails.plugins:spring-security-core:$springSecurityCoreVersion" + api "org.grails.plugins:spring-security-core:$springSecurityCoreVersion" - compile "org.jasig.cas.client:cas-client-core:$casClientCoreVersion", { + api "org.jasig.cas.client:cas-client-core:$casClientCoreVersion", { exclude module: 'slf4j-api' } - compile "org.springframework.security:spring-security-cas:$springSecurityVersion", { + api "org.springframework.security:spring-security-cas:$springSecurityVersion", { ['spring-beans', 'spring-context', 'spring-core', 'spring-security-core', 'spring-security-web', 'spring-web'].each { exclude module: it } } } publishing { - publications { - mavenJava(MavenPublication) { - from components.java - } - } - repositories { - mavenLocal() - } + if (isSnapshot) { + repositories { + maven { + credentials { + def u = System.getenv("ARTIFACTORY_USERNAME") ?: project.hasProperty("artifactoryPublishUsername") ? project.artifactoryPublishUsername : '' + def p = System.getenv("ARTIFACTORY_PASSWORD") ?: project.hasProperty("artifactoryPublishPassword") ? project.artifactoryPublishPassword : '' + username = u + password = p + } + url "https://repo.grails.org/grails/plugins3-snapshots-local" + } + } + } + + publications { + maven(MavenPublication) { + artifactId project.name + from components.java + + artifact sourcesJar + artifact javadocJar + artifact source: "${buildDir}/classes/groovy/main/META-INF/grails-plugin.xml", + classifier: "plugin", + extension: 'xml' + pom.withXml { + def xml = asNode() + + xml.children().last() + pomInfo + // dependency management shouldn't be included + def n = xml.get("dependencyManagement") + if (n) + xml.remove(n) + } + + } + } +} + +signing { + sign publishing.publications.maven } -// apply from: "${rootProject.projectDir}/gradle/artifactoryPublish.gradle" +tasks.withType(Sign) { + onlyIf { isReleaseVersion } +}