问题
i'm working on a project in which i have an android application project which has pom dependencies on other projects something like this:
<dependencies>
<dependency>
<groupId>some.project/groupId>
<artifactId>some.artifact<artifactId>
<version>1.0.0</version>
<type>apklib</type>
</dependency>
</dependencies>
while developing i always want Intellij to use the local source code from the some.project library i have in the project.
the problem is it will pull version 1.0.0 from the server and use that.
i tried using LATEST as version, this works fine as long as my some.project library version is updated to the latest version on the server.
since we have automated builds that will increment the version for some.project when changes are made i will have a scenario in which my source says 1.0.0 but the server has 1.0.1 and again intellij will pull the server apklib
Any suggestions how to achieve this? if i could use a dev profile to somehow define this for development only and a prod profile to use exact version numbers (which it should) that will be amazing.
Thanks!
回答1:
There is a checkbox "resolve Workspace artifacts" under Maven Run/Debug Configuration, select it then it'll work as expected.
回答2:
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.
回答3:
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.
回答4:
This works for Maven projects in the following way:
- Add the dependencies that you want to work with to the Maven Projects tab.
- Navigate to the implementation of the class for which you are looking.
- Once you are in the implementation, you can navigate back to the Super Method for the declaration.
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.
回答5:
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.
回答6:
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.
来源:https://stackoverflow.com/questions/23523573/intellij-maven-dependency-prefer-local-code