[英]IntelliJ: activate Maven profile when running Junit tests
I have declared some properties that are specific to Maven profiles.我已经声明了一些特定于 Maven 配置文件的属性。 A part of my pom.xml:
我的 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>
I encounter some problem to use the "ci" Maven profile when I start Junit tests via IntelliJ IDEA 2016.当我通过 IntelliJ IDEA 2016 启动 Junit 测试时,我在使用“ci”Maven 配置文件时遇到了一些问题。
I activate my profile via the "Maven Projects" panel, then I start tests.我通过“Maven 项目”面板激活我的配置文件,然后开始测试。 The problem is the "my.properties.file" property value is equal to "foo.xml", not "bar.xml".
问题是“my.properties.file”属性值等于“foo.xml”,而不是“bar.xml”。
I have no problem with command-line (I can use the "-Pci" flag).我对命令行没问题(我可以使用“-Pci”标志)。 How can I tell IntelliJ to use the "ci" profile?
我如何告诉 IntelliJ 使用“ci”配置文件? Thx.
谢谢。
You should add the profiles to the Maven setting.xml file (you should find it in the path ${YOUR_MAVEN_HOME}\\apache-maven-3.1.1\\conf\\setting.xml). 您应该将配置文件添加到Maven setting.xml文件中(您应该在路径$ {YOUR_MAVEN_HOME} \\ apache-maven-3.1.1 \\ conf \\ setting.xml中找到它)。 Then, you have to open intellij, click on View > Tool Windows > Maven Projects.
然后,您必须打开intellij,单击视图>工具窗口> Maven项目。 There, you should see your profiles (ci and release) and select the correct one.
在那里,您应该看到您的个人资料(ci和发布)并选择正确的个人资料。
Hope this can help you. 希望这可以帮到你。
Just finally solved it.终于解决了。
<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>
Goto JUnit default profile (aka configuration template).转到 JUnit 默认配置文件(又名配置模板)。 Add into JVM args:
添加到 JVM 参数中:
-Dmvn-profile-env-var-trigger
You may need to manually reload maven profiles in IDE.您可能需要在 IDE 中手动重新加载 maven 配置文件。
Also make sure on [Settings > Build Tools > Maven > Running tests] envVars is checked (or better everything).还要确保 [Settings > Build Tools > Maven > Running tests] envVars 被选中(或更好的一切)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.