【问题标题】:Multi module project to deliver two different wars多模块项目交付两种不同的战争
【发布时间】:2019-12-11 12:26:23
【问题描述】:

我正在开发一个多模块 Spring MVC 项目,其中一个模块必须交付一个包含所有依赖项的战争,而另一个模块必须交付一个排除少数依赖项的战争。这可能吗?如果是的话,我怎么能做到这一点?项目详情如下:

结构是:

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

在 Websphere 中创建了一个共享库,并在其中添加了所有依赖项。因此, 将被部署在那里。 将用于构建 docker tomcat 映像并托管在 diff 环境中。 我的项目必须支持这两种环境。因此出现了奇怪的要求。

【问题讨论】:

  • 我相信你不能这样做,除非每个模块都有不同的 pom 文件。
  • 首先你为什么喜欢这样做?
  • 实际上可以根据当前活动的 Maven 配置文件构建选定的模块:stackoverflow.com/questions/13381179/…

标签: java spring maven


【解决方案1】:

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

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 fake-testcontainer 库中

【讨论】:

    猜你喜欢
    • 2018-10-06
    • 1970-01-01
    • 2014-01-12
    • 1970-01-01
    • 1970-01-01
    • 2015-04-24
    • 2013-06-02
    • 2011-05-12
    • 2012-03-01
    相关资源
    最近更新 更多