Skip to content

Commit

Permalink
🔧 Add publishing to maven central
Browse files Browse the repository at this point in the history
  • Loading branch information
giannivh committed May 29, 2022
1 parent ae5c722 commit ca57864
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 4 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@
out/

# Gradle
.gradle/
.gradle/

# Publishing
local.properties
15 changes: 12 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
plugins {
id 'java'
id "java"
id("io.github.gradle-nexus.publish-plugin") version "1.1.0"
}

group "com.giannivanhoecke.oauth"
Expand All @@ -14,7 +15,6 @@ repositories {
}

dependencies {

implementation "org.apache.commons:commons-lang3:${commonsLang3Version}"
implementation "commons-codec:commons-codec:${commonsCodecVersion}"
implementation "com.google.code.gson:gson:${gsonVersion}"
Expand All @@ -28,4 +28,13 @@ dependencies {

test {
useJUnitPlatform()
}
}

ext {
PUBLISH_GROUP_ID = "com.giannivanhoecke.oauth"
PUBLISH_ARTIFACT_ID = "oauth-desktop"
PUBLISH_VERSION = "${version}"
}

apply from: "${rootDir}/gradle/publish-root.gradle"
apply from: "${rootProject.projectDir}/gradle/publish-module.gradle"
73 changes: 73 additions & 0 deletions gradle/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'

task javadocJar(type: Jar) {
archiveClassifier.set('javadoc')
from javadoc
}

task sourcesJar(type: Jar) {
archiveClassifier.set('sources')
from sourceSets.main.allSource
}

artifacts {
archives javadocJar, sourcesJar
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
from components.java
}

artifact sourcesJar
artifact javadocJar

pom {
name = PUBLISH_ARTIFACT_ID
description = 'Open source OAuth2 desktop library for Java'
url = 'https://github.com/giannivh/oauth-desktop'
licenses {
license {
name = 'MIT License'
url = 'https://github.com/giannivh/oauth-desktop/blob/master/LICENSE'
}
}
developers {
developer {
id = 'gvhoecke'
name = 'Gianni Van Hoecke'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:github.com/giannivh/oauth-desktop.git'
developerConnection = 'scm:git:ssh://github.com/giannivh/oauth-desktop.git'
url = 'https://github.com/giannivh/oauth-desktop/tree/master'
}
}
}
}
}
}

signing {
useInMemoryPgpKeys(
rootProject.ext["signing.keyId"],
rootProject.ext["signing.key"],
rootProject.ext["signing.password"],
)
sign publishing.publications
}
36 changes: 36 additions & 0 deletions gradle/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// create variables with empty default values
ext["signing.keyId"] = ''
ext["signing.password"] = ''
ext["signing.key"] = ''
ext["ossrhUsername"] = ''
ext["ossrhPassword"] = ''
ext["sonatypeStagingProfileId"] = ''

File secretPropsFile = project.rootProject.file('local.properties')
if (secretPropsFile.exists()) {
// read local.properties file first if it exists
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
// use system environment variables
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.key"] = System.getenv('SIGNING_KEY')
ext["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
}

// set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
stagingProfileId = sonatypeStagingProfileId
username = ossrhUsername
password = ossrhPassword
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}

0 comments on commit ca57864

Please sign in to comment.