1

We have Project-Core that provides a base functionality. Project-X uses the Project-Core.

Project-Core is internally a multi-module project. To avoid deploying all the sub-modules, we create a fat-jar (uber-jar) using maven-shade-plugin. Project-Core also has external dependencies such as Spring. The result is a fat 45MB jar.

Now for Project-X to use Project-Core, it includes the dependency-reduced-pom of the fat-jar and it works fine.

However, this approach is a little inflexible: If Project-X wants to exclude or use newer versions of dependencies, it is not possible.

Alternatively, Project-Core deploys a slim-jar with only core implementation, but excluding all external dependencies - this is possible with shade-plugin configuration. However, Project-X needs to include all external dependencies explicitly. This is cumbersome as they need to know the dependencies and the right versions.

A better approach: The slim-jar is deployed with a custom POM that includes external dependencies. Project-X can then include this custom POM and still get all dependencies without including them explicitly. It also provides flexibility to exclude / upgrade dependencies.

Question: How to create slim-jar custom POM that retains only the external dependencies?

Tried playing around with createDependencyReducedPom and keepDependenciesWithProvidedScope options (https://maven.apache.org/plugins/maven-shade-plugin/shade-mojo.html), none of which meet the purpose.

gammay
  • 5,957
  • 7
  • 32
  • 51
  • Quick Answer: Afaik there is no easy solution to archive this with the shader plugin (e.g. you have to list all of your excludes specificially - using wildcards at a group-Id level as highest level accepted). As a side note: I realy dont think you should do what you are trying to do unless Project-X is a non-maven project - if it is a maven project i would realy think about why not deploying your core to a remote repository for reuse. Oftenly i see core-projects having a common parent for all of their modules and a "myGroup:ourPlattformCore:version".jar resulting as single-dependency artefact – JBA Apr 28 '15 at 12:26
  • Thanks for the response. The core project contains several sub-modules. We do not really want to deploy each sub-module individually as Project-X has to add all these as dependencies. So core project should deploy a single jar combining all sub-module jars. Assume core project was made up of a single module. We could deploy this module along with parent POMs as well. But how do we do this in case of sub-modules? On related note, I wonder how projects like Apache do this. (I will investigate) – gammay Apr 28 '15 at 12:45
  • Sorry for the late reply - the general setup hardly depends on how independant your core, its modules and other projects should be, not only considered Maven but also versionising software/ strategy in use - have a look at http://stackoverflow.com/questions/1992213/maven-parent-pom-vs-modules-pom for a general overview. In my current core-setup i have a parent project that is packed as `pom`, lists its `modules` and declares the modules as its own dependencies as well - that way my projects are able to only depend on my core's parent project. – JBA Apr 30 '15 at 11:31
  • Note that one of the most simple things to do is to just group multiple dependencies within a new maven project like described here: http://blog.sonatype.com/2009/10/maven-tips-and-tricks-grouping-dependencies/#.VUIS3YbelaQ (i basicially adopted that grouping to my parent and voila - a simple setup is born that fits my needs as i release everything together which might be not what a company with 200 developers and serval hundred modules/ projects would do, hence the above link) – JBA Apr 30 '15 at 11:34

0 Answers0