如何在Maven配置文件中提取公共部分

问题描述 投票:3回答:2

在我的pom.xml中,我定义了几个配置文件来运行Oracle WebLogic下的Spring Boot应用程序:

    <profile>
        <id>wls-1</id>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
        </dependencies>
        <properties>

        </properties>
    </profile>
    <profile>
        <id>wls-2</id>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
        </dependencies>
        <properties>

        </properties>
    </profile>
    <profile>
        <id>wls-3</id>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
        </dependencies>
        <properties>

        </properties>
    </profile>
    <profile>
        <id>tomcat1</id>
        <properties>

        </properties>
    </profile>

正如您在每个新的wls配置文件中看到的那样,我需要定义依赖关系以使用提供范围(否则部署将因某些tomcat资源而失败)。但我仍然有一些其他配置文件,不会使用这个wls-common部分

有没有办法如何定义一些wls-common配置文件,将自动使用该配置文件而不更改我的mvn命令?我知道我可以在mvn -P p1,p2或属性-Dp1=wls链接配置文件,但这不是我想要的。

java maven spring-boot
2个回答
0
投票

在所有配置文件中,定义将激活特定配置文件的属性,并将所有配置文件放在通用配置文件中。

但是,这需要您将命令从mvn -Pwls-1更改为mvn -Dwls-1

<profile>
 <id>wls-1</id>
 <activation>
   <property>
     <name>wls-1</name>
   </property>
 </activation>
 ...
</profile> 
<profile>
    <id>common</id>
    <activation>
      <property>
        <name>wls-1</name>
        <name>wls-2</name>
        <name>wls-3</name>
      </property>
    </activation>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-tomcat</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <properties>
    </properties>
</profile>

0
投票

您无法从其他配置文件激活配置文件。您只能通过命令行,标记文件,操作系统等外部手段激活它们。

© www.soinside.com 2019 - 2024. All rights reserved.