简体   繁体   中英

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

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.

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.

如果已安装maven,则可以使用maven-install-plugininstall-file目标。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM