java - 如何在特定条件下停止 Gradle 或 Maven 构建

标签 java maven gradle

当找不到某些资源时,我想停止程序中的 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/

相关文章:

Maven 和 Exec : forking a process?

java - 如何设置 jformattedtextfield 仅采用 2 个值?

用于处理列表的 Java API

java - 为什么 GridBagLayout 会强制我的组件具有一定的高度?

javascript - 编译时设置错误 react native "gradle"

gradle - Gradle-为特定项目设置特定的JAVA_HOME

java - 如何让 jar 任务在 gradle 中包含单个依赖项

java - 如何使用私钥身份验证进行 SVN 结账?

maven - 不同目录中的 XSD 和 WSDL

Maven 中的 Java EE 7 First Cup 教程错误 : Could not find artifact org. glassfish.javaeetutorial.firstcup :firstcup:pom:7. 0.1-SNAPSHOT