From 0a2480227f8d07e1ecf5c6312bbabd4c671b3908 Mon Sep 17 00:00:00 2001 From: Max Lv Date: Thu, 21 Feb 2019 15:12:24 +0800 Subject: [PATCH] Refine plugin sign and upload --- build.gradle | 1 + plugin/build.gradle | 28 ++++++- plugin/gradle-mvn-push.gradle | 133 ---------------------------------- plugin/gradle.properties | 22 ++++++ 4 files changed, 47 insertions(+), 137 deletions(-) delete mode 100644 plugin/gradle-mvn-push.gradle create mode 100644 plugin/gradle.properties diff --git a/build.gradle b/build.gradle index 49f666093b..f1af52f91a 100644 --- a/build.gradle +++ b/build.gradle @@ -26,6 +26,7 @@ buildscript { } dependencies { + classpath 'com.vanniktech:gradle-maven-publish-plugin:0.8.0' classpath 'com.android.tools.build:gradle:3.3.1' classpath 'com.github.ben-manes:gradle-versions-plugin:0.20.0' classpath 'com.google.gms:google-services:4.2.0' diff --git a/plugin/build.gradle b/plugin/build.gradle index 103b916df2..a0e36526af 100644 --- a/plugin/build.gradle +++ b/plugin/build.gradle @@ -1,8 +1,17 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +apply plugin: 'com.vanniktech.maven.publish' -apply from: 'gradle-mvn-push.gradle' +@SuppressWarnings("GroovyUnusedDeclaration") +def getRepositoryUsername() { + return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" +} + +@SuppressWarnings("GroovyUnusedDeclaration") +def getRepositoryPassword() { + return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" +} android { buildToolsVersion rootProject.buildToolsVersion @@ -11,10 +20,10 @@ android { defaultConfig { minSdkVersion rootProject.minSdkVersion targetSdkVersion rootProject.sdkVersion - versionCode 9 - versionName "1.2.0" + versionCode Integer.parseInt(VERSION_CODE) + versionName VERSION_NAME - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + testInstrumentationRunner "androidx.testgetRepositoryPassword().runner.AndroidJUnitRunner" } buildTypes { @@ -28,6 +37,17 @@ androidExtensions { experimental = true } +mavenPublish { + targets { + uploadArchives { + releaseRepositoryUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/" + snapshotRepositoryUrl = "https://oss.sonatype.org/content/repositories/snapshots/" + repositoryUsername = getRepositoryUsername() + repositoryPassword = getRepositoryPassword() + } + } +} + dependencies { api "androidx.core:core-ktx:1.0.1" api "com.google.android.material:material:1.1.0-alpha03" diff --git a/plugin/gradle-mvn-push.gradle b/plugin/gradle-mvn-push.gradle deleted file mode 100644 index 1446d6fbb7..0000000000 --- a/plugin/gradle-mvn-push.gradle +++ /dev/null @@ -1,133 +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' - -@SuppressWarnings(["GroovyUnusedDeclaration", "GrMethodMayBeStatic"]) -def isReleaseBuild() { - return !android.defaultConfig.versionName.contains("SNAPSHOT") -} - -@SuppressWarnings("GroovyUnusedDeclaration") -def getReleaseRepositoryUrl() { - return hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL - : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" -} - -@SuppressWarnings("GroovyUnusedDeclaration") -def getSnapshotRepositoryUrl() { - return hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL - : "https://oss.sonatype.org/content/repositories/snapshots/" -} - -@SuppressWarnings("GroovyUnusedDeclaration") -def getRepositoryUsername() { - return hasProperty('NEXUS_USERNAME') ? NEXUS_USERNAME : "" -} - -@SuppressWarnings("GroovyUnusedDeclaration") -def getRepositoryPassword() { - return hasProperty('NEXUS_PASSWORD') ? NEXUS_PASSWORD : "" -} - -afterEvaluate { project -> - uploadArchives { - repositories { - mavenDeployer { - beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } - - pom.groupId = 'com.github.shadowsocks' - pom.artifactId = 'plugin' - pom.version = android.defaultConfig.versionName - - repository(url: getReleaseRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - snapshotRepository(url: getSnapshotRepositoryUrl()) { - authentication(userName: getRepositoryUsername(), password: getRepositoryPassword()) - } - - pom.project { - name 'Shadowsocks Plugin' - packaging 'aar' - description 'Shadowsocks Plugin' - url 'https://github.com/shadowsocks/shadowsocks-android' - - scm { - url 'https://github.com/shadowsocks/shadowsocks-android.git' - connection 'scm:git:git://github.com/shadowsocks/shadowsocks-android.git' - developerConnection 'scm:git:git@github.com:shadowsocks/shadowsocks-android.git' - } - - licenses { - license { - name 'GPLv3' - url 'https://www.gnu.org/licenses/gpl-3.0.html' - distribution 'repo' - } - } - - developers { - developer { - id 'madeye' - name 'Max Lv' - url 'https://github.com/madeye' - } - developer { - id 'Mygod' - name 'Mygod Studio' - url 'https://github.com/Mygod' - } - } - } - } - } - } - - signing { - required { isReleaseBuild() && gradle.taskGraph.hasTask("uploadArchives") } - sign configurations.archives - } - - android.libraryVariants.all { variant -> - def javadocTask = task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) { - description "Generates Javadoc for $variant.name." - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - exclude '**/*.kt' - exclude '**/BuildConfig.java' - exclude '**/R.java' - } - - def jarJavadocTask = task("jar${variant.name.capitalize()}Javadoc", type: Jar) { - description "Generate Javadoc Jar for $variant.name" - classifier = 'javadoc' - from javadocTask.destinationDir - } - - jarJavadocTask.dependsOn javadocTask - artifacts.add('archives', jarJavadocTask) - - def jarSourceTask = task("jar${variant.name.capitalize()}Sources", type: Jar) { - description "Generates Java Sources for $variant.name." - classifier = 'sources' - from android.sourceSets.main.java.srcDirs - } - - artifacts.add('archives', jarSourceTask) - } -} diff --git a/plugin/gradle.properties b/plugin/gradle.properties new file mode 100644 index 0000000000..743a42b2d9 --- /dev/null +++ b/plugin/gradle.properties @@ -0,0 +1,22 @@ +GROUP=com.github.shadowsocks +VERSION_NAME=1.2.0 +VERSION_CODE=9 + +POM_ARTIFACT_ID=plugin +POM_NAME=Shadowsocks Plugin +POM_PACKAGING=aar + +POM_DESCRIPTION=SIP003 plugin for Shadowsocks +POM_INCEPTION_YEAR=2018 + +POM_URL=https://github.com/shadowsocks/shadowsocks-android +POM_SCM_URL=https://github.com/shadowsocks/shadowsocks-android +POM_SCM_CONNECTION=scm:git:git://github.com/shadowsocks/shadowsocks-android.git +POM_SCM_DEV_CONNECTION=scm:git:ssh://git@github.com/shadowsocks/shadowsocks-android.git + +POM_LICENCE_NAME=The GNU General Public License v3.0 +POM_LICENCE_URL=https://www.gnu.org/licenses/gpl-3.0.html +POM_LICENCE_DIST=repo + +POM_DEVELOPER_ID=Mygod +POM_DEVELOPER_NAME=Mygod Studio