Gradle 和 Maven 在将 null 作为 varargs 参数发送时表现不同
Gradle and Maven act differently when send null as varargs parameter
我正在对接收字符串可变参数的函数进行单元测试。
在函数中我正在检查发送的参数是否为空:
public static String generate(String... input) {
if (input == null) {
LOGGER.warn("Input is null for CheckSumGenerator");
return null;
}
// Other not relevant code here
}
单元测试:
String checkSum2 = CheckSumGenerator.generate(null);
Assert.assertEquals(checkSum2, null);
使用 Maven 作为构建工具时 - 测试 运行 正常。通过。
当使用 gradle 将项目更改为 运行 时,构建打印警告为红色:
warning: non-varargs call of varargs method with inexact argument type
for last parameter
问题是为什么 gradle 打印它而 Maven 不打印?
maven 编译器插件默认配置为忽略警告
https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#showWarnings
<showWarnings>
Set to true to show compilation warnings.
Type: boolean
Since: 2.0
Required: No
User Property: maven.compiler.showWarnings
**Default: false**
另一方面,Gradle 默认显示它们。 You can turn them off.
我正在对接收字符串可变参数的函数进行单元测试。
在函数中我正在检查发送的参数是否为空:
public static String generate(String... input) {
if (input == null) {
LOGGER.warn("Input is null for CheckSumGenerator");
return null;
}
// Other not relevant code here
}
单元测试:
String checkSum2 = CheckSumGenerator.generate(null);
Assert.assertEquals(checkSum2, null);
使用 Maven 作为构建工具时 - 测试 运行 正常。通过。 当使用 gradle 将项目更改为 运行 时,构建打印警告为红色:
warning: non-varargs call of varargs method with inexact argument type for last parameter
问题是为什么 gradle 打印它而 Maven 不打印?
maven 编译器插件默认配置为忽略警告
https://maven.apache.org/plugins/maven-compiler-plugin/compile-mojo.html#showWarnings
<showWarnings>
Set to true to show compilation warnings.Type: boolean Since: 2.0 Required: No User Property: maven.compiler.showWarnings **Default: false**
另一方面,Gradle 默认显示它们。 You can turn them off.