diff --git a/.gitignore b/.gitignore index a91c1af..7ebad63 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,7 @@ out/ # Gradle -.gradle/ \ No newline at end of file +.gradle/ + +# Publishing +local.properties \ No newline at end of file diff --git a/build.gradle b/build.gradle index 3f61e5a..ce2d3cf 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { - id 'java' + id "java" + id("io.github.gradle-nexus.publish-plugin") version "1.1.0" } group "com.giannivanhoecke.oauth" @@ -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}" @@ -28,4 +28,13 @@ dependencies { test { useJUnitPlatform() -} \ No newline at end of file +} + +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" diff --git a/gradle/publish-module.gradle b/gradle/publish-module.gradle new file mode 100644 index 0000000..3572bfe --- /dev/null +++ b/gradle/publish-module.gradle @@ -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 = 'gianni@giannivanhoecke.com' + } + } + 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 +} \ No newline at end of file diff --git a/gradle/publish-root.gradle b/gradle/publish-root.gradle new file mode 100644 index 0000000..c8b6fdd --- /dev/null +++ b/gradle/publish-root.gradle @@ -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/")) + } + } +} \ No newline at end of file