Maven项目作为Gradle项目的依赖项 [英] maven project as dependency in gradle project

查看:192
本文介绍了Maven项目作为Gradle项目的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Gradle作为构建工具的项目,第二个使用Maven的POM的子项目。我没有在子项目上更改构建工具的自由。



我想要实现的是将Maven POM添加为依赖于我的Gradle项目的项目。

其中root(current dir)是我的Gradle项目并包含 build.gradle ,Maven项目是在 vendor / other-proj / 下,在POM文件的目录下。



build.gradle 档案:



第一次尝试:

 include(vendor / other-proj /)
project(':other-proj'){
projectDir = new File(vendor / other-proj /pom.xml)
}

依赖关系{
编译项目(':other-proj')
}


$ b <第二次尝试: $ b compile project('vendor / other-proj /')
}

第三次尝试:

 依赖关系{
compile project('v endor / other-proj / pom.xml')
}

第四次尝试: p>

 依赖关系{
编译文件'vendor / other-proj / pom.xml'
}

我在网上找不到任何相关的东西,似乎大部分的Gradle / Maven用例都受到发布到Maven的影响或者生成POM,但我不想做任何这些。



任何人都可以指出我正确的方向吗?



 依赖关系{ 
编译文件(vendor / other-proj / target / classes){
builtBycompileMavenProject
}
}

任务compileMavenProject(type :Exec){
workingDirvendor / other-proj /
commandLine/ usr / bin / mvn,clean,compile
}

在编译之前,Gradle将执行Maven构建( compileMavenProject )。但请注意,它不是传统意义上的Gradle项目,并且不会显示出来,例如如果你运行 gradle dependencies 。在你的Gradle项目中包含已编译的类文件只是一个窍门。



编辑:
您可以使用类似的技术来包含maven依赖项:

 依赖项{
编译文件(vendor / other-proj / target / classes){
builtBycompileMavenProject
}
编译文件(vendor / other-proj / target / libs){
builtBydownloadMavenDependencies
}
}

任务compileMavenProject(类型:Exec){
workingDirvendor / other-proj /
commandLine/ usr / bin / mvn,clean,compile
}

任务downloadMavenDependencies(type:Exec){
workingDirvendor / other-proj /
commandLine/ usr / bin / mvn,dependency:copy-依赖关系,-DoutputDirectory = target / libs
}


I have a project which is using Gradle as build tool and a second subproject which is using Maven's POM. I don't have the freedom of changing build tool on the subproject.

What I want to achieve is to add my project with Maven POM as dependency on my Gradle project.

Where root (current dir) is my project with Gradle and contains the build.gradle, the Maven project is under vendor/other-proj/ with POM file just under that directory.

I have tried these variations on my build.gradle file:

1st try:

include("vendor/other-proj/")
project(':other-proj') {
    projectDir = new File("vendor/other-proj/pom.xml")
}

dependencies {
    compile project(':other-proj')
}

2nd try:

dependencies {
    compile project('vendor/other-proj/')
}

3rd try:

dependencies {
    compile project('vendor/other-proj/pom.xml')
}

4th try:

dependencies {
    compile files 'vendor/other-proj/pom.xml'
}

I can't find anything related on the web, it seems most Gradle/Maven use cases are affected by publishing to Maven or generating POM, but I dont want to do any of those.

Can anybody point me to right direction?

解决方案

you can "fake" including a Maven project like this:

dependencies {
    compile files("vendor/other-proj/target/classes") {
        builtBy "compileMavenProject"
    }
}

task compileMavenProject(type: Exec) {
    workingDir "vendor/other-proj/"
    commandLine "/usr/bin/mvn", "clean", "compile"
}

This way Gradle will execute a Maven build (compileMavenProject) before compiling. But be aware that it is not a Gradle "project" in the traditional sense and will not show up, e.g. if you run gradle dependencies. It is just a hack to include the compiled class files in your Gradle project.

Edit: You can use a similar technique to also include the maven dependencies:

dependencies {
    compile files("vendor/other-proj/target/classes") {
        builtBy "compileMavenProject"
    }
    compile files("vendor/other-proj/target/libs") {
        builtBy "downloadMavenDependencies"
    }
}

task compileMavenProject(type: Exec) {
    workingDir "vendor/other-proj/"
    commandLine "/usr/bin/mvn", "clean", "compile"
}

task downloadMavenDependencies(type: Exec) {
    workingDir "vendor/other-proj/"
    commandLine "/usr/bin/mvn", "dependency:copy-dependencies", "-DoutputDirectory=target/libs"
}

这篇关于Maven项目作为Gradle项目的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆