如何在我的Maven本地存储库中发布带有gradle的现有aar? [英] How to publish in my maven local repository an existing aar with gradle?

查看:457
本文介绍了如何在我的Maven本地存储库中发布带有gradle的现有aar?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构的项目:

I have a project that have the following structure:

  • projectRoot

  • projectRoot

build.gradle

build.gradle

模块1/

  • build.gradle

  • build.gradle

artifact1.aar

artifact1.aar

模块2/ ....

我的artifact1.aar是已编译的工件,我无权访问源.

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

我的模块1 gradle构建文件如下:

my module 1 gradle build file is the following:

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

通过此操作,只需引用gradle项目依赖项,即可在模块2中获得.aar中包含的代码.

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

但是我想在我的maven本地发布.aar,以便其他Android项目可以访问它.

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

我检查了maven-publish插件和android-maven-publish插件,但两者似乎在java-library插件或com.android.library插件之后被调用.

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.

所以我的问题是如何在我的Maven本地存储库中发布带有gradle的现有aar?

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

我在4.8版中使用gradle.

I'm using gradle in version 4.8.

推荐答案

在此示例中,我使用了rxbinding aar.

I used an rxbinding aar for this example.

  1. 正如您正确提到的那样,发布者"项目中必须有一个子项目,该子项目必须包含aar和具有以下内容的构建文件:

  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
        }
    }
}

您可以将maven-publish插件应用于任何项目,但是您必须手动定义工件,就像我们在这里所做的那样.某些插件(如java-library插件)与maven-publish插件集成在一起,以自动发布项目的默认工件.

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.

现在运行./gradlew rxbinding:publishToMavenLocal-这会将工件放入您的本地存储库

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

提及以这种方式发布的任何aar都非常重要,不会带来它的依赖关系,因此您必须知道实际使用发布的aar所需的库.

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本地存储库中发布带有gradle的现有aar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆