Should gradle command fail when no build file is found?


(andrew.oberstar) #1

It appears that any time you execute Gradle and it doesn’t find a build file, it still exits with a 0 return code. This causes issues in our CI environment where the build is reported as a success when it never happened.

The ultimate issue is that the CI config is looking in the wrong place for the build file. However, it results in confusing output when Gradle doesn’t actually fail because of this.

Is there a reason for the behavior, or has no one brought this up before?

Example Output:

:help
    Welcome to Gradle 1.0-milestone-4.
    To run a build, run gradle <task> ...
    To see a list of available tasks, run gradle tasks
    To see a list of command-line options, run gradle --help
    BUILD SUCCESSFUL

(Peter Niederwieser) #2

It’s not mandatory to have a build file, especially when you just run gradle without any arguments. If that’s what you do, I suggest to list tasks explicitly instead of relying on default tasks.


(andrew.oberstar) #3

I agree we should be calling with a list of tasks, but I’m still not understanding the reasoning.

What does Gradle do if you don’t have a build file? If it’s not going to execute anything and merely print out that message, it seems counterintuitive to have that succeed.


(Peter Niederwieser) #4

At the end of the day it’s really just an edge case where ‘gradle’ can have different meanings depending on whether a build script is present or not.

Failing the build would mean that you can’t get help if no build script is present, which is counter-intuitive as well. Maybe it’s still the right thing to do, I don’t know. I haven’t seen default tasks used a lot, which might explain why people haven’t hit this yet and why we haven’t considered to put some check in place for this edge case.

In general, a Gradle build is not required to have a build script as long as there is a settings.gradle.


(andrew.oberstar) #5

Not to keep pushing this, because it is an edge case as you say, but couldn’t it print out the help and then fail?

This is a small percentage of our builds that have the potential to be affected, so we can live with it either way.


(andrew.oberstar) #6

This would just be in the case where you don’t pass any arguments. If you pass -h or -v or something like that it obviously shouldn’t fail.

As an example running ant with no arguments prints this:

Buildfile: build.xml does not exist!
Build failed