maven project as dependency in gradle project

You cannot "include" a maven project in gradle settings.gradle. The simplest way would be to build the maven project and install it to your local repo using mvn install(can be default .m2, or any other custom location) and then consume it from your gradle project using groupname:modulename:version

repositories{
    mavenLocal()
}

dependencies{
    compile 'vendor:otherproj:version'
}

It is possible to depend directly on the jar of the maven project using compile files but this isn't ideal because it wont fetch transitive dependencies and you'll have to add those manually yourself.


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

Tags:

Maven

Gradle