htm*_*m01 52 gradle pom.xml maven
我有一个Gradle项目,我需要将其所有依赖项转移并与另一个Maven项目一起使用.换句话说,我如何从build.gradle生成(或者我可以生成)pom.xml?
小智 64
使用Gradle的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'
}
Run Code Online (Sandbox Code Playgroud)
您可以gradle install在其文件夹中调用,您将在build/poms子文件夹中找到一个名为pom-default.xml的文件,该文件将包含依赖项.此外,内置的JAR和POM将在您的Maven本地回购中.
dil*_*ide 20
因为我不想在我的本地仓库中安装任何东西,所以我在阅读文档之后做了以下操作.添加你的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")
}
Run Code Online (Sandbox Code Playgroud)
运行它
gradle writeNewPom
@a_horse_with_no_name
使用groovy制作的gradle可以尝试在结束后添加}项目块
build{
plugins{
plugin{
groupId 'org.apache.maven.plugins'
artifactId 'maven-compiler-plugin'
configuration{
source '1.8'
target '1.8'
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
没试过,猜猜!
Mat*_*ple 13
最内置的解决方案可能是使用archiveTaskMaven插件中的任务,它将poms在您的构建目录中的文件夹中生成一个pom .http://www.gradle.org/docs/current/userguide/maven_plugin.html#sec:maven_pom_generation
and*_*rej 13
如果你没有安装gradle,那么"写gradle任务来执行此操作"并不是非常有用.我没有安装这个带有dependecies的100MB beast,而是将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"
Run Code Online (Sandbox Code Playgroud)
这转换
compile 'org.slf4j:slf4j-api:1.7.+'
compile 'ch.qos.logback:logback-classic:1.1.+'
compile 'commons-cli:commons-cli:1.3'
Run Code Online (Sandbox Code Playgroud)
成
<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>
Run Code Online (Sandbox Code Playgroud)
应该手动创建pom.xml的其余部分.
| 归档时间: |
|
| 查看次数: |
77640 次 |
| 最近记录: |