Use Gradle module as module dependency in another Gradle module

已回答

Is it possible with IDEA to use one Gradle module as a "module dependency" in another Gradle module within the same project? I have imported first, main project into IDEA and then added secondary library project. I expected that IDE would recognize one beeing dependency to another and link them correctly (add library project to main project module dependencies), similar to Maven projects.

I have correct versions specified between them. They are not part of one multi-module project. I have read about new support for composite-build, but due to some limitations I cannot use it in this case.

1

It's supported only via the Gradle multi-project.

1
Avatar
Permanently deleted user

I was hoping there is a way to do this transparently to linked projects. To use multi-projects you have to create one common root for included projects but also alter their dependencies to project(':library'). I was hoping there would be a better way.

I came from Eclipse + Maven background and its Maven integration would recognize POM dependencies as modules within workspace and install them into local repository to be picked up in another project. 

1

This is a blocker for us in our migration to gradle.

We have a large-ish multi-repository project with many maven modules.

When working with this as a maven-based project, IDEA correctly sets-up the maven module dependencies as "module" dependencies in its own projects settings (rather than a "library" dependency pointing to maven).

Now we have migrated on repository to gradle.

You just cannot work at all without major hassles in the multi-project: A dependency from a gradle module to a maven module always uses at least the local maven repository.

You even cannot refactor across repositories any more: If I refactor source code in a base module, any modules in other repositories are not changed, because IDEA believes they reference the code in the maven repository instead of the local source code.

Aaaaaarg!! Is there any hope to get this fixed? Shouldn't it be as easy as "when IDEA detects a dependency in a gradle file and the artifact is available in source code in the current project, then use the project's module dependency instead of the maven/gradle one"?

 

 

0

AFAICS I can't: How do you create a composite build were some module/repositories are build with maven and some with gradle?

We really need a migration path instead of a "big bang" where we convert everything in all modules/repositories and affect all teams simultaneously.

It must be possible to convert part of the overall/multi-repository project and still continue working.

If you cannot even do project-wide refactorings anymore (because IDEA misses the intra-project dependencies) then it is just not feasible.

0

Sigh. I had hoped that as a temporary workaround I could just add module dependencies manually and place them before the auto generated dependencies to maven.

At least at https://blog.jetbrains.com/idea/2013/04/gradle-improvements-at-121/ it says "when a user manually adds a library dependency to a module it’s not automatically removed during the auto-import."

However a gradle refresh (and save) will remove my manually added module dependencies :-(

Right now I am downloading the source code of the intellij community edition to see if I can understand what's going on there and either write a fix or a separate plugin that patches the behaviour.

0

请先登录再写评论。