簡體   English   中英

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

[英]How to extract common part in Maven profiles

在我的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>

您無法從其他配置文件激活配置文件。 您只能通過命令行,標記文件,操作系統等外部手段激活它們。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM