当找不到某些资源时,我想停止程序中的 gradle 构建。
例如,我的程序搜索 abc.properties。目前,当未找到时,会在需要属性文件值的地方显示所有可能的错误消息。相反,我只想显示一行错误消息,例如“文件 abc.properties 丢失”,然后停止构建而不显示其他冗长的消息。我尝试过 System.exit(),但没有帮助。
try {
properties.load(PropertyFactory.class.classLoader.getResourceAsStream("abc.properties") );
} catch(Exception e) {
System.out.println("Please put a valid properties file in the src/main/resources folder named abc.properties");
System.exit(1);//something that will stop the build and prevent other error messages
}
最佳答案
在 gradle 中,你可以将其放入构建脚本中:
if(!file("src/main/resources/abc.properties").exists()){
throw new GradleException("Please put a valid properties file in the src/main/resources folder named abc.properties")
}
关于java - 如何在特定条件下停止 Gradle 或 Maven 构建,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26113769/