[英]How to publish in my maven local repository an existing aar with gradle?
I have a project that have the following structure: 我有一个具有以下结构的项目:
projectRoot projectRoot
build.gradle build.gradle
module1/ 模块1 /
build.gradle build.gradle
artifact1.aar artifact1.aar
module2/ .... module2 / ....
My artifact1.aar is a compiled artifact and i have no access to the sources. 我的artifact1.aar是已编译的工件,我无法访问源。
my module 1 gradle build file is the following: 我的模块1 gradle构建文件如下:
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. 这样,只需引用gradle项目依赖项,模块2中就可以使用.aar中包含的代码。
But i want to publish the .aar in my maven local, in order that it can be accessible for other android project. 但我想在我的Maven本地发布.aar,以便其他Android项目可以访问它。
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-publish插件和android-maven-publish插件,但两者似乎在java-library插件或com.android.library插件之后被调用。
So my question is how to publish in my maven local repository an existing aar with gradle ? 所以我的问题是如何在我的Maven本地存储库中发布带有gradle的现有aar?
I'm using gradle in version 4.8. 我在4.8版中使用gradle。
I used an rxbinding aar for this example. 在此示例中,我使用了rxbinding aar。
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: 正如您正确提到的,“发布者”项目中必须有一个子项目,该子项目必须包含aar和一个包含以下内容的构建文件:
// 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. 您可以将maven-publish
插件应用于任何项目,但是随后您必须手动定义工件,就像我们在这里所做的那样。 Some plugins (like the java-library
plugin) are integrated with the maven-publish
plugin to automatically publish the default artifacts of the project. 一些插件(例如java-library
插件)与maven-publish
插件集成在一起,以自动发布项目的默认工件。
Now run ./gradlew rxbinding:publishToMavenLocal
- This should place the artifact into your local repo 现在运行./gradlew rxbinding:publishToMavenLocal
这应该将工件放入本地./gradlew rxbinding:publishToMavenLocal
implementation 'my.sample.artifact:somerandomname:1.0.0'
to the consumer app, in any project on your machine. 在计算机上的任何项目中,将implementation 'my.sample.artifact:somerandomname:1.0.0'
到使用者应用程序。 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. 提及以这种方式发布的任何aar都非常重要,不会带来它的依赖关系,因此您必须知道实际使用发布的aar所需的库。
I have also created an example project , where you can try this. 我还创建了一个示例项目 ,您可以在其中进行尝试。
如果已安装maven,则可以使用maven-install-plugin
的install-file
目标。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.