2

I am using IDEA to build a big maven project which contains a lot of submodules. And i could not find a similar feature which provided in eclipse. This feature has block me for years which avoid me to switch to IDEA.

In eclipse, there has a feature named "Enable Workspace Resolution". With this feature, all projects in eclipse workspace will be auto resolved by other project in same workspace (Eclipse will auto update build classpath, and replace dependencies jar path to other project's output folder like target/classes). Then the dependencies will always point to the latest compiled class file, even you can update the class file in runtime (when debug, it will effect immediately if u did not update method signature but just method content).

For example, for a maven project like:

Project
  |- module1
  |- module2
  |- pom.xml 

module1 depends on module2, In eclipse, module1 will not find module2.jar from maven repo but directly from module2/target/classes(compile output folder). But IDEA will always try to find module2.jar from maven repo.

Any ideas?

NewBee
  • 1,331
  • 12
  • 13
  • Is this a submodule a child of Project which means is this a multi module build? Meaning module1 is an entry in project pom.xml `module1`? – khmarbaise Mar 04 '20 at 09:05
  • @khmarbaise yes. (i have restrict the scope to same project submodule in IDEA, in eclipse, the scope is same workspace) – NewBee Mar 04 '20 at 09:33
  • 1
    Than there is no need to have "Workspace resolution" cause IDEA already does that correctly (even better than Eclipse does) ...workspace resolution is only used if you have a dependency which is not part of the reactor (multi module build) to solve that inside Eclipse...if you really need that... – khmarbaise Mar 04 '20 at 18:11
  • @khmarbaise In this "workspace resolution" part, IDEA is far away from eclipse. there are no limit in eclipse, it will always find the latest compiled .class file no matter whether the class belongs to same submodule of a project. And the class file effect immediately, you can hot reload your running application(I am trying to find same feature of IDEA in this part too). – NewBee Mar 17 '20 at 10:40

2 Answers2

1

At our project we use multiple maven modules with dependencies to other our modules and I don't have any problems with IDEA similar to the ones you've described.

In my opinion there are 2 important moments to consider:

  1. Always import module to IDEA as maven module. In other words click File -> New -> Module from Existing Sources... -> select pom.xml of your module. Otherwise IDEA will not download changed dependencies when pom.xml has changed.

  2. Use DEVELOPMENT-SNAPSHOT (or exactly the same) version of your dependencies which are present at workspace. If you specify some other released version then (IDEA via) maven will download it from maven repo.

Rara
  • 639
  • 9
  • 22
  • I am exactly using SNAPSHOT now (btw, eclipse does not care about the version). Let me confirm, if you delete the depend jar(module2) file in local maven repo, can the module1 still run? – NewBee Mar 04 '20 at 09:31
  • @NewBee I never tried deleting modules in local maven repo for such purpose but when I change something in module2 it immediately affects module1. I suppose it is enough to prove that this schema works. – Rara Mar 05 '20 at 14:14
  • It seems you are right. I see your answer in idea document somewhere before, but it does not work (maybe i test it in wrong way). I re-test it, it seems work good. – NewBee Mar 09 '20 at 07:44
  • I got a new question, may IDEA use newest .class when application is running? In eclipse, if i edit code logic of a method(not method signture), it effects immediately. – NewBee Mar 17 '20 at 10:37
  • In general it is possible. You should recompile(rebuild) and reload your classes. After the rebuild IDEA usually shows dialog which asks if you want to reload your classes. It can succeed of fail depending on what changes were done and what are supported to hot swap by your JVM. For advanced capabilities you can have a look at DCEVM(free) or JRebel(paid). – Rara Mar 17 '20 at 13:07
  • thanks, i have try recompile operation, it do works. but still waste a lot of time. May it like eclipse auto replace class file. – NewBee Mar 17 '20 at 13:15
  • You can recompile just the current file (Ctrl-Shift-F9 in Linux/Windows). Should be pretty fast. – Rara Mar 17 '20 at 13:38
  • aha, i really do not like Ctrl-Shift-F9 everytime and wait seconds. DCEVM seems a good option, i will have a try. – NewBee Mar 17 '20 at 13:40
  • See also https://stackoverflow.com/questions/12744303/intellij-idea-java-classes-not-auto-compiling-on-save – Rara Mar 17 '20 at 13:41
  • i try the solution in that question. but no lucky. Still need Ctrl-Shift-F9, or else it won't effect. – NewBee Mar 17 '20 at 13:44
0

In a multi-module Maven project IDE will resolve dependency to a module sources, rather than to a local maven jar library, if maven coordinates (groupId, artifactId, versionId) are the same.

Also for the 'SNAPSHOT' version, dependency of the 'LATEST' version will be resolved.

For versions without 'SNAPSHOT' dependencies with versions declared as 'LATEST' and 'RELEASE' will be resolved.

Of course these modules should be present in current IDE project and added as a Maven modules.

Andrey
  • 15,144
  • 25
  • 91
  • 187