簡體   English   中英

IntelliJ:運行 Junit 測試時激活 Maven 配置文件

[英]IntelliJ: activate Maven profile when running Junit tests

我已經聲明了一些特定於 Maven 配置文件的屬性。 我的 pom.xml 的一部分:

<profiles>
            <profile>
                <id>release</id>
                <activation>
                    <activeByDefault>true</activeByDefault>
                </activation>
                <properties>
                    <my.properties.file>foo.xml</my.properties.file>
                </properties>
            </profile>
            <profile>
              <id>ci</id>
              <properties>
                <my.properties.file>bar.xml</my.properties.file>
              </properties>
        </profile>
</profiles>

當我通過 IntelliJ IDEA 2016 啟動 Junit 測試時,我在使用“ci”Maven 配置文件時遇到了一些問題。
我通過“Maven 項目”面板激活我的配置文件,然后開始測試。 問題是“my.properties.file”屬性值等於“foo.xml”,而不是“bar.xml”。

我對命令行沒問題(我可以使用“-Pci”標志)。 我如何告訴 IntelliJ 使用“ci”配置文件? 謝謝。

您應該將配置文件添加到Maven setting.xml文件中(您應該在路徑$ {YOUR_MAVEN_HOME} \\ apache-maven-3.1.1 \\ conf \\ setting.xml中找到它)。 然后,您必須打開intellij,單擊視圖>工具窗口> Maven項目。 在那里,您應該看到您的個人資料(ci和發布)並選擇正確的個人資料。

希望這可以幫到你。

終於解決了。

    <profile>
        <id>profile-to-be-activated-on-build</id>
        <activation>
            <activeByDefault>false</activeByDefault><!-- on your flavor -->
            <property>
                <name>mvn-profile-env-var-trigger</name>
            </property>
        </activation>
    </profile>

轉到 JUnit 默認配置文件(又名配置模板)。 添加到 JVM 參數中:

-Dmvn-profile-env-var-trigger

您可能需要在 IDE 中手動重新加載 maven 配置文件。

還要確保 [Settings > Build Tools > Maven > Running tests] envVars 被選中(或更好的一切)。

暫無
暫無

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

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