Reputation: 1501
I want to stop the gradle build from my program when certain resources are not found.
For example, My program searches for abc.properties. Currently when it is not found, all the possible error messages are displayed where the values of the property file are required. Instead I just want to display one line error message like "The file abc.properties is missing" , and then stop the build without displaying other lengthy messages. I have tried System.exit(), but is does not help.
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
}
Upvotes: 0
Views: 743
Reputation: 179
Another alternative in Gradle would be declaring that file as a dependency. If it can't be resolved, build will fail. It's somewhat of a workaround, but it should work.
Upvotes: 1
Reputation: 28653
In gradle you can just put this in your buildscript:
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")
}
Upvotes: 2