2

I am working on a big set of projects strongly related to each other and looking for a way to reduce to minimimun the maintenance overhead using a good maven configuration.

One of the scenarios which I am currently working on is a set of several small projects inside the same "company project", most of them depending on the others, with a big list of external dependencies in each one.

In order to make it cleaner I created a parent pom, set all of them as modules and created a big list of dependencies inside the parent's dependencyManagement section allowing me to remove most of the version tags inside the project poms.

The next stage for me is to reduce the amount of resulting jars by making use of some plugin, such as one-jar or assembly, in oder to get a signle jar from one of those projects containing all the others inside. However, this led me to having an enourmous jar with tons of external libraries inside, most of them already provided by the running environment. I know that adding the <scope>provided</scope> tag to the declaration of external dependencies would do the job, but I would like to avoid having dozens of these tags in my poms.

So the questions are:

  • Is there any way to define a default scope, so I can use compile scope only in the libs which I want included?

Then, instead of having this:

<dependencyManagement>
    <dependency>
        <groupId>any.external</groupId>
        <artifactId>lib</artifactId>
        <version>1.0</version>
        <scope>provided</scope> <!--Skip Inclusion-->
    </dependency>
    <dependency>
        <groupId>any.external</groupId>
        <artifactId>cool-lib</artifactId>
        <version>1.0</version>
        <scope>provided</scope> <!--Skip Inclusion-->
    </dependency>
    <dependency>
        <groupId>another.external</groupId>
        <artifactId>lib</artifactId>
        <version>1.0</version>
        <scope>provided</scope> <!--Skip Inclusion-->
    </dependency>
    <dependency>
        <groupId>my.company</groupId>
        <artifactId>some-dependency</artifactId>
        <version>1.0</version>
    </dependency>
</dependencyManagement>

I could have this (note that the difference will come when we have only 10 internal projects to include, but more than 100 external libs):

<dependencyManagement>
    <dependency>
        <groupId>any.external</groupId>
        <artifactId>lib</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>any.external</groupId>
        <artifactId>cool-lib</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>another.external</groupId>
        <artifactId>lib</artifactId>
        <version>1.0</version>
    </dependency>
    <dependency>
        <groupId>my.company</groupId>
        <artifactId>some-dependency</artifactId>
        <version>1.0</version>
        <scope>compile</scope><!-- Include It! -->
    </dependency>
</dependencyManagement>
  • Or better: Maybe I'm skipping something and there is already a way to tell maven: "Include only the jars generated within the current project"? Remember that all modules are "brothers", included as modules of the same parent, and compiled at the same time.

Many thanks in advance! Carles

Carles Sala
  • 1,989
  • 1
  • 16
  • 34
  • This sounds more like a job for a maven multi-module build. – khmarbaise Dec 20 '12 at 16:23
  • What do you mean? As far as I understand it, it already is a multi-module build. The only thing is that I want all the modules packaged inside a signle jar instead of producing several of them – Carles Sala Dec 20 '12 at 16:25
  • If you like to package all modules into a single zip/tar.gz whatever archive you should create a separate module mod-piling and define the dependencies to the other modules there and use the maven-assembly-plugin to create the archive (see [here](https://github.com/khmarbaise/maven-packaging-test/tree/master/package)). – khmarbaise Dec 20 '12 at 17:28
  • Well, the idea is to have a single executable jar, so this solution does not exactly fit my requirement. At the moment I managed to get a single executable jar with my modules inside using "one-jar" plugin, so my current problem is having to fill all my pom files with those "provided" scope tags. – Carles Sala Dec 22 '12 at 21:21
  • The assembly plugin provides a defined descriptor which is called **jar-with-dependencies** furthermore for your requirement a better approach is to use the maven-shade-plugin for such purposes. – khmarbaise Dec 23 '12 at 13:23

0 Answers0