是否可以在pom中使用条件.xml



我有一个maven web项目,我正在使用pom中的配置文件.xml为不同的环境创建.war文件。请参阅下面的示例 我的pom片段.xml

    ...
<profiles>
    <!-- DEVELOPMENT PROFILE -->
    <profile>
        <id>development</id>
        ...
        <build>
           ...
                <plugin> 
                    <groupId>com.google.code.echo-maven-plugin</groupId> 
                    <artifactId>echo-maven-plugin</artifactId> 
                    ...
                    <configuration>
                        <message>Message 1</message> 
                    </configuration> 
                    ...
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                    <configuration>
                        <webXml>src/main/webapp/WEB-INF/web-development.xml</webXml>
                    </configuration>
                </plugin>
                 ...
        </build>
    </profile>
    <!-- PRODUCTION PROFILE -->
    <profile>
        <id>production</id>
        ...
       <build>
           ...
                <plugin> 
                    <groupId>com.google.code.echo-maven-plugin</groupId> 
                    <artifactId>echo-maven-plugin</artifactId> 
                    ...
                    <configuration>
                        <message>Message 2</message> 
                    </configuration> 
                    ...
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-war-plugin</artifactId>
                    <version>3.2.2</version>
                    <configuration>
                        <webXml>src/main/webapp/WEB-INF/web-production.xml</webXml>
                    </configuration>
                </plugin>
        </build>
    </profile>
</profiles>

但是,这使我的pom.xml非常大-我有5种不同的配置文件。我想做的只是显示自定义消息并使用基于配置文件的自定义 web.xml 文件。有没有办法我可以在pom中添加条件.xml以便我可以简化它,如下所示:

...
    <profiles>
        <profile>
            <id>development</id>
            ...
        </profile>
        <profile>
            <id>production</id>
            ...
        </profile>
    <profiles>
    <build>
       ...
            <plugin> 
                <groupId>com.google.code.echo-maven-plugin</groupId> 
                <artifactId>echo-maven-plugin</artifactId> 
                <version>1.0.0</version> 
                <inherited>false</inherited> 
                <configuration>
                    <IF CONDITION TO CHECK IF development PROFILE>
                        <message>Message 1</message> 
                    </IF CONDITION>
                    <ELSE CASE>
                        <message>Message 2</message> 
                    <ELSE CASE>
                </configuration> 
                <executions> 
                    <execution> 
                        <goals> 
                            <goal>echo</goal> 
                        </goals> 
                    </execution> 
                </executions> 
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.2</version>
                <configuration>
                    <IF CONDITION TO CHECK IF development PROFILE>
                        <webXml>src/main/webapp/WEB-INF/web-development.xml</webXml>
                    </IF CONDITION>
                    <ELSE CASE>
                        <webXml>src/main/webapp/WEB-INF/web-production.xml</webXml>
                    <ELSE CASE>
                </configuration>
            </plugin>
                    ...
    </build>

No.

但是,您可以尝试在配置文件中定义属性,这可能会让您更简洁地编写内容。

最新更新