How to publish in my maven local repository an existing aar with gradle?
Asked Answered
L

2

2

I have a project that have the following structure:

  • projectRoot

  • build.gradle

  • module1/

    • build.gradle

    • artifact1.aar

  • module2/ ....

My artifact1.aar is a compiled artifact and i have no access to the sources.

my module 1 gradle build file is the following:

configurations.maybeCreate("default")
artifacts.add("default", file('artifact1.aar'))

With this the code contains in the .aar is available in module 2 by simply reference a gradle project dependency.

But i want to publish the .aar in my maven local, in order that it can be accessible for other android project.

I check the maven-publish plugin and the android-maven-publish plugin but the two seems to be called after java-library plugin or com.android.library plugin.

So my question is how to publish in my maven local repository an existing aar with gradle ?

I'm using gradle in version 4.8.

Lorrin answered 10/8, 2018 at 9:58 Comment(0)
D
15

I used an rxbinding aar for this example.

  1. As you correctly mentioned, there has to be a subproject in the "publisher" project, which must contain the aar, and a build file with the following content:

    // rxbinding/build.gradle
    apply plugin: "maven-publish"
    
    configurations.maybeCreate("default")
    def publishArtifact = artifacts.add("default", file('rxbinding-2.1.1.aar'))
    
    publishing {
        publications {
                aar(MavenPublication) {
                groupId = 'my.sample.artifact'
                artifactId = 'somerandomname'
                version = '1.0.0'
                artifact publishArtifact
            }
        }
    }
    

    You can apply the maven-publish plugin to any project, but then you have to define the artifacts manually, like we've just done here. Some plugins (like the java-library plugin) are integrated with the maven-publish plugin to automatically publish the default artifacts of the project.

  2. Now run ./gradlew rxbinding:publishToMavenLocal - This should place the artifact into your local repo

  3. Add implementation 'my.sample.artifact:somerandomname:1.0.0' to the consumer app, in any project on your machine.

It is very important to mention any aar published this way, will not bring it's dependencies, so you have to know what libs are needed to actually use the published aar.

I have also created an example project, where you can try this.

Derekderelict answered 10/8, 2018 at 11:36 Comment(1)
Thanks Balasz :). Exactly what I was looking for.Mollymollycoddle
A
0

If you have maven installed, you could use the install-file goal of the maven-install-plugin.

Apyretic answered 10/8, 2018 at 12:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.