0

There is a common maven module with dependencies. There are also two other maven modules which depend on the common module but use its different functionality and as result don't require all jars of the common module to be included in their artifacts.

I want to pack optimal artifacts for each module which would contain just really used libs which the common module depends on.

I'm working with Intellij IDEA 14, Linux.

Software Engineer
  • 15,457
  • 7
  • 74
  • 102
humkins
  • 9,635
  • 11
  • 57
  • 75

1 Answers1

1

The ideal answer is to split your common module into sub-modules, each tightly focussed on one area, and import just the sub-modules you need.

If this is not possible, then Nitin's linked question has an answer that uses exclusions to remove the unwanted jars. Working out which dependencies that can be safely excluded can be a challenge, especially if you are running on an application server that may provide the wrong versions of the dependencies at runtime.

kiwiron
  • 1,677
  • 11
  • 17
  • It's not just the ideal answer, it's the only correct answer. Regardless of build system or deployment (Java JAR, RPM, etc), an artifact is the minimum deployable package of code. If it needs to be smaller, don't make a single module. The dependency contract created by the POM embedded in the artifact is not conditional on entry point. Adding those semantics "because you can" doesn't mean people aren't going to curse your name after you're gone. Not worth it!! – Brian Topping May 13 '15 at 15:47
  • Yeah, maven exclusions should be a last resort. Primarily (IMHO) used for excluding libraries dragged in by third party dependencies. – Carlos Bribiescas May 13 '15 at 16:08