我有一个摇篮的项目,我需要它的所有的依赖被转移并与另一个Maven项目使用。 换句话说,我怎么能产生(或我可以生成)从的build.gradle pom.xml中?
Answer 1:
内置的解决方案,最很可能会使用archiveTask
在Maven插件任务,这将产生在一个POM poms
在build目录文件夹。 http://www.gradle.org/docs/current/userguide/maven_plugin.html#sec:maven_pom_generation
Answer 2:
当使用摇篮的Maven插件 , 安装任务会自动添加到您的任务,并调用它总是会产生一个POM文件。
所以,如果你的build.gradle文件是这样的:
apply plugin: 'java'
apply plugin: 'maven'
group = 'myGroup'
// artifactId is taken by default, from folder name
version = '0.1-SNAPSHOT'
dependencies {
compile 'commons-lang:commons-lang:2.3'
}
您可以拨打gradle install
的文件夹中,你会发现在build /劲歌子文件夹中,文件名为POM-default.xml中 ,将包含的依赖关系。 此外,内置与POM一起JAR会在你的Maven本地回购。
Answer 3:
由于我不想在我的本地回购安装任何东西,我做以下,相反,阅读文档后。 添加在您的build.gradle
apply plugin: 'maven'
group = 'com.company.root'
// artifactId is taken by default, from folder name
version = '0.0.1-SNAPSHOT'
task writeNewPom << {
pom {
project {
inceptionYear '2014'
licenses {
license {
name 'The Apache Software License, Version 2.0'
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
distribution 'repo'
}
}
}
}.writeTo("pom.xml")
}
运行它gradle writeNewPom
@a_horse_with_no_name
正在gradle这个用Groovy做可以尝试结束后添加}项目块
build{
plugins{
plugin{
groupId 'org.apache.maven.plugins'
artifactId 'maven-compiler-plugin'
configuration{
source '1.8'
target '1.8'
}
}
}
}
没有尝试,胡乱猜测!
Answer 4:
如果你没有安装的gradle“写gradle这个任务来完成不是很Userful公司除了用依赖条件安装此100MB兽我做了过滤器的gradle转换到依赖Maven依赖:
cat build.gradle\
| awk '{$1=$1};1'\
| grep -i "compile "\
| sed -e "s/^compile //Ig" -e "s/^testCompile //Ig"\
| sed -e "s/\/\/.*//g"\
| sed -e "s/files(.*//g"\
| grep -v ^$\
| tr -d "'"\
| sed -e "s/\([-_[:alnum:]\.]*\):\([-_[:alnum:]\.]*\):\([-+_[:alnum:]\.]*\)/<dependency>\n\t<groupId>\1<\/groupId>\n\t<artifactId>\2<\/artifactId>\n\t<version>\3<\/version>\n<\/dependency>/g"
这种转换
compile 'org.slf4j:slf4j-api:1.7.+'
compile 'ch.qos.logback:logback-classic:1.1.+'
compile 'commons-cli:commons-cli:1.3'
成
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.+</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.+</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3</version>
</dependency>
pom.xml中的其余部分应该用手工来创建。
文章来源: Gradle build.gradle to Maven pom.xml