diff --git a/build.gradle b/build.gradle index 1fdf8a8..b9704cc 100644 --- a/build.gradle +++ b/build.gradle @@ -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 -} \ No newline at end of file +} + +apply from: "${rootDir}/scripts/publish-root.gradle" diff --git a/composecalendar/build.gradle b/composecalendar/build.gradle index 1715eeb..f3a4d1e 100644 --- a/composecalendar/build.gradle +++ b/composecalendar/build.gradle @@ -17,7 +17,6 @@ plugins { id 'com.android.library' id 'org.jetbrains.kotlin.android' - id 'maven-publish' } android { @@ -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" diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle new file mode 100644 index 0000000..7874ef5 --- /dev/null +++ b/scripts/publish-module.gradle @@ -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 = 'lampione95@gmail.com' + } + } + 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 +} diff --git a/scripts/publish-root.gradle b/scripts/publish-root.gradle new file mode 100644 index 0000000..05b2955 --- /dev/null +++ b/scripts/publish-root.gradle @@ -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/")) + } + } +}