Skip to content

Commit

Permalink
chore: add support for mavenCentral publication
Browse files Browse the repository at this point in the history
  • Loading branch information
lampione committed Jul 18, 2022
1 parent 0de7d0f commit 9a29074
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 14 deletions.
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ plugins {
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
id 'io.github.gradle-nexus.publish-plugin' version "1.1.0"
}

task clean(type: Delete) {
delete rootProject.buildDir
}
}

apply from: "${rootDir}/scripts/publish-root.gradle"
19 changes: 6 additions & 13 deletions composecalendar/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}

android {
Expand Down Expand Up @@ -73,16 +72,10 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release

groupId = 'com.squaredem'
artifactId = 'composecalendar'
version = '1.0.0'
}
}
}
ext {
PUBLISH_GROUP_ID = 'com.squaredem'
PUBLISH_ARTIFACT_ID = 'composecalendar'
PUBLISH_VERSION = '1.0.0'
}

apply from: "${rootProject.projectDir}/scripts/publish-module.gradle"
79 changes: 79 additions & 0 deletions scripts/publish-module.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright 2022 Matteo Miceli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

apply plugin: 'maven-publish'
apply plugin: 'signing'

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

artifacts {
archives androidSourcesJar
}

group = PUBLISH_GROUP_ID
version = PUBLISH_VERSION

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

artifact androidSourcesJar

pom {
name = PUBLISH_ARTIFACT_ID
description = 'A basic library that provides an Android composable view which allows selection of a date from a calendar.'
url = 'https://github.com/lampione/ComposeCalendar'
licenses {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
}
developers {
developer {
id = 'lampione'
name = 'Matteo Miceli'
email = '[email protected]'
}
}
scm {
connection = 'scm:git:github.com/lampione/ComposeCalendar.git'
developerConnection = 'scm:git:ssh://github.com/lampione/ComposeCalendar.git'
url = 'https://github.com/lampione/ComposeCalendar/tree/main'
}
}
}
}
}
}

signing {
sign publishing.publications
}
48 changes: 48 additions & 0 deletions scripts/publish-root.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2022 Matteo Miceli
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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()) {
Properties p = new Properties()
new FileInputStream(secretPropsFile).withCloseable { is -> p.load(is) }
p.each { name, value -> ext[name] = value }
} else {
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')
}

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 9a29074

Please sign in to comment.