我有一个包含多个模块的库项目,因此我将其依赖项集中在项目级别 build.gradle 中,如下所示
ext {
compileSdkVersion = 23
minSdkVersion = 9
targetSdkVersion = 24
buildToolsVersion = '23.0.3'
junit = 'junit:junit:4.12'
mockito = 'org.mockito:mockito-core:1.10.19'
testRunner = 'com.android.support.test:runner:0.5'
appcompat = 'com.android.support:appcompat-v7:24.1.0'
retrofit2 = 'com.squareup.retrofit2:retrofit:2.1.0'
gsonConverter = 'com.squareup.retrofit2:converter-gson:2.1.0'
httpLogInterceptor = 'com.squareup.okhttp3:logging-interceptor:3.4.1'
design = 'com.android.support:design:24.1.0'
cardview = 'com.android.support:cardview-v7:24.1.1'
universalImageLoader = 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
}
我在模块中使用它作为
dependencies {
compile project(':module1')
compile rootProject.appcompat
compile rootProject.retrofit2
compile rootProject.gsonConverter
compile rootProject.httpLogInterceptor
compile rootProject.design
compile rootProject.cardview
compile rootProject.universalImageLoader
testCompile rootProject.junit
testCompile rootProject.mockito
androidTestCompile rootProject.junit
androidTestCompile rootProject.testRunner
}
在我的示例应用程序(同一项目中的另一个模块)中,我将库模块包含为 compile project(':module2')
& 它工作正常,但现在我在 jcenter 中发布了 sdk & if我在新应用程序中使用它,我在库中提到的依赖项没有解决。
我尝试包含像
这样的依赖项compile ('com.github.xxx:module2:1.0.0@aar') {
transitive=true
}
和
compile 'com.github.xxx:module2:1.0.0'
和
compile ('com.github.xxx:module2:1.0.0') {
transitive=true
}
我已经尝试过
How to specify dependencies in aar library?
Can an AAR include transitive dependencies?
如果我错过任何信息,请评论
提前致谢
最佳答案
回答我自己的问题,这样可能对任何人都有用。感谢@Gabriele Mariotti, 我检查了生成的 pom,因为没有可用的依赖项标记,因此搜索并找到了 snippet添加它。
但是他们在publications
中添加了它,在我的例子中,一个模块依赖于另一个尚未发布的模块,该依赖关系在 module2 的 build.gradle 中提到as complie project(':module1')
并生成新的 pom,其中不包含出版物文件夹中的名称、描述等标签。
所以我将它添加到之前的 pom 字段创建区域并且它对我有用
这是gradle-mvn-push.gradle的更新部分
if (project.getPlugins().hasPlugin('com.android.application') ||
project.getPlugins().hasPlugin('com.android.library')) {
task install(type: Upload, dependsOn: assemble) {
repositories.mavenInstaller {
configuration = configurations.archives
pom.groupId = GROUP
pom.artifactId = POM_ARTIFACT_ID
pom.version = VERSION_NAME
pom.project {
name POM_NAME
packaging POM_PACKAGING
description POM_DESCRIPTION
url POM_URL
scm {
url POM_SCM_URL
connection POM_SCM_CONNECTION
developerConnection POM_SCM_DEV_CONNECTION
}
licenses {
license {
name POM_LICENCE_NAME
url POM_LICENCE_URL
distribution POM_LICENCE_DIST
}
}
developers {
developer {
id pom_developer_id
name pom_developer_name
}
}
}
//Updated part which adds dependencies in pom
pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')
//Iterate over the compile dependencies (we don't want the test ones), adding a <dependency> node for each
configurations.compile.allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
关于android - 如何指定具有多个模块的库(sdk)中的依赖关系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39701553/