From 7cb6d072604f73c211408955a9ff1f5483cb1de6 Mon Sep 17 00:00:00 2001 From: codezjx Date: Mon, 15 Nov 2021 16:59:16 +0800 Subject: [PATCH] Add maven-publish.gradle, upload aar to maven central. --- andlinker/bintray.gradle | 58 ---------------------- andlinker/build.gradle | 3 +- andlinker/install.gradle | 44 ---------------- andlinker/maven-publish.gradle | 91 ++++++++++++++++++++++++++++++++++ andlinker/properties.gradle | 10 ++-- build.gradle | 10 ---- 6 files changed, 95 insertions(+), 121 deletions(-) delete mode 100644 andlinker/bintray.gradle delete mode 100644 andlinker/install.gradle create mode 100644 andlinker/maven-publish.gradle diff --git a/andlinker/bintray.gradle b/andlinker/bintray.gradle deleted file mode 100644 index 3ceefad..0000000 --- a/andlinker/bintray.gradle +++ /dev/null @@ -1,58 +0,0 @@ -apply plugin: 'com.jfrog.bintray' - -version = libraryVersion - -if (project.hasProperty("android")) { // Android libraries - task sourcesJar(type: Jar) { - classifier = 'sources' - from android.sourceSets.main.java.srcDirs - } - - task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs - classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - } -} else { // Java libraries - task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource - } -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - -artifacts { - archives javadocJar - archives sourcesJar -} - -// Bintray -Properties properties = new Properties() -properties.load(project.rootProject.file('gradle.properties').newDataInputStream()) - -bintray { - user = properties.getProperty("bintray.user") - key = properties.getProperty("bintray.apikey") - - configurations = ['archives'] - pkg { - repo = bintrayRepo - name = bintrayName - desc = libraryDescription - websiteUrl = siteUrl - vcsUrl = gitUrl - licenses = allLicenses - publish = true - publicDownloadNumbers = true - version { - desc = libraryDescription - gpg { - sign = true //Determines whether to GPG sign the files. The default is false - passphrase = properties.getProperty("bintray.gpg.password") //Optional. The passphrase for GPG signing' - } - } - } -} diff --git a/andlinker/build.gradle b/andlinker/build.gradle index deb6a68..695d629 100644 --- a/andlinker/build.gradle +++ b/andlinker/build.gradle @@ -25,5 +25,4 @@ dependencies { } apply from: 'properties.gradle' -apply from: 'install.gradle' -apply from: 'bintray.gradle' \ No newline at end of file +apply from: 'maven-publish.gradle' \ No newline at end of file diff --git a/andlinker/install.gradle b/andlinker/install.gradle deleted file mode 100644 index c05f008..0000000 --- a/andlinker/install.gradle +++ /dev/null @@ -1,44 +0,0 @@ -apply plugin: 'com.github.dcendents.android-maven' - -// Maven Group ID for the artifact -group = publishedGroupId - -install { - repositories.mavenInstaller { - // This generates POM.xml with proper parameters - pom { - project { - packaging 'aar' - groupId publishedGroupId - artifactId artifact - - // Add your description here - name libraryName - description libraryDescription - url siteUrl - - // Set your license - licenses { - license { - name licenseName - url licenseUrl - } - } - - developers { - developer { - id developerId - name developerName - email developerEmail - } - } - - scm { - connection gitUrl - developerConnection gitUrl - url siteUrl - } - } - } - } -} diff --git a/andlinker/maven-publish.gradle b/andlinker/maven-publish.gradle new file mode 100644 index 0000000..89b8f8a --- /dev/null +++ b/andlinker/maven-publish.gradle @@ -0,0 +1,91 @@ +apply plugin: 'maven' +apply plugin: 'signing' + +// Android libraries +task sourcesJar(type: Jar) { + classifier = 'sources' + from android.sourceSets.main.java.srcDirs +} + +task javadoc(type: Javadoc) { + // https://github.com/novoda/bintray-release/issues/71 + excludes = ['**/*.kt'] // < ---- Exclude all kotlin files from javadoc file. + source = android.sourceSets.main.java.srcDirs + classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) + options.encoding = "UTF-8" + options.charSet = "UTF-8" +} + +tasks.withType(JavaCompile) { + options.encoding = "UTF-8" +} + +tasks.withType(Javadoc) { + options.encoding = "UTF-8" +} + +task javadocJar(type: Jar, dependsOn: javadoc) { + classifier = 'javadoc' + from javadoc.destinationDir +} + +// Add javadoc/source jar tasks as artifacts +artifacts { + archives javadocJar + archives sourcesJar +} + +// Signing artifacts +signing { + required { gradle.taskGraph.hasTask("uploadArchives") } + sign configurations.archives +} + +uploadArchives { + repositories { + mavenDeployer { + beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } + + repository(url: "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + snapshotRepository(url: "https://s01.oss.sonatype.org/content/repositories/snapshots/") { + authentication(userName: ossrhUsername, password: ossrhPassword) + } + + pom.groupId = publishedGroupId + pom.artifactId = artifact + pom.version = libraryVersion + + pom.project { + packaging 'aar' + + name libraryName + description libraryDescription + url siteUrl + + scm { + connection gitUrl + developerConnection gitUrl + url siteUrl + } + + licenses { + license { + name licenseName + url licenseUrl + } + } + + developers { + developer { + id developerId + name developerName + email developerEmail + } + } + } + } + } +} diff --git a/andlinker/properties.gradle b/andlinker/properties.gradle index 616399b..ec1655c 100644 --- a/andlinker/properties.gradle +++ b/andlinker/properties.gradle @@ -1,18 +1,14 @@ ext { - bintrayRepo = 'maven' - bintrayName = 'and-linker' - publishedGroupId = 'com.codezjx.library' - libraryName = 'AndLinker' artifact = 'andlinker' - + libraryVersion = '0.8.0' + + libraryName = 'AndLinker' libraryDescription = 'AndLinker is a IPC library for Android, which combines the features of AIDL and Retrofit. Allows IPC call seamlessly compose with rxjava and rxjava2 call adapters.' siteUrl = 'https://github.com/codezjx/AndLinker' gitUrl = 'https://github.com/codezjx/AndLinker.git' - libraryVersion = '0.7.2' - developerId = 'codezjx' developerName = 'codezjx' developerEmail = 'code.zjx@gmail.com' diff --git a/build.gradle b/build.gradle index 5254def..6e214fa 100644 --- a/build.gradle +++ b/build.gradle @@ -8,9 +8,6 @@ buildscript { } dependencies { classpath 'com.android.tools.build:gradle:3.4.2' - classpath 'com.github.dcendents:android-maven-gradle-plugin:1.5' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.1' - // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files @@ -22,13 +19,6 @@ allprojects { google() jcenter() } - - tasks.withType(Javadoc) { - options.encoding = 'UTF-8' - if (JavaVersion.current().isJava8Compatible()) { - options.addStringOption('Xdoclint:none', '-quiet') - } - } } task clean(type: Delete) {