Skip to content

Commit

Permalink
Configuration for maven publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
ihcoople committed Jan 24, 2023
1 parent 87751bf commit 9ca73d3
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 18 deletions.
8 changes: 7 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,10 @@ plugins {
id 'com.android.application' version "$toolsVersion" apply false
id 'com.android.library' version "$toolsVersion" apply false
id 'org.jetbrains.kotlin.android' version "$kotlinVersion" apply false
}
id 'io.github.gradle-nexus.publish-plugin' version "$nexusPublishPluginVersion" apply false
id 'org.jetbrains.dokka' version "$kotlinVersion" apply false
}

apply plugin: 'io.github.gradle-nexus.publish-plugin'

apply from: "$rootDir/gradle/publish-root.gradle"
26 changes: 9 additions & 17 deletions format-watcher/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}

apply from: "$rootDir/gradle/version.gradle"
ext {
PUBLISH_GROUP_ID = 'io.github.ihermandev'
PUBLISH_VERSION = '1.0.0'
PUBLISH_ARTIFACT_ID = 'format-watcher'
}

apply from: "$rootProject.projectDir/gradle/version.gradle"
apply from: "$rootProject.projectDir/gradle/publish-module.gradle"

android {
namespace 'com.github.ihermandev.formatwatcher'
Expand All @@ -23,18 +29,4 @@ android {
dependencies {
androidTestImplementation "androidx.test.ext:junit:$jUnitExtVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$espressoCoreVersion"
}

publishing {
publications {
release(MavenPublication) {
groupId = 'com.github.ihermandev'
artifactId = 'format-watcher'
version = versionName

afterEvaluate {
from components.release
}
}
}
}
}
94 changes: 94 additions & 0 deletions gradle/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
apply plugin: 'maven-publish'
apply plugin: 'signing'
apply plugin: 'org.jetbrains.dokka'

task androidSourcesJar(type: Jar) {
archiveClassifier.set('sources')
if (project.plugins.findPlugin("com.android.library")) {
// For Android libraries
from android.sourceSets.main.java.srcDirs
from android.sourceSets.main.kotlin.srcDirs
} else {
// For pure Kotlin libraries
from sourceSets.main.java.srcDirs
from sourceSets.main.kotlin.srcDirs
}
}

tasks.withType(dokkaHtmlPartial.getClass()).configureEach {
pluginsMapConfiguration.set(
["org.jetbrains.dokka.base.DokkaBase": """{ "separateInheritedMembers": true}"""]
)
}

task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
archiveClassifier.set('javadoc')
from dokkaJavadoc.outputDirectory
}

artifacts {
archives androidSourcesJar
archives javadocJar
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
// The coordinates of the library
groupId PUBLISH_GROUP_ID
artifactId PUBLISH_ARTIFACT_ID
version PUBLISH_VERSION

// Two artifacts, the `aar` (or `jar`) and the sources
if (project.plugins.findPlugin("com.android.library")) {
from components.release
} else {
from components.java
}

artifact androidSourcesJar
artifact javadocJar

// Metadata
pom {
name = PUBLISH_ARTIFACT_ID
description = 'FormatWatcher library for Android EditText'
url = 'https://github.com/ihermandev/format-watcher'
licenses {
license {
name = 'Apache 2.0 license'
url = 'https://github.com/ihermandev/format-watcher/blob/master/LICENSE.md'
}
}
developers {
developer {
id = 'ihermandev'
name = 'Illia Herman'
email = 'illiaherman8@gmail.com'
}
}

// Version control info
scm {
connection = 'scm:git:github.com/ihermandev/format-watcher.git'
developerConnection = 'scm:git:ssh://github.com/ihermandev/format-watcher.git'
url = 'https://github.com/ihermandev/format-watcher/tree/master'
}
}
}
}
}
}

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

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["ossrhUsername"] = System.getenv('OSSRH_USERNAME')
ext["ossrhPassword"] = System.getenv('OSSRH_PASSWORD')
ext["sonatypeStagingProfileId"] = System.getenv('SONATYPE_STAGING_PROFILE_ID')
ext["signing.keyId"] = System.getenv('SIGNING_KEY_ID')
ext["signing.password"] = System.getenv('SIGNING_PASSWORD')
ext["signing.key"] = System.getenv('SIGNING_KEY')
}

// Set up Sonatype repository
nexusPublishing {
repositories {
sonatype {
nexusUrl.set(uri("https://s01.oss.sonatype.org/service/local/"))
snapshotRepositoryUrl.set(uri("https://s01.oss.sonatype.org/content/repositories/snapshots/"))
}
}
}
1 change: 1 addition & 0 deletions gradle/version.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ext {
/** Environment **/
toolsVersion = "7.3.1"
kotlinVersion = "1.7.20"
nexusPublishPluginVersion = "1.1.0"

/** Android **/
androidxAppCompatVersion = "1.6.0"
Expand Down

0 comments on commit 9ca73d3

Please sign in to comment.