如何从进口的build.gradle依赖判断的pom.xml [英] How to import dependecies from build.gradle to pom.xml
问题描述
我用 Maven的发布
插件部署的Android库( .aar
)。
我的图书馆有另外的依赖,这也是 .aar
如何导入所有依赖从的build.gradle
,依赖
部分:
{相关性
编译文件树(导演:'库',包括:['的* .jar'])
编译com.android.support:appcompat-v7:23.1.1
编译com.android.support:design:23.1.1
编译com.android.support:support-v4:23.1.1
编译('com.android.support:recyclerview-v7:22.2.1'){
排除组:com.android.support',模块:支持-V4
}
编译com.inthecheesefactory.thecheeselibrary:表示片段的支持-V4:0.10.0 // HTTP通信的WebSockets等。
编译com.squareup.okhttp:okhttp:2.4.0
编译com.squareup.retrofit:改造:1.9.0 //字体
编译uk.co.chrisjenx:书法:2.1.0 //单元测试
testCompile'的JUnit:JUnit的:4.12
testCompile'org.mockito:的Mockito核心:1.9.5 //其他
编译('org.apache.commons:公地lang3:3.4'){
排除组:org.apache.httpcomponents
} //无功programmnig
编译io.reactivex:rxjava:1.0.13
编译io.reactivex:rxandroid:0.25.0 编译com.github.bumptech.glide:滑翔:3.6.1
}
要生成的的pom.xml
依赖
部分:
<项目的xmlns =http://maven.apache.org/POM/4.0.0的xmlns:XSI =http://www.w3.org/2001 / XML模式实例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 GT; com.my.sdk< /的groupId>
<&的artifactId GT; SDK开发及LT; / artifactId的>
<&版GT; 0.0.1< /版本>
<包装和GT;&AAR LT; /包装><依赖和GT;
...
< /依赖和GT;< /项目>
我发现了一些解释如何做类似的事情:
<一个href=\"http://stackoverflow.com/questions/25345804/optional-gradle-dependencies-for-maven-libraries\">Optional摇篮依赖对Maven库
<一个href=\"http://stackoverflow.com/questions/31069666/how-to-change-artifactory-runtime-scope-to-compile-scope\">How改变artifactory的运行时间范围,编制范围?
https://issues.gradle.org/browse/GRADLE-1749
<一个href=\"http://www.scriptscoop.net/t/6ac07fb41846/how-to-maven-publish-a-gradle-project-jar-with-provided-scope.html\" rel=\"nofollow\">http://www.scriptscoop.net/t/6ac07fb41846/how-to-maven-publish-a-gradle-project-jar-with-provided-scope.html
所以,我明白了,我应该用 pom.withXml
,进口从 project.configurations.compile.allDependencies $ C全部依赖条件$ C>作用域
编译
,并把它变成 asNode()。依赖性
但我不熟悉,我觉得我做错了什么。这是我目前的code:
出版{
出版物{
行家(MavenPublication){
神器$ {} project.buildDir /输出/ AAR / $ {} project.name -release.aar
的artifactId = POM_ARTIFACT_ID
的groupId =集团
版本= VERSION_NAME //任务androidSourcesJar由gradle这个-MVN-push.gradle提供
//神器androidSourcesJar {
//分类源
//} pom.withXml {
高清depsNode = asNode()的依赖。*
project.configurations.compile.allDependencies.each {DEP - &GT;
如果(dep.name = NULL&放大器;!&安培; dep.group = NULL&放大器;!&安培;!dep.version = NULL){
高清depNode =新节点(NULL,'依赖') 高清groupIdNode =新节点(depNode的groupId',dep.getGroup())
高清artifactIdNode =新节点(depNode的artifactId',dep.getName())
高清versionNode =新节点(depNode,'版本',dep.getVersion())
depsNode.add(depNode)
的println depsNode
}
}
}
}
} 库{
行家{
凭据{
用户名System.getenv('NEXUS_USER_NAME')
密码System.getenv('NEXUS_PASSWORD')
}
URL的http:// NEXUS-回购
}
}
}
要发布在pom.xml中正确列出的依赖关系的 .aar
库,它可能会更容易使用这插件,而不是使用自己组装的依赖性部分Maven的发布插件。
要应用插件:
插件{
IDcom.github.dcendents.android Maven的版本1.3
}
和运行任务安装
推图书馆本地回购的.m2
您可以覆盖回购发布到这样的:
安装{
库{
mavenDeployer {
库(...)
}
}
}
您当然可以继续使用 Maven的发布
插件,如果你愿意的preFER。在您的code,你正在寻找 depsNode
不存在。您可能需要为depsNode一个新节点,它首先添加到POM。或者只是使用附加:
pom.withXml {
高清depsNode = asNode()。appendNode('依赖') configurations.compile.allDependencies.each {DEP - &GT;
高清depNode = depsNode.appendNode('依赖')
depNode.appendNode('的groupId',dep.group)
depNode.appendNode('的artifactId',dep.name)
depNode.appendNode('版本',dep.version)
//可选附加范围
//可选添加传递排除
}
}
在这里需要说明的是,你仍然需要正确地处理除外。另外,如果你在你的项目的变种,并有不同的编译配置,如 androidCompile
或 somethingElseCompile
,你需要处理这些正确的为好。
I use maven-publish
plugin for deploying android library(.aar
).
My library has another dependencies, which are also .aar
How can I import all dependencies from build.gradle
, dependencies
section:
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'
}
To generated pom.xml
dependencies
section:
<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>
I found some explanation how to do similar things:
Optional Gradle dependencies for Maven libraries
How to change artifactory runtime scope to compile scope?
https://issues.gradle.org/browse/GRADLE-1749
So, I understood, that I should use pom.withXml
, import all dependecies from project.configurations.compile.allDependencies
with scope compile
, and put it into asNode().dependencies
But I'm not familiar with it, and I think I doing something wrong. Here is my current code:
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"
}
}
}
To publish a .aar
library with the dependencies listed correctly in pom.xml, it might be easier to use this plugin, rather than assemble the dependencies section yourself using the maven-publish plugin.
To apply plugin:
plugins {
id "com.github.dcendents.android-maven" version "1.3"
}
and run task install
to push library to local .m2 repo.
You can override the repo being published to like this:
install {
repositories {
mavenDeployer {
repository(...)
}
}
}
You can of course, continue to use the maven-publish
plugin if you so prefer. In your code, you're looking for depsNode
which does not already exist. You likely need to create a new Node for depsNode and add it to the pom first. Or just use append:
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
}
}
The caveat here is that, you still need to handle exclusions correctly. Also, if you have variants in your project, and have different compile configurations such as androidCompile
or somethingElseCompile
, you need to handle those correctly as well.
这篇关于如何从进口的build.gradle依赖判断的pom.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!