我有这样一个项目:
MyProject
|-ModuleA
|-ModuleB
模块 A 是一个创建 aar 的 Android 库,它依赖于模块 B,如下所示:
dependencies {
compile project(':ModuleB')
在 ModuleA 中,我使用 mavenDepoyer
在本地发布:
uploadArchives {
repositories.mavenDeployer {
pom.groupId = "com.foo"
pom.artifactId = "bar"
pom.version = "1.0"
repository(url: "file://${localReleaseDest}")
}
}
这会生成一个 AAR
文件和一个 POM
。
当解压缩 AAR
不包含模块 B 中的类文件
POM
看起来像这样:
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.foo</groupId>
<artifactId>bar</artifactId>
<version>1.0</version>
<packaging>aar</packaging>
<dependencies>
<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
如您所见,这声明 AAR
依赖于未指定版本的 ModuleB。因此,如果我将此 AAR/POM
用作远程,它无法解析依赖项 ModuleB。
Error:A problem occurred configuring project ':example'.
Could not resolve all dependencies for configuration ':example:_debugCompile'.
Could not find MyProject:ModuleB:unspecified.
Searched in the following locations:
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.pom
https://jcenter.bintray.com/MyProject/ModuleB/unspecified/ModuleB-unspecified.jar
Required by:
Test:example:unspecified > com.foo:MyProject:1.0
我不希望它尝试将模块 B 解析为另一个依赖项,我想使用 mavenDeployer 来创建 AAR
和 POM
模块 B 包含在里面,因为我这里有源代码来做到这一点!
网上搜索无果,这些网站给出了提示但没有答案:
How to publish apks to the Maven Central with gradle?
how to tell gradle to build and upload archives of dependent projects to local maven
http://www.gradle.org/docs/current/userguide/artifact_management.html
http://gradle.org/docs/current/userguide/userguide_single.html#sub:multiple_artifacts_per_project
http://gradle.org/docs/current/userguide/userguide_single.html#deployerConfig
最佳答案
据我所知,AAR 不包含它们的依赖项(只有 APK 包含)。相反,传递依赖解析不仅会解析 AAR,还会解析它的依赖。未指定的版本很可能是未在 ModuleB 中设置 project.version
属性的结果。
关于java - Gradle mavenDeployer - 如何包含单独的模块代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26939628/