Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven ejb-client generation dependency exclusion

We have a solution where our UI projects are including quite a bunch of business services by using the EJB client dependencies. The problem with this on Maven is that even though the client .jar usually contains about 1-2 classes, they bring with them the full dependency stack of the entire service application. This can get a bit ugly, when the .ear files start growing up to 50-100Mb a pop and there are from time to time pesky errors thanks to irrelevant dependencies sneaking their way into the UI application.

Of course, we can always exclude the dependencies on the client end, but then we have to write the same bunch of lines to each client project using those services and that's a lot of needless repetition. Plus, people come up with the weirdest error messages and use a lot of time tracking them down before remembering to mention that they included some client jar and didn't check what additional dependencies it brought into the equation.

Example:

        <dependency>
            <groupId>fi.path.to.service</groupId>
            <artifactId>customermanagement-common</artifactId>
            <version>2.6</version>
        </dependency>
        <dependency>
            <groupId>fi.path.to.service</groupId>
            <artifactId>customermanagement-service</artifactId>
            <classifier>client</classifier>
            <exclusions>
                <exclusion>
                    <groupId>fi.path.to.dependency</groupId>
                    <artifactId>internal-dependency-#1</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>org.codehaus.castor</groupId>
                    <artifactId>castor</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>fi.path.to.dependency</groupId>
                    <artifactId>internal-dependency-#2</artifactId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#3</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#4</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#5</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>castor-xml</artifactId>
                    <groupId>org.codehaus.castor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>castor-codegen</artifactId>
                    <groupId>org.codehaus.castor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>castor-xml-schema</artifactId>
                    <groupId>org.codehaus.castor</groupId>
                </exclusion>
                <exclusion>
                    <artifactId>internal-dependency-#6</artifactId>
                    <groupId>fi.path.to.dependency</groupId>
                </exclusion>
            </exclusions>
            <version>2.6</version>
        </dependency>

That is just one service client being included, imagine having several of these in several different applications and you get the picture, writing up all the excludes each time is quite annoying and the project POMs start getting fairly longwinded.

I would mark the dependency as provided, but there are a couple dependencies that do crash on runtime, if they don't exist. Say ones that include another service call to yet another app with an external Exception class, which isn't for one reason or another wrapped inside the service project and will cause a ClassNotFoundException on runtime, if not present.

Therefore, I know it's possible to exclude/include classes from an ejb client during its generation through the usage of pom.xml specs on the maven-ejb-plugin, but is there any way to exclude dependencies as well?

like image 812
t0mppa Avatar asked Jul 10 '12 06:07

t0mppa


1 Answers

Seems that Maven just doesn't support building multiple jars out of one module very well.

Thus the only reasonable way around this that we've found is to create another module (break xxx-service into xxx-service and xxx-service-client) and configure the xxx-service-client module to have only the EJB client/delegate class & minimal dependencies. That way the project can be built with a single execution.

like image 125
t0mppa Avatar answered Nov 02 '22 13:11

t0mppa