万一有人需要,经过大量的Google搜索,并尝试了一些gradle插件(mobbeel,kezong等),我终于得出结论,在github包中添加依赖项是一个坏主意,因此最终用户应该包括那些依赖项。也就是说,最终用户应通过以下方式添加gradle依赖项:
dependencies{
implementation 'com.mycompany:mylibrary:1.2.3' // <-- the actual lirbary
// library dependencies
implementation 'com.alimuzaffar.lib:pinentryedittext:2.0.6'
implementation "com.google.android.gms:play-services-auth-api-phone:17.3.0"
// other dependencies of end user's app
// ... ... ...
}
,
- 本教程中显示的库文件(aar)将不包含传递依赖项。
- 对于Maven仓库,Gradle将使用包含依赖项列表的pom文件下载依赖项。
- 在教程所示的项目中,pom文件不会生成嵌套的依赖项列表。您必须在项目中指定依赖项,或者必须修改代码以生成包含依赖项的pom文件。
- 使用以下代码并在Android库模块中更新build.gradle文件,以生成包含相关依赖项信息的.pom文件。
publications {
bar(MavenPublication) {
groupId getGroupId()
artifactId getArtificatId()
version getVersionName()
artifact("$buildDir/outputs/aar/${getArtificatId()}-release.aar")
pom.withXml {
final dependenciesNode = asNode().appendNode('dependencies')
ext.addDependency = { Dependency dep,String scope ->
if (dep.group == null || dep.version == null || dep.name == null || dep.name == "unspecified")
return // ignore invalid dependencies
final dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId',dep.group)
dependencyNode.appendNode('artifactId',dep.name)
dependencyNode.appendNode('version',dep.version)
dependencyNode.appendNode('scope',scope)
if (!dep.transitive) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
exclusionNode.appendNode('groupId','*')
exclusionNode.appendNode('artifactId','*')
} else if (!dep.properties.excludeRules.empty) {
final exclusionNode = dependencyNode.appendNode('exclusions').appendNode('exclusion')
dep.properties.excludeRules.each { ExcludeRule rule ->
exclusionNode.appendNode('groupId',rule.group ?: '*')
exclusionNode.appendNode('artifactId',rule.module ?: '*')
}
}
}
configurations.compile.getDependencies().each { dep -> addDependency(dep,"compile") }
configurations.api.getDependencies().each { dep -> addDependency(dep,"compile") }
configurations.implementation.getDependencies().each { dep -> addDependency(dep,"runtime") }
}
}
}
上面的代码来自Publish an Android library to Maven with aar and source jar
本文链接:https://www.f2er.com/3068090.html