i\'m working on a project in which i have an android application project which has pom dependencies on other projects something like this:
Just a small hint how to do the same with Gradle. Supposing you have two workspaces with lib and app. The lib is deployed to some maven repo and needs to be described in the following way:
// build.gradle
group 'lib.group'
version 'lib.version'
// settings.gradle
rootProject.name = 'lib.name'
While app dependencies are the following:
// build.gradle
compile "lib.group:lib.name:lib.version"
So, the app module uses lib as a maven dependency. Now, you can import lib sources into app workspace using File | New | Module from existing sources. After refreshing the project from Gradle tool window, you will get two modules lib and app in the app workspace. However, even after reimporting Gradle the lib dependency will still point to the maven repository, what you can check in File | Project Structure.
The trick to be done here is to click with the right mouse button on app module in the Gradle tool window, and select Composite Build Configuration option. Then, on the popup window just select the local lib module to include it in the app module build. Now, after reimporting Gradle deps again for the whole workspace you will get the maven dependencies for lib replaced with the local dependency.
Assuming that you have the project organised as a multi-module project, and that you're talking about a dependency on a library that's one of the project's modules, then you need to use a snapshot dependency, and you need to use the full maven release process. As it is, you're depending on a pre-built, static version of the given library, but you need IntelliJ to look at the source and class you compile instead, and snapshot dependencies are used exactly for this purpose.
You can add a module dependency in IntelliJ: File->Project Settings->Modules click on the module -> click Dependencies tab and then click the green '+' sign and choose '3. Module dependency'.. add the module on which you want to depend locally and click the blue arrows to bring the module above the Maven dependencies.
This works for Maven projects in the following way:
That's either Navigate -> Implementation(s)
or ALT+COMMAND+B (on the Mac map). Intellij will then present you with the option of decompiling the class from the JAR in the dependency list or the source code in the attached Maven project.
For example, I am in project bank
of the Rooskie Bank, and I want to view the code for the Account
class in bank-domain
. I click on an Account object declaration and press ALT+COMMAND+B. From the popup menu, I choose the definition from the list of sources that does not have "(Maven: com.rooskiebank.bank-domain.jar)" in the choice.
IMO this is an awkward way of doing things. As much as I like it, I find Intellij is difficult to use in enterprise-sized systems with multiple in-house libraries, and I still use Eclipse a lot for them. Intellij works better with Git and is great for stand-alone microservices.
I imagine Gradle works in a similar way.
There is a checkbox "resolve Workspace artifacts" under Maven Run/Debug Configuration, select it then it'll work as expected.
We are dealing with the same problem...
"IDEA should resolve dependencies as a module dependency type (rather than a local jar Maven library) if this Maven project is opened in IDE and it's version matches the version, installed in a local Maven repository."
https://intellij-support.jetbrains.com/hc/en-us/community/posts/206836605-Always-prefer-local-module-source-over-Maven-dependencies
Our solution was to add local Maven profile in pom.xml and specify local dependency version. To make it work, you have to turn on local profile.
<profiles>
<profile>
<id>local</id>
<properties>
<dependency.version>x.x.x</dependency.version>
</properties>
</profile>
</profiles>
When local dependency is updated, you have to take care to update this version too, but currently this is the best solution we found and it's working for us.