我有一个这样的项目:
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
&amp;其中包含模块B的POM
,因为我在这里有源代码!
搜索网络无济于事,这些网站给出了提示,但没有答案:
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
答案 0 :(得分:2)
据我所知,AAR没有包含他们的依赖关系(只有APK)。相反,传递依赖性解决方案不仅要解决AAR,还要解决其依赖关系。未指定的版本很可能是因为未在ModuleB中设置project.version
属性。
答案 1 :(得分:0)
<dependency>
<groupId>MyProject</groupId>
<artifactId>ModuleB</artifactId>
<version>unspecified</version>
<scope>compile</scope>
</dependency>
原因是您的模块依赖性如下:
compile project(':module B')
要解决此问题,您应该取决于maven dep 编译'com.xxxxxx.xxx:xxxxx:1.0.0-SHNAPSHOT'