Intellij maven dependency prefer local code

2019-03-30 08:11发布

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!

4条回答
Juvenile、少年°
2楼-- · 2019-03-30 08:41

There is a checkbox "resolve Workspace artifacts" under Maven Run/Debug Configuration, select it then it'll work as expected.

查看更多
Explosion°爆炸
3楼-- · 2019-03-30 08:52

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.

查看更多
淡お忘
4楼-- · 2019-03-30 09:01

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.

查看更多
欢心
5楼-- · 2019-03-30 09:02

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.

查看更多
登录 后发表回答