From 2413f489496e5b638a63248cc6d8dfa72eff8aa6 Mon Sep 17 00:00:00 2001 From: Beka Westberg Date: Sat, 1 Apr 2023 11:01:46 -0700 Subject: [PATCH] chore: work on updating publish scripts --- build.gradle | 9 +- gradle.properties | 14 --- gradle/wrapper/gradle-wrapper.properties | 2 +- library/build.gradle | 8 +- library/maven-push.gradle | 103 ----------------------- scripts/publish-module.gradle | 80 ++++++++++++++++++ scripts/publish-root.gradle | 33 ++++++++ 7 files changed, 129 insertions(+), 120 deletions(-) delete mode 100644 library/maven-push.gradle create mode 100644 scripts/publish-module.gradle create mode 100644 scripts/publish-root.gradle diff --git a/build.gradle b/build.gradle index c32b9a1..99ee9fd 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:7.3.1' + classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" @@ -17,6 +17,13 @@ buildscript { } } +plugins { + id("io.github.gradle-nexus.publish-plugin") version "1.3.0" +} + +apply from: "${rootDir}/scripts/publish-root.gradle" + + allprojects { repositories { google() diff --git a/gradle.properties b/gradle.properties index 218fe51..718ea5b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -27,17 +27,3 @@ android.useAndroidX=true # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true -VERSION_NAME=0.4.1 -VERSION_CODE=7 -GROUP=com.github.beksomega - -POM_DESCRIPTION=A library that adds a looping layout manager for recycler views. -POM_URL=https://github.com/BeksOmega/looping-layout -POM_SCM_URL=https://github.com/BeksOmega/looping-layout -POM_SCM_CONNECTION=scm:git@github.com:BeksOmega/looping-layout.git -POM_SCM_DEV_CONNECTION=scm:git@github.com:BeksOmega/looping-layout.git -POM_LICENCE_NAME=The Apache Software License, Version 2.0 -POM_LICENCE_URL=http://www.apache.org/licenses/LICENSE-2.0.txt -POM_LICENCE_DIST=repo -POM_DEVELOPER_ID=BeksOmega -POM_DEVELOPER_NAME=Beka Westberg diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index c08da4b..3b35ba8 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip diff --git a/library/build.gradle b/library/build.gradle index 15e656b..39eb067 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,7 +1,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-parcelize' -apply from: 'maven-push.gradle' android { compileSdkVersion 33 @@ -29,3 +28,10 @@ dependencies { implementation 'androidx.recyclerview:recyclerview:1.3.0' } +ext { + PUBLISH_GROUP_ID = 'com.github.beksomega' + PUBLISH_VERSION = '0.4.1' + PUBLISH_ARTIFACT_ID = 'loopinglayout' +} + +apply from: "${rootProject.projectDir}/scripts/publish-module.gradle" diff --git a/library/maven-push.gradle b/library/maven-push.gradle deleted file mode 100644 index fad4fb3..0000000 --- a/library/maven-push.gradle +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2013 Chris Banes - * - * 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' -apply plugin: 'signing' - -def isReleaseBuild() { - return VERSION_NAME.contains("SNAPSHOT") == false -} - -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -def getSnapshotRepositoryUrl() { - return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL - : "https://oss.sonatype.org/content/repositories/snapshots/" -} - -def getRepositoryUsername() { - return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" -} - -def getRepositoryPassword() { - return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" -} - -afterEvaluate { project -> - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - pom.groupId = GROUP - pom.artifactId = POM_ARTIFACT_ID - pom.version = VERSION_NAME - - repository(url: getReleaseRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - snapshotRepository(url: getSnapshotRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - - pom.project { - name POM_NAME - packaging POM_PACKAGING - description POM_DESCRIPTION - url POM_URL - - scm { - url POM_SCM_URL - connection POM_SCM_CONNECTION - developerConnection POM_SCM_DEV_CONNECTION - } - - licenses { - license { - name POM_LICENCE_NAME - url POM_LICENCE_URL - distribution POM_LICENCE_DIST - } - } - - developers { - developer { - id POM_DEVELOPER_ID - name POM_DEVELOPER_NAME - } - } - } - } - } - } - - signing { - required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } - sign configurations.archives - } - - task androidSourcesJar(type: Jar) { - archiveClassifier = 'sources' - from android.sourceSets.main.java.srcDirs - } - - artifacts { - archives androidSourcesJar - } -} diff --git a/scripts/publish-module.gradle b/scripts/publish-module.gradle new file mode 100644 index 0000000..73d8f34 --- /dev/null +++ b/scripts/publish-module.gradle @@ -0,0 +1,80 @@ +apply plugin: 'maven-publish' +apply plugin: 'signing' + +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, in case you have them + 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) { + // 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 + + // Meta data + pom { + name = PUBLISH_ARTIFACT_ID + description = 'A library that adds a looping layout manager for recycler views.' + url = 'https://github.com/BeksOmega/looping-layout' + licenses { + license { + name = 'The Apache Software License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + developers { + developer { + id = 'BeksOmega' + name = 'Beka Westberg' + email = 'bekawestberg@gmail.com' + } + } + + // Version control info + scm { + connection = 'scm:git:github.com/BeksOmega/looping-layout.git' + developerConnection = 'scm:git:ssh://github.com/BeksOmega/looping-layout.git' + url = 'https://github.com/getstream/stream-chat-android/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/scripts/publish-root.gradle b/scripts/publish-root.gradle new file mode 100644 index 0000000..0582862 --- /dev/null +++ b/scripts/publish-root.gradle @@ -0,0 +1,33 @@ +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["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 { + stagingProfileId = sonatypeStagingProfileId + username = ossrhUsername + password = ossrhPassword + } + } +} \ No newline at end of file