Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failure from BuildListener are ignored #7329

Closed
ljacomet opened this issue Oct 10, 2018 · 8 comments
Closed

Failure from BuildListener are ignored #7329

ljacomet opened this issue Oct 10, 2018 · 8 comments
Assignees
Milestone

Comments

@ljacomet
Copy link
Member

When a BuildListener is registered, any exception thrown during its execution should fail the build.

With the following settings.gradle:

def adapter = new BuildAdapter() {
    void projectsEvaluated(Gradle gradle) {
        println 'About to break the build!'
        throw new GradleException('BOOOM')
    }
}

gradle.addListener(adapter)

and an empty build.gradle

Expected Behavior

Running ./gradlew tasks should fail the build as the listener throws an exception.
That is the case with Gradle 4.9

Current Behavior

Starting with Gradle 4.10 and the latest 5.0 nightly, the build is successful.

Steps to Reproduce (for bugs)

  • Create a settings.gradle as indicated above
  • Create an empty build.gradle
  • Run with Gradle > 4.10 and see build pass
  • Run with Gradle <= 4.9 and see build fail

Your Environment

@ljacomet
Copy link
Member Author

From initial investigations, it looks like between this code which sets the failure on the context and this code which creates the context and passes it down for execution, nowhere is the context queried for a failure and that failure thrown out.

@mkobit
Copy link
Contributor

mkobit commented Oct 10, 2018

Maybe similar to #6900 ?

@ljacomet
Copy link
Member Author

I should have searched better, thanks for the link!
But the difference between Kotlin and Groovy DSL might indicate a different problem.
So not marking this one a duplicate just now.

@ljacomet
Copy link
Member Author

Playing around with the behavior reported in #6900, I tested using Gradle.projectsEvaluated and both the Closure and Action based version do fail the build when used.

@ldaley
Copy link
Member

ldaley commented Oct 11, 2018

@ljacomet I think the solution should be to change

to just throw there (by using JavaMethod to do the invoke).

And… add some test coverage :S

@oehme
Copy link
Contributor

oehme commented Oct 15, 2018

The decoration did not cause this failure - It doesn't matter if you throw or call context.setFailure, the exception will be propagated.

The reason why buildFinished can no longer fail the build are the changes in feb84b4. This was not caught, because the corresponding test case has been @Ignored for a long time.

@adammurdoch would you mind taking a look at this? The behavior is pretty confusing now, as you will get both a Build Successful and Build Failed message in the console output and the latter lacks the correct location information. The overall return code of Gradle is successful.

Looking at the code, the behavior was odd before too. If a listener failed, it was actually called again with that failure.

@oehme oehme assigned adammurdoch and unassigned oehme Oct 15, 2018
@slaverda
Copy link

slaverda commented Oct 16, 2018

Hi All,

Do you have any updates on that issue ? It's blocking our migration to the latest gradle.

@adammurdoch
Copy link
Member

Fixed via #7510. The fix will be in Gradle 5.0.

The PR doesn't fix the issue of missing location information and misleading BUILD SUCCESSFUL message for buildFinished failures. That is a separate issue that I'll fix in master for 5.1, as it's been around for a very long time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants