java - 为什么执行 mvn test -P{profile Id} 时没有运行测试
问题描述
我在 pom.xml 中定义了我的配置文件,如下所示:
<profiles>
<profile>
<id>Test123</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</profile>
</profiles>
我们我运行了一个命令mvn test -PTest123,没有运行测试,如下所示: cmd 输出
但是,我们使用命令mvn test运行,它已经运行了如下所示的测试: cmd 输出
解决方案
查看输出文件后,我注意到每个配置文件都在运行不同版本的 maven-compiler-plugin 和 maven-surefire-plugin。这个项目是否依赖于父 pom.xml?否则将插件上的版本更改为:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<!-- put your configurations here -->
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src/target/testdemo.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
如果版本控制不重要,应该解决问题。
推荐阅读
- sql - 通过 querybuilder 在学说列别名中添加一个空格
- swift - 如何使用保存在其他视图控制器的结构模型中的数据连接到新视图控制器
- vb.net - PictureBox2.Image = PictureBox1.Image 似乎是链接框而不是复制图像?
- java - 使用两个实体验证 DTO
- android - 自定义日历 // android-times-square // 如何在 decorate 方法中从 CalendarCellDecorator 中获取 mont 和 year
- java - DynamoDB 慢扫描查询
- php - 我的 php 邮件联系表有什么问题?
- php - 如何列出赞助商用户左侧或右侧记录的所有用户
- dagger-2 - 如何处理应用程序后台以恢复使用 Dagger2 注入的 Exoplayer?
- vb.net - 如何拆分字符串和浮点数 vb.net