maven项目作为gradle项目中的依赖项

maven项目作为gradle项目中的依赖项,maven,gradle,Maven,Gradle,我有一个项目使用Gradle作为构建工具,还有一个子项目使用Maven的POM。我没有在子项目上更改构建工具的自由 我想要实现的是将我的项目添加到Maven POM中,作为对Gradle项目的依赖 其中root(当前目录)是我的Gradle项目,包含build.Gradle,Maven项目位于vendor/other proj/目录下,POM文件就在该目录下 我已经在我的build.gradle文件中尝试了这些变体: 第一次尝试: include("vendor/other-proj/") pr

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

我想要实现的是将我的项目添加到Maven POM中,作为对Gradle项目的依赖

其中root(当前目录)是我的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")
}

dependencies {
    compile project(':other-proj')
}
第二次尝试:

dependencies {
    compile project('vendor/other-proj/')
}
第三次尝试:

dependencies {
    compile project('vendor/other-proj/pom.xml')
}
第四次尝试:

dependencies {
    compile files 'vendor/other-proj/pom.xml'
}
我在网上找不到任何相关的东西,似乎大多数Gradle/Maven用例都会受到发布到Maven或生成POM的影响,但我不想做任何这些

有人能给我指出正确的方向吗?

你不能在gradle settings.gradle中“包含”maven项目。最简单的方法是构建maven项目并使用
mvn install
(可以是default.m2或任何其他自定义位置)将其安装到本地repo,然后使用groupname:modulename:version从gradle项目中使用它

repositories{
    mavenLocal()
}

dependencies{
    compile 'vendor:otherproj:version'
}
可以使用编译文件直接依赖maven项目的jar,但这并不理想,因为它无法获取可传递的依赖项,您必须自己手动添加这些依赖项。

您可以“伪造”maven项目,包括如下所示:

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

task compileMavenProject(type: Exec) {
    workingDir "vendor/other-proj/"
    commandLine "/usr/bin/mvn", "clean", "compile"
}
这样,Gradle将在编译之前执行Maven构建(
compileMavenProject
)。但请注意,它不是传统意义上的渐变“项目”,也不会出现,例如,如果运行
Gradle dependencies
。在Gradle项目中包含已编译的类文件只是一种攻击

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

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"
}

对于我来说,在本地回购上安装它不是一个选项,因为存在很多问题,主要是因为每次更改后都应该重新编译它,而不依赖于主项目。这显然是一种痛苦。当我尝试这一点时,我得到:无法解析POM,已经看到doctype。然而,通过这种方式,该库的依赖项没有加载,有什么方法可以修复它吗?令人震惊的是,没有插件,反之亦然?我的意思是,如果我想在maven项目中包含一个gradle项目,那么使用
文件
包含
libs
目录似乎是行不通的。对于作为Maven子项目依赖项的类,我不断得到
NoClassDefFoundError
s。