0

I have hierarchy of 15 projects (-ear, -web, javaFX applications, common libraries), so it is like an ordinary maven tree:

PROJECT-ROOT
- PROJECT1
-- PROJECT1-EAR
-- PROJECT1-WEB
- PROJECT2
-- PROJECT2-EAR
-- PROJECT2-WEB
- PROJECT3-COMMON-LIB
- PROJECT4-JAVAFX

Every project has its own parent except for PROJECT-ROOT of course. Thing is, for compiling just PROJECT4-JAVAFX I need to run compilation on the root project, which takes some extra time and gets already annoying. If I run compilation (or packaging whatever) in the sub-project PROJECT4-JAVAFX it cannot just find the PROJECT3-COMMON-LIB as it is in dependencies list and fails with ERROR.

How I can solve this? I need during the development to be able compile just part of the maven project tree. My IDE is IntelliJ but obviously is not important, but hot-swap should also work.

There is possibility maybe to mvn install it, but come on, I am developing still, I do not want to touch my local repository yet.

UPDATE: So once more to clarify. What I am trying to achieve:

To be able to compile just dependent and changed modules for one particular module. I do not want to track these changes, I want to leave it for build tool. The last thing is to clean/compile the whole project.

However I found in IntelliJ - Resolve workspace conflicts. It just compiles the dependent modules (it's Maven configuration).

Mejmo
  • 2,363
  • 9
  • 35
  • 54
  • `mvn install`s purpose is to make artifacts available for other projects. It's common use to "publish" unfinished moduls (snapshot versions) in the local repository multiple times a day. – JimHawkins Jan 23 '18 at 13:29

2 Answers2

1

Why not just use mvn install? It will compile, package and publish the artifacts to your local repository. Until you do that, the particular module will not be available to other maven projects as dependency.

Moreover, you need to build your root only once. This will build and publish all sub modules as well. You don't need to build any of them again unless you change something there. After that, you should only be compiling/packaging the required sub module(in your case, PROJECT4-JAVAFX).

Also, I think you don't need to explicitly use mvn install after first time. If you have selected Build Automatically in Eclipse(not sure about IntelliJ), it should invoke maven builder to build your project and any dependent projects automatically.

Rahul
  • 637
  • 5
  • 16
  • Yes `unless you change something there`. This should be detected by build tool, not me. In case of bigger projects, just to build each time the tree could be not so efficient. – Mejmo Jan 23 '18 at 14:20
  • @Mejmo - As I mentioned in the answer, eclipse does what you are asking for, you just need to enable **Build Automatically**. For IntelliJ, refer to following: https://stackoverflow.com/questions/12744303/intellij-idea-java-classes-not-auto-compiling-on-save – Rahul Jan 23 '18 at 14:59
0

If you don't want to install the module you could call maven from the root project folder like this:

mvn --projects subtwo,subone package

Where subtwo depends on subone.

You can read up on the commands here and here.

However I wouldn't mind adding my projects which are still in development in my local repository, the way I see it, that's exactly what it is for.

Daniel Figueroa
  • 10,348
  • 5
  • 44
  • 66
  • The problem with local repository is, that it can be in not equal state as in your IDE. Imagine you have changed something in `common`, but you have forgot about that... I just want to compile the projects which are dependent on `JAVAFX` which were changed, the way how `make` is doing it. It detects changes and compile just the affected modules. Imagine you have much more complex tree... you have to `mvn install` the root project each time you change something in dependent library. So to compile not 5% of the workspace but 100%. This is just so wrong. – Mejmo Jan 23 '18 at 14:18
  • I'm not sure I follow you completely, but for sure, my suggestion is very manual, and thus does not seem to be what you want. I think your problem is that maven is a very opinionated tool, maybe you should try something else, like gradle? – Daniel Figueroa Jan 23 '18 at 15:12