- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用maven-publish
插件来部署android 库(.aar
)。
我的库还有一个依赖,也是.aar
如何从 build.gradle
的 dependencies
部分导入所有依赖项:
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.android.support:support-v4:23.1.1'
compile ('com.android.support:recyclerview-v7:22.2.1'){
exclude group: 'com.android.support', module: 'support-v4'
}
compile 'com.inthecheesefactory.thecheeselibrary:stated-fragment-support-v4:0.10.0'
//Http communication, websockets, etc.
compile 'com.squareup.okhttp:okhttp:2.4.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
//Fonts
compile 'uk.co.chrisjenx:calligraphy:2.1.0'
//Unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.9.5'
//Other
compile ('org.apache.commons:commons-lang3:3.4'){
exclude group: 'org.apache.httpcomponents'
}
//Reactive programmnig
compile 'io.reactivex:rxjava:1.0.13'
compile 'io.reactivex:rxandroid:0.25.0'
compile 'com.github.bumptech.glide:glide:3.6.1'
}
生成pom.xml
dependencies
部分:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.my.sdk</groupId>
<artifactId>SDK</artifactId>
<version>0.0.1</version>
<packaging>aar</packaging>
<dependencies>
...
</dependencies>
</project>
我找到了一些关于如何做类似事情的解释:
Optional Gradle dependencies for Maven libraries
How to change artifactory runtime scope to compile scope?
https://issues.gradle.org/browse/GRADLE-1749
所以,我明白了,我应该使用 pom.withXml
,从 project.configurations.compile.allDependencies
导入所有依赖项,范围为 compile
,并将其放入 asNode().dependencies
但是我不熟悉,我觉得我做错了什么。这是我当前的代码:
publishing {
publications {
maven(MavenPublication) {
artifact "${project.buildDir}/outputs/aar/${project.name}-release.aar"
artifactId = POM_ARTIFACT_ID
groupId = GROUP
version = VERSION_NAME
// Task androidSourcesJar is provided by gradle-mvn-push.gradle
//artifact androidSourcesJar {
// classifier "sources"
//}
pom.withXml {
def depsNode = asNode().dependencies.'*'
project.configurations.compile.allDependencies.each { dep ->
if(dep.name != null && dep.group != null && dep.version != null) {
def depNode = new Node(null, 'dependency')
def groupIdNode = new Node(depNode, 'groupId', dep.getGroup())
def artifactIdNode = new Node(depNode, 'artifactId', dep.getName())
def versionNode = new Node(depNode, 'version', dep.getVersion())
depsNode.add(depNode)
println depsNode
}
}
}
}
}
repositories {
maven {
credentials {
username System.getenv('NEXUS_USER_NAME')
password System.getenv('NEXUS_PASSWORD')
}
url "http://nexus-repo"
}
}
}
最佳答案
要发布一个.aar
库并在pom.xml 中正确列出依赖关系,使用this 可能更容易。插件,而不是使用 maven-publish 插件自己组装依赖项部分。
应用插件:
plugins {
id "com.github.dcendents.android-maven" version "1.3"
}
并运行任务 install
将库推送到本地 .m2 存储库。
您可以像这样覆盖正在发布的仓库:
install {
repositories {
mavenDeployer {
repository(...)
}
}
}
如果您愿意,当然可以继续使用 maven-publish
插件。在您的代码中,您正在寻找尚不存在的 depsNode
。您可能需要为 depsNode 创建一个新节点并首先将其添加到 pom。或者只使用追加:
pom.withXml {
def depsNode = asNode().appendNode('dependencies')
configurations.compile.allDependencies.each { dep ->
def depNode = depsNode.appendNode('dependency')
depNode.appendNode('groupId', dep.group)
depNode.appendNode('artifactId', dep.name)
depNode.appendNode('version', dep.version)
//optional add scope
//optional add transitive exclusions
}
}
这里需要注意的是,您仍然需要正确处理排除项。此外,如果您的项目中有变体,并且有不同的编译配置,例如 androidCompile
或 somethingElseCompile
,您也需要正确处理这些配置。
关于maven - 如何将依赖项从 build.gradle 导入到 pom.xml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34484733/
我是一名优秀的程序员,十分优秀!