簡體   English   中英

maven 配置文件應該被激活但不是

[英]maven profile should be activated but is not

我多年來一直在使用 maven,但遇到了一個問題。 與往常一樣,我創建了一個存儲庫來說明我的問題: git clone https://github.com/clembo590/issues.git --branch mavenProfiles

我剛剛創建了一個多模塊 maven ,我希望 QA 配置文件處於活動狀態,但事實並非如此。

這是父 pom 的樣子:

  <profiles>
    <!-- build mdr-commons ONLY IF PRESENT -->
    <profile>
      <id>mdr-commons</id>
      <activation>
        <file>
          <exists>mdr-commons/pom.xml</exists>
        </file>
      </activation>
      <modules>
        <module>mdr-commons</module>
      </modules>
    </profile>

    <profile>
      <id>QA</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <build>
        <plugins>

          <!-- this is to check that the coded is formatted : you can use 'apply' instead of 'check' to actually format the code -->
          <plugin>
            <groupId>com.diffplug.spotless</groupId>
            <artifactId>spotless-maven-plugin</artifactId>

如果你運行mvn clean install你會得到這些日志:

[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO] 
[INFO] mdr-parent                                                         [pom]
[INFO] mdr-commons                                                        [pom]
[INFO] 
[INFO] -----------------------< com.example:mdr-parent >-----------------------
[INFO] Building mdr-parent 1.0.0                                          [1/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mdr-parent ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mdr-parent ---
[INFO] Installing ...
[INFO] 
[INFO] ----------------------< com.example:mdr-commons >-----------------------
[INFO] Building mdr-commons 1.0.0                                         [2/2]
[INFO] --------------------------------[ pom ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ mdr-commons ---
[INFO] 
[INFO] --- spotless-maven-plugin:2.11.1:check (default) @ mdr-commons ---
[INFO] 
[INFO] --- maven-install-plugin:2.4:install (default-install) @ mdr-commons ---
[INFO] Installing ...
[INFO] ------------------------------------------------------------------------

構建 mdr-parent 時不執行 spotless-maven-plugin,這意味着構建 mdr-parent 時 QA 配置文件不活動。 (它在構建 mdr-commons 時處於活動狀態)

問題1:為什么構建mdr-parent時QA profile沒有激活?

問題 2:只需完全刪除名為 mdr-commons 的文件夾並重新運行mvn clean install --> 為什么這次 QA 配置文件處於活動狀態? (您將在日志中看到一塵不染的 maven-plugin 已執行)

在此先感謝maven experts

這在文檔中有所描述:

除非使用上述方法之一激活同一 POM 中的另一個配置文件,否則此配置文件將自動對所有構建處於活動狀態。 當在命令行或通過其激活配置激活 POM 中的配置文件時,默認情況下處於活動狀態的所有配置文件都會自動停用。

答案可以在 Maven 指南的配置文件激活詳細信息中找到。

TLDR; 每當另一個配置文件通過任何其他方法激活時,默認激活的配置文件就會被停用。

如果文件mdr-commons/pom.xml存在,則會激活 mdr-commons 配置文件。 在這種情況下,QA 配置文件將被停用。 如果此文件不存在,則 QA 配置文件為“默認活動”。

暫無
暫無

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

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