Maven ejb-client生成依赖性排除

t0m*_*ppa 6 java dependencies client ejb maven

我们有一个解决方案,我们的UI项目通过使用EJB客户端依赖项包含了大量业务服务.Maven上的问题在于,即使客户端.jar通常包含大约1-2个类,它们也会带来整个服务应用程序的完整依赖性堆栈.这可能会有点难看,当.ear文件开始增长到50-100Mb pop 并且由于不相关的依赖性偷偷进入UI应用程序时不时出现麻烦的错误.

当然,我们总是可以排除客户端上的依赖关系,但是我们必须使用这些服务为每个客户端项目编写相同的一行,这是很多不必要的重复.此外,人们提出了最奇怪的错误消息并使用大量时间跟踪它们,然后再记得提到它们包含一些客户端jar并且没有检查它带来了什么额外的依赖性.

例:

        <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>
Run Code Online (Sandbox Code Playgroud)

这只是一个服务客户端被包含在内,想象在几个不同的应用程序中有几个并且你得到了图片,每次写入所有排除非常烦人并且项目POM开始变得相当漫长.

我会将依赖项标记为已提供,但是如果它们不存在,则会有一些依赖项在运行时崩溃.比如那些包含另一个带有外部Exception类的应用程序的服务调用,这不是出于某种原因而包含在服务项目中,并且如果不存在则会在运行时导致ClassNotFoundException.

因此,我知道通过在maven-ejb-plugin上使用pom.xml规范,可以在ejb客户端生成期间排除/包含类,但是有没有办法排除依赖项?

t0m*_*ppa 1

似乎 Maven 不太支持从一个模块构建多个 jar。

因此,我们发现解决这个问题的唯一合理方法是创建另一个模块(将 xxx-service 分解为 xxx-service 和 xxx-service-client)并将 xxx-service-client 模块配置为仅具有 EJB 客户端/委托类和最小依赖关系。这样,可以通过单次执行来构建项目。