多模块项目交付两场不同的战争



我正在研究一个多模块Spring MVC项目,其中一个模块必须与所有依赖项进行战争,而另一个模块必须提供一场排除很少依赖项的战争。这可能吗?如果是,我该如何实现?项目详情如下:

结构为:

Parent pom:
<modules>
<web-war-with-all-dependencies>
<web-ear-without-dependencies>  --> Only to pack the war into an ear.
</modules>

在 Websphere 中创建一个共享库,并将所有依赖项添加到其中。因此,<没有依赖关系的 web-ear-now=">将部署在那里。将用于构建 docker tomcat 映像并托管在差异环境中。 我的项目必须支持这两种环境。因此提出了奇怪的要求。

使用 Maven 配置文件并仅在某些配置文件中添加一些依赖项或使用 scope 设置它们: 前提是:

https://www.baeldung.com/maven-profiles

例:

<profiles>
<profile>
<id>dev</id>
<dependencies>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>${testcontainers.version}</version>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<version>${testcontainers.version}</version>
</dependency>
</dependencies>
</profile>
<profile>
<id>prod</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<!-- my own library in my private repository which acts like a mock of testcontainers project. Don't ask :-) -->
<dependency>
<groupId>cz.jiripinkas</groupId>
<artifactId>fake-testcontainers</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
</dependencies>
</profile>
</profiles>

然后使用以下方法构建项目:

mvn clean install -P dev

这将放入 WAR 测试容器库中

或:

mvn clean install -P prod

这将放入 WAR 假测试容器库