How to publish Android library as a Maven artifact on Bitbucket?

I am trying to publish the Android library as a Maven artifact in the Bitbucket repository, starting with this article , which was related to the Android Weekly Newsletter release some time ago. This article describes how to publish and how to link the published artifact to another Android project. However, I was not even able to get part of the publication to work correctly.

This is currently the corresponding contents of the build.gradle file belonging to the library project:

 apply plugin: 'maven' allprojects { repositories { jcenter() maven { url "https://raw.github.com/synergian/wagon-git/releases" } } } configurations { deployerJar } dependencies { deployerJar 'ar.com.synergian:wagon-git:0.2.5' } 

The relevant parts of the library module build.gradle file in the project are as follows:

 apply plugin: 'maven' uploadArchives { configuration = rootProject.configurations.archives repositories { configuration = rootProject.configurations.deployerJar mavenDeployer { pom.groupId = 'com.example' pom.artifactId = 'example-library' pom.version = '1.0.0' repository(url: "${bitbucketUrl}") { authentication(userName: bitbucketUsername, password: bitbucketPassword) } } } } 

where bitbucketUrl , bitbucketUsername and bitbucketPassword are included in the gradle.properties file in the root of the project.

So what is the problem? When I run the uploadArchives task from Android Studio, Gradle shows that the operation completed successfully. But nothing appears in the Bitbucket repository.

Nothing has been written about the structure of this repository, except for the Wagon Git website (the call to its documentation seems a little stretched for me), where the specified URL of the form repository

 git:releases:// git@github.com :synergian/wagon-git.git 

states that releases represents a repository branch. I obligated this part about the structure even tried to add a repository directory (to mimic the local Maven repository on my machine), but no luck and, above all, there was no hint.

An even more serious problem is that when I experimented with different configurations, I noticed that my repository URL was incorrect; however, at runtime, Gradle never noticed an error, and warned or informed me of a suitable message. This made me suspect that he did not even prepare the artifact for download and did not try to connect to Bitbucket, but I could not find a pointer to understand why.

Finally, something even stranger happens: when I comment out a line:

 configuration = rootProject.configurations.deployerJar 

in the build.gradle module, and I run the uploadArchives task, Gradle stops with an error, stating that it can’t find the right universal for managing the Git protocol, which is expected; however, in this process, the Maven artifact appears in the local repository on my machine. Thus, if the publishing process fails, at least I can work locally with my library from other projects, depending on this, using Gradle to manage Maven dependencies.

What am I doing wrong?

+7
android maven gradle
source share
3 answers
  • Silent crash, enable --info . This is probably the biggest barrier to debugging the problem. For some reason, the people who wrote the wagon-git deployer decided to write error messages at the information level. This way gradle fails without showing you any error messages. This is one of the messages I received when I turned on --info :

     [INFO] [git] fatal: ' git@bitbucket.org /foragerr/mvn-deploy-test.git' does not appear to be a git repository 

This is apparently a fatal error, but as for gradle, everything is fine and dandy. When you start reading these error messages, we can make real progress!

  1. git url: git URL as described here , starts with git: The wagon git deployment is activated when the URL starts with git: . It is possible to use the https: URL, but the maven plugin will use the internal deployer, not wagon-git. To use wagon-git explicitly, the url must start with git:

     repository(url: "git:releases:// git@bitbucket.org :foragerr/mvn-bitbucket-deploy-test.git") 

Where
releases - branch
foragerr - username bitbucket
mvn-bitbucket-deploy-test - repo bitbucket

  1. Authentication: wagon-git uses SSH to connect to the bitpack. You need to configure both git at the local end and relaying the bitpack at the remote end to use SSH.

    • Configuring SSH for git (I do not recommend using an access code, less secure, but convenient for automatic deployment)
  2. All set! expand into the bitbucket repository using gradle uploadArchives . See an example repo here .

Build.gradle example:

  group 'net.foragerr.test' version '1.2-SNAPSHOT' apply plugin: 'java' apply plugin: 'maven' sourceCompatibility = 1.5 repositories { mavenCentral() maven { url "https://raw.github.com/synergian/wagon-git/releases" } } configurations { deployerJar } dependencies { testCompile group: 'junit', name: 'junit', version: '4.11' deployerJar "ar.com.synergian:wagon-git:0.2.3" } uploadArchives { repositories.mavenDeployer { configuration = configurations.deployerJar; repository(url: "git:releases:// git@bitbucket.org :foragerr/mvn-bitbucket-deploy-test.git") } } 
+6
source share

Here is all you need to do, you even need to use the git protocol ( this example shows how to use HTTPS instead ):

1) create an application password for your application on Bitbucket

 https://bitbucket.org/account/user/YOUR_USERNAME_HERE/app-passwords 

2) inside build.gradle:

 apply plugin: 'java' apply plugin: 'maven' // artifact --> rootProject.name at settings.gradle <-- // DOWN HERE just add your artifact INFO group = 'br.com.fora.temer' version = '0.1-SNAPSHOT' description = """Diretas Ja""" dependencies { // your dependencies goes here, like this --> // compile group: 'br.gov.governo', name: 'golpista', version:'2.0' } apply from: 'uploadArchives.gradle' // --> deploy configuration 

3) inside uploadArchives.gradle (you need to create it):

 configurations { deployerJars } dependencies { deployerJars "ar.com.synergian:wagon-git:0.2.5" // plugin } uploadArchives { configuration = configurations.archives repositories.mavenDeployer { configuration = configurations.deployerJars repository(url: "git:releases://https://YOUR_USERNAME: YOUR_APP_PASSWORD@bitbucket.org /YOUR_COMPANY/repo-release.git") snapshotRepository(url: "git:snapshots://https://YOUR_USERNAME: YOUR_APP_PASSWORD@bitbucket.org /YOUR_COMPANY/repo-snapshot.git") } } allprojects { repositories { mavenCentral() maven { url "https://raw.github.com/synergian/wagon-git/releases"} } } 

For deployment:

 gradle uploadArchives 

TIP: be careful with the order of the entries ... if you change it, it will break everything.

+4
source share

I know the question is old, but there is not much information on this topic, so I think this is the right place to add some tips. I ran into the same problems, there seemed to be no way to make it work. So there are some tips that may help:

  • As already mentioned, all this maven plugin wagon thingy uses SSH to connect to the repository (Bitbucket in my case). So you need to check a few things:
    • what Bitbuchet knows about your SSH key.go in your profile settings ( not repository settings! ) β†’ SSH keys and put the public key obtained with keygen there. In the small β€œInsert Key” window on Bitbucket, there is an instruction to help you.
    • that you added your private keygen generated by keygen to your ssh agent (type ssh-add ~ / .ssh / id_rsa fot Linux and possibly mac)
    • also add credentials to your repository item:

repository(url: 'git:releases:// git@bitbucket.org :gendalf/repo.git'){ authentication(userName: "gendalf", password: "swordfish") }

  1. This plugin will not get confused in your output file. When I started uploading my library to the repository, I had flavors , so the plugin did not know which option to choose and not select anything (apparently).

    • As far as I know, this material does not work with aromas. Therefore, if you have tastes in the library that you send to a private repository ... think about getting rid of the aromas. You probably don't need them anyway.
  2. if you tried other publishing plugins before trying maven (for example maven-publish ), comment out all the script associated with other materials, or delete them. My gradle was confused due to extra scripts.
  3. Think about this solution https://jeroenmols.com/blog/2016/02/05/wagongit/ . This is what I used to finally publish, although it is rather confusing due to validation from your newly created repository. Do not check. Create a repository and publish right after that.

Hope this helps.

0
source share

All Articles