Java – publish AAR files to Maven central, gradle does not work
Publishing a file to Maven central and gradle still doesn't work:
OK, let's restate all the steps I follow and try to "publish files to Maven central with gradle" (I mainly follow this guide), just to ensure that
1) I use "Android studio". I have this simple Android lib. I want to use Maven: https://github.com/danielemaddaluno/Android-Update-Checker Available on
2) In the updatecheckerlib folder, I have the Lib code mentioned above And in the folder of build Application plug-ins in gradle: 'com android. S output one in the build / outputs / AAR / directory of the module directory aar
3) My first step is to find an approved repository I decided to use sonatype OSS repository Here I registered a project and opened a new question (create – > create question – > community support – open source project repository hosting – > new project) with groupid com github. danielemaddaluno
4) So I added a file in the root directory of the project: Maven_ push. gradle:
apply plugin: 'maven' apply plugin: 'signing' def sonatypeRepositoryUrl if (isReleaseBuild()) { println 'RELEASE BUILD' sonatypeRepositoryUrl = hasProperty('RELEASE_REPOSITORY_URL') ? RELEASE_REPOSITORY_URL : "https://oss.sonatype.org/service/local/staging/deploy/maven2/" } else { println 'DEBUG BUILD' sonatypeRepositoryUrl = hasProperty('SNAPSHOT_REPOSITORY_URL') ? SNAPSHOT_REPOSITORY_URL : "https://oss.sonatype.org/content/repositories/snapshots/" } def getRepositoryUsername() { return hasProperty('nexusUsername') ? nexusUsername : "" } def getRepositoryPassword() { return hasProperty('nexusPassword') ? nexusPassword : "" } afterEvaluate { project -> uploadArchives { repositories { mavenDeployer { beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } pom.artifactId = POM_ARTIFACT_ID repository(url: sonatypeRepositoryUrl) { 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 androidJavadocs(type: Javadoc) { source = android.sourceSets.main.java.sourceFiles } task androidJavadocsJar(type: Jar) { classifier = 'javadoc' //basename = artifact_id from androidJavadocs.destinationDir } task androidSourcesJar(type: Jar) { classifier = 'sources' //basename = artifact_id from android.sourceSets.main.java.sourceFiles } artifacts { //archives packageReleaseJar archives androidSourcesJar archives androidJavadocsJar } }
6) I'm in the file gradle The following lines have been added to properties:
VERSION_NAME=1.0.1-SNAPSHOT VERSION_CODE=2 GROUP=com.github.danielemaddaluno POM_DESCRIPTION=Android Update Checker POM_URL=https://github.com/danielemaddaluno/Android-Update-Checker POM_SCM_URL=https://github.com/danielemaddaluno/Android-Update-Checker POM_SCM_CONNECTION=scm:git@github.com:danielemaddaluno/Android-Update-Checker.git POM_SCM_DEV_CONNECTION=scm:git@github.com:danielemaddaluno/Android-Update-Checker.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=danielemaddaluno POM_DEVELOPER_NAME=Daniele Maddaluno
7) In the root directory, I modified build gradle:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' } } allprojects { repositories { jcenter() } }
To this end:
buildscript { repositories { mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' } } def isReleaseBuild() { return version.contains("SNAPSHOT") == false } allprojects { version = VERSION_NAME group = GROUP repositories { mavenCentral() } } apply plugin: 'android-reporting'
8) I see that for each module or application to be uploaded to the central, I should:
>Provide a gradle Propeties > Modify build Gradle adds the following line at the end: for: '/ maven_ push. gradle’
So in the updatecheckerlib folder, I:
>Added a gradle properties:
POM_NAME=Android Update Checker POM_ARTIFACT_ID=androidupdatechecker POM_PACKAGING=aar
>Modify build Gradle adds the following line at the bottom of the file: apply from: '/ maven_ push. gradle’
9) In order to sign my cultural relics, I did:
gpg --gen-key gpg --list-keys --> get my PubKeyId... gpg --keyserver hkp://pool.sks-keyservers.net --send-keys PubKeyId
10) I added a file to ~ / gradle / gradle. Properties path and such content (I use GPG – list secret keys to obtain the secret key):
signing.keyId=xxxxxxx signing.password=YourPublicKeyPassword signing.secretKeyRingFile=~/.gnupg/secring.gpg nexusUsername=YourSonatypeJiraUsername nexusPassword=YourSonatypeJiraPassword
11) Sudo apt get is installed on the terminal because "andoid studio" teminal does not recognize graduation
12) Finally graduated, upload files
13) I get this error:
FAILURE: Build Failed with an exception. * Where: Build file '/home/madx/Documents/Workspace/Android-Update-Checker/UpdateCheckerLib/build.gradle' line: 1 * What went wrong: A problem occurred evaluating project ':UpdateCheckerLib'. > Could not create plugin of type 'LibraryPlugin'.
Maybe it's just a graduation / graduation plug-in problem, but I want to share all the programs in case it can help others!
Thank you in advance!
Publishing an AAR file to jcenter and gradle still doesn't work:
Thank jbaruch and his staff very much! So I tried to publish to jcenter instead of Maven central. In fact, jcenter () is a superset of Maven central () OK, let's start again with my GitHub library Android Update Checker I tried to follow some of his tips, but I'm still stuck. I have to write my own steps for my release (I hope it's useful to someone) Maybe I missed some
1) Register to bintray user name: danielemaddaluno
2) Enable automatic signature of uploaded content: from binray profile URL – > GPG signature – > copy and paste your public / private key You can open the file public_ key_ sender. asc / private_ key_ sender. These two are found in ASC respectively if you execute the following code (the - A or – armor option in gpgis for generating ASCII armor key pairs):
gpg --gen-key gpg -a --export daniele.maddaluno@gmail.com > public_key_sender.asc gpg -a --export-secret-key daniele.maddaluno@gmail.com > private_key_sender.asc
2.1) in the same web page, you can configure automatic signature from the following location: repository – > maven – > check "GPG automatically uploaded files" – > update
3) In the same web page, you can find your bintray API key (copied for later use)
4) In the same web page, you can configure your sonatype OSS users (in the previous section of the questions I have created users and questions)
5) I add these two lines to build. Net in the root gradle
classpath 'com.github.dcendents:android-maven-plugin:1.2' classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1"
So my own build Gradle looks like:
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.0.0' classpath 'com.github.dcendents:android-maven-plugin:1.2' classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:1.1" } } allprojects { repositories { jcenter() } }
6) I modified my build Gradle is located in my project folder and looks like:
apply plugin: 'com.android.library' apply plugin: 'com.github.dcendents.android-maven' apply plugin: "com.jfrog.bintray" // This is the library version used when deploying the artifact version = "1.0.0" android { compileSdkVersion 21 buildToolsVersion "21.1.2" defaultConfig { //applicationId "com.madx.updatechecker.lib" minSdkVersion 8 targetSdkVersion 21 versionCode 1 versionName "1.0.0" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs',include: ['*.jar']) compile 'org.jsoup:jsoup:1.8.1' } def siteUrl = 'https://github.com/danielemaddaluno/Android-Update-Checker' // Homepage URL of the library def gitUrl = 'https://github.com/danielemaddaluno/Android-Update-Checker.git' // Git repository URL group = "com.github.danielemaddaluno.androidupdatechecker" // Maven Group ID for the artifact install { repositories.mavenInstaller { // This generates POM.xml with proper parameters pom { project { packaging 'aar' // Add your description here name 'The project aims to provide a reusable instrument to check asynchronously if exists any newer released update of your app on the Store.' url siteUrl // Set your license licenses { license { name 'The Apache Software License,Version 2.0' url 'http://www.apache.org/licenses/LICENSE-2.0.txt' } } developers { developer { id 'danielemaddaluno' name 'Daniele Maddaluno' email 'daniele.maddaluno@gmail.com' } } scm { connection gitUrl developerConnection gitUrl url siteUrl } } } } } task sourcesJar(type: Jar) { from android.sourceSets.main.java.srcDirs classifier = 'sources' } task javadoc(type: Javadoc) { source = android.sourceSets.main.java.srcDirs classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) } task javadocJar(type: Jar,dependsOn: javadoc) { classifier = 'javadoc' from javadoc.destinationDir } artifacts { archives javadocJar archives sourcesJar } Properties properties = new Properties() properties.load(project.rootProject.file('local.properties').newDataInputStream()) bintray { user = properties.getProperty("bintray.user") key = properties.getProperty("bintray.apikey") configurations = ['archives'] pkg { repo = "maven" name = "androidupdatechecker" websiteUrl = siteUrl vcsUrl = gitUrl licenses = ["Apache-2.0"] publish = true } }
7) I added it to root local Properties root file, as follows:
bintray.user=<your bintray username> bintray.apikey=<your bintray API key>
8) Default gradient added to my path 2.2 1 "Android studio" actually used, for example:
PATH=$PATH:/etc/android-studio/gradle/gradle-2.2.1/bin
9) Open the "Android studio" terminal and execute:
gradle bintrayUpload
10) From bintray – > my recent package – > Android updatechecker (this is only after point 9 above) – > add to jcenter – > check box – > group id = "com. GitHub. Danielemaddaluno. Android updatechecker"
11) Finally, I tried to follow: bintray – > my recent package – > Android updatechecker – > Maven central – > synchronization, but I received this error in the "synchronization status" column on the right side of the page:
Last Synced: Never Last Sync Status: Validation Failed Last Sync Errors: Missing Signature: '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0-javadoc.jar.asc' does not exist for 'UpdateCheckerLib-1.0.0-javadoc.jar'. Missing Signature: '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0.aar.asc' does not exist for 'UpdateCheckerLib-1.0.0.aar'. Missing Signature: '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0-sources.jar.asc' does not exist for 'UpdateCheckerLib-1.0.0-sources.jar'. Missing Signature: '/com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0.pom.asc' does not exist for 'UpdateCheckerLib-1.0.0.pom'. Invalid POM: /com/github/danielemaddaluno/androidupdatechecker/UpdateCheckerLib/1.0.0/UpdateCheckerLib-1.0.0.pom: Project description missing Dropping existing partial staging repository.
Solution
You can publish your AAR to jcenter
This is default in Android studio. > You can sync to central from there in much each way. > So much each to publish there. > You can use OSS jfrog. org for snapshots.