简体   繁体   English

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

[英]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。

  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: 正如您正确提到的,“发布者”项目中必须有一个子项目,该子项目必须包含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插件集成在一起,以自动发布项目的默认工件。

  2. Now run ./gradlew rxbinding:publishToMavenLocal - This should place the artifact into your local repo 现在运行./gradlew rxbinding:publishToMavenLocal这应该将工件放入本地./gradlew rxbinding:publishToMavenLocal

  3. Add 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-plugininstall-file目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用maven-publish gradle插件附加AAR文件的源? - How to attach sources of an AAR file with maven-publish gradle plugin? 如何使用 JavaDocs 将 AAR 发布到 Maven Local - How do I publish an AAR to Maven Local With JavaDocs 使用Gradle将aar文件发布到Maven Central无法正常工作 - Publish an aar file to Maven Central with Gradle not working Gradle:如何将Android库发布到本地存储库 - Gradle: How to publish a Android library to local repository Android库 - 使用Gradle将多个变体发布到本地Maven存储库 - Android Library - Publish Multiple Variants to Local Maven Repository using Gradle 将AAR库上传到本地Maven存储库并在git中共享build.gradle - Upload AAR library to local maven repository and share build.gradle in git 无法使用gradle build dystem将生成的.aar文件上传到android studio中的本地Maven存储库 - Not able to upload the generated .aar file to local maven repository in android studio with gradle build dystem 如何将文档字符串添加到 build.gradle.kts 中的 android maven-publish.aar 文件? - How can I add docstrings to android maven-publish .aar files in build.gradle.kts? 如何使用Gradle将aar文件发布到Apache Archiva - How to publish aar file to Apache Archiva with Gradle 如何构建和 maven 发布 flutter aar? - How to build and maven-publish a flutter aar?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM