我正在使用Gradle构建一个Android库项目并将其部署到maven仓库作为一个aar。
该库有一些依赖项,应包含在POM中。
使用apply plugin: 'maven'
时,没有POM文件,只有artifact。
使用apply plugin: 'maven-publish'
会生成一个POM文件,但不包括任何依赖项。
有什么想法吗?这是不支持的吗?
Gradle 2.2和Android Gradle插件1.1.0
第一种方法:
configurations {
archives {
extendsFrom configurations.default
}
}
afterEvaluate { project ->
uploadArchives {
configuration = configurations.archives
repositories {
mavenDeployer {
repository(url: "http://nexus-url") {
authentication(userName: nexusUsername, password: nexusPassword)
pom.groupId = 'com.example'
pom.version = '123-SNAPSHOT'
pom.artifactId = 'foo'
pom.packaging = 'aar'
pom.project {
artifactId = 'bar'
packaging 'aar'
description 'baz'
}
}
}
}
也尝试了在不用afterEvaluate
包裹的情况下进行测试。
第二种方法:
publishing {
publications {
sdk(MavenPublication) {
groupId 'com.example'
artifactId 'foo'
version = "0.123-SNAPSHOT"
artifact("$buildDir/outputs/aar/app-sdk-debug.aar")
}
}
repositories {
maven {
url "http://nexus-url"
credentials {
username 'foo'
password 'bar'
}
}
}
}
更新
问题的根本原因是该项目使用了flavors。如果不使用flavors,在使用apply plugin: 'maven'
时,pom文件将被正确生成。
configurations.compile.allDependencies.withType(ModuleDependency)
替换configurations.compile.allDependencies.each
,以避免在使用compile fileTree(dir: 'libs', include: ['*.jar'])
时出现异常。 - Denys VasylenkomatchingFallbacks
可以帮助解决问题?https://developer.android.com/studio/build/dependencies#resolve_matching_errors - Philipp E.java
插件来解决,但是依赖项仍然缺失。 - desgraci