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



在我的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中链接配置文件,但这不是我想要的。

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

但是,这将需要表单将命令从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>

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

最新更新