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

跟風遠走 提交于 2019-12-23 06:31:22

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/51783925/how-to-publish-in-my-maven-local-repository-an-existing-aar-with-gradle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!