From 0e329bec294043c8c47e0ba7a8a9c0e5f732ef2b Mon Sep 17 00:00:00 2001 From: licheedev Date: Tue, 1 Jun 2021 11:46:48 +0800 Subject: [PATCH] 2.1.3 migrate from Jcenter to MavenCentral --- README.md | 10 ++- build.gradle | 7 +- maven_publish.gradle | 130 ++++++++++++++++++++++++++++++++++++++ sample/build.gradle | 4 +- serialport/bintray.gradle | 86 ------------------------- serialport/build.gradle | 2 +- 6 files changed, 146 insertions(+), 93 deletions(-) create mode 100644 maven_publish.gradle delete mode 100644 serialport/bintray.gradle diff --git a/README.md b/README.md index 83f21a5..d05c6d4 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,16 @@ This lib is a [fork](https://code.google.com/archive/p/android-serialport-api/) Add the dependency: ``` +allprojects { + repositories { + ... + jcenter() + mavenCentral() // since 2.1.3 + } +} + dependencies { - implementation 'com.licheedev:android-serialport:2.1.2' + implementation 'com.licheedev:android-serialport:2.1.3' } ``` diff --git a/build.gradle b/build.gradle index fd36fc3..68e717a 100644 --- a/build.gradle +++ b/build.gradle @@ -4,13 +4,13 @@ buildscript { repositories { google() jcenter() + mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:4.0.1' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' + classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32' } } @@ -18,6 +18,7 @@ allprojects { repositories { google() jcenter() + mavenCentral() } } @@ -32,5 +33,5 @@ ext { targetSdkVersion = 29 versionCode = 2 - versionName = "2.1.2" + versionName = "2.1.3" } \ No newline at end of file diff --git a/maven_publish.gradle b/maven_publish.gradle new file mode 100644 index 0000000..e8a2281 --- /dev/null +++ b/maven_publish.gradle @@ -0,0 +1,130 @@ +// 依赖信息 +def groupIdDefined = "com.licheedev" +def artifactIdDefined = "android-serialport" +// 如果是测试版,版本号后面加上 -SNAPSHOT +def versionDefined = rootProject.ext.versionName +// 其他信息 +def gitUrl = "https://github.com/licheedev/Android-SerialPort-API" + +// 配置是否上传 +def toUpload = true + +//在根build.gradle中加入,最新版本号参考 https://github.com/Kotlin/dokka#using-dokka +//classpath 'org.jetbrains.dokka:dokka-gradle-plugin:1.4.32' + +//在module的build.gradle末位加入 +//apply from: '../maven_publish.gradle' + +if (toUpload) { + apply plugin: 'signing' + apply plugin: 'maven-publish' + apply plugin: 'org.jetbrains.dokka' + + // + // 打包源码 + task sourcesJar(type: Jar) { + from android.sourceSets.main.java.srcDirs + classifier = 'sources' + } + + task javadoc(type: Javadoc) { + failOnError false + source = android.sourceSets.main.java.sourceFiles + options { + encoding = "utf-8" + charSet 'UTF-8' + } + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + classpath += configurations.compile + } + + // 打包javadoc + task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir + } + + // 打包包含kotlin源码的javadoc + task kotlinDocJar(type: Jar, dependsOn: dokkaHtml) { + classifier = 'javadoc' + from dokkaHtml.outputDirectory + } + // + + afterEvaluate { + + publishing { + publications { + mavenAndroid(MavenPublication) { + from components.release + + groupId "$groupIdDefined" + artifactId "$artifactIdDefined" + version "$versionDefined" + // 上传source + artifact sourcesJar + // 上传javadoc + if (project.plugins.hasPlugin('kotlin-android')) { + artifact kotlinDocJar + } else { + artifact javadocJar + } + + pom { + name = 'Android-SerialPort-API' + description = 'Android-SerialPort-API' + url = "$gitUrl" + + //licenses { + // license { + // name = 'The MIT License' + // url = 'https://opensource.org/licenses/MIT' + // } + //} + + licenses { + license { + name = 'The Apache License, Version 2.0' + url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' + } + } + + developers { + developer { + id = 'licheedev' + name = 'John Lee' + email = 'licheedev@foxmail.com' + } + } + scm { + connection = "$gitUrl" + developerConnection = "${gitUrl}.git" + url = "$gitUrl" + } + } + } + } + + repositories { + + maven { + // 依赖发布地址 + def releasesRepoUrl = "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/" + def snapshotsRepoUrl = "https://s01.oss.sonatype.org/content/repositories/snapshots/" + url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl + + // 配置账号密码 + println "user=${ossrhUsername},key=${ossrhPassword}" + credentials { + username "${ossrhUsername}" + password "${ossrhPassword}" + } + } + } + } + + signing { + sign publishing.publications.mavenAndroid + } + } +} \ No newline at end of file diff --git a/sample/build.gradle b/sample/build.gradle index 167098d..f2834ca 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -27,6 +27,6 @@ dependencies { }) implementation 'androidx.appcompat:appcompat:1.2.0' testImplementation 'junit:junit:4.13' -// implementation project(':serialport') - implementation 'com.licheedev:android-serialport:2.1.1' + implementation project(':serialport') + //implementation 'com.licheedev:android-serialport:2.1.3' } diff --git a/serialport/bintray.gradle b/serialport/bintray.gradle deleted file mode 100644 index fbb21ef..0000000 --- a/serialport/bintray.gradle +++ /dev/null @@ -1,86 +0,0 @@ -//在根build.gradle中加入 -//classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' -//classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - -//在module的build.gradle末位加入 -//apply from: './bintray.gradle' - -// 执行 ./gradlew clean bintrayUpload - -def toUpload = true // 配置是否上传 -if (toUpload) { - apply plugin: 'com.github.dcendents.android-maven' - apply plugin: 'com.jfrog.bintray' - - // 定义参数 - // 依赖信息 - def groupIdDefined = "com.licheedev" - def artifactIdDefined = "android-serialport" - def versionDefined = rootProject.ext.versionName - // 其他信息 - def siteUrl = "https://github.com/licheedev" - def gitUrl = "https://github.com/licheedev/Android-SerialPort-API.git" - def libName = "$artifactIdDefined" - - // 待发布项目的groupId和version。android-maven-gradle-plugin插件需要这么配置。 - group = "$groupIdDefined" - version = "$versionDefined" - - // bintray平台信息配置 - bintray { - user = BINTRAY_USER - key = BINTRAY_KEY - - println "user=${user},key=${key}" - - configurations = ['archives'] - publish = true - pkg { - repo = "maven" - name = libName - licenses = [" Apache-2.0"] - websiteUrl = siteUrl - vcsUrl = gitUrl - version { - name = "$versionDefined" - } - } - } - - // pom文件信息配置 - install { - repositories.mavenInstaller { - pom.project { - groupId "$groupIdDefined" - artifactId "$artifactIdDefined" - version "$versionDefined" - packaging 'aar' - } - } - } - - // 生成sourceJar和javaDocJar - task sourcesJar(type: Jar) { - from android.sourceSets.main.java.srcDirs - classifier = 'sources' - } - - task javadoc(type: Javadoc) { - failOnError false - source = android.sourceSets.main.java.sourceFiles - options { - encoding = "utf-8" - } - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - classpath += configurations.compile - } - task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir - } - - artifacts { - archives sourcesJar - archives javadocJar - } -} diff --git a/serialport/build.gradle b/serialport/build.gradle index 874cafa..f9f8f28 100644 --- a/serialport/build.gradle +++ b/serialport/build.gradle @@ -37,5 +37,5 @@ dependencies { api "androidx.annotation:annotation:1.1.0" } -apply from: './bintray.gradle' +apply from: '../maven_publish.gradle'