IDEA integration: Resolve maven dependency to IDEA project?

We use IDEA’s built-in gradle integration - which again uses gradle’s built-in tooling api.

Our project is large(-ish) with a mix of maven and gradle modules.

Unfortunately gradle always resolves dependencies to maven modules to the maven repository, instead of checking if that module is also present in the overall IDEA project and creating a project-local module dependency instead. (And that causes lots of problems, for example you have to “mvn install” any change in a maven module to make that change visible in dependent gradle modules.)

There’s an issue in IDEA’s bug tracker ( ) but I think the root cause is gradle’s tooling api.

gradle’s internal classes IdeaDependenciesProvider and IdeDependenciesExtractor provide the actual dependencies to IDEA.

Is it possible to patch those classes from within buildSrc/build.gradle?

I can access methods, e.g. if I add this to build.gradke, it gets executed when I refresh the gradle project in IDEA:

def provideMethod = IdeaDependenciesProvider.metaClass.getMetaMethod("provide", [IdeaModule.class])

However when I try to replace the original method, it never gets called:

    IdeaDependenciesProvider.metaClass.provide = { ideaModule ->
        def result = provideMethod.invoke(ideaModule)

Can this patching of the tooling api from within a build.gradle work at all?

Any other approach to the problem?