[GRADLE-2617] Some exception during plugin.apply() cant be eaten and don't break the build Created: 03/Jan/13  Updated: 17/Nov/16  Resolved: 17/Nov/16

Status: Resolved
Project: Gradle
Affects Version/s: 1.3
Fix Version/s: None

Type: Bug
Reporter: Xavier Ducrohet Assignee: Luke Daley
Resolution: Duplicate Votes: 0


 Description   

Due to a broken Groovy refactor, my code ended up throwing a java.lang.IllegalAccessError from a method called from my plugin's apply(Project) method.

I would expect this to stop gradle executing the build, but instead the exception ended up being eaten by the caller somehow and the build continued (and failed later in a weird way).



 Comments   
Comment by Xavier Ducrohet [ 03/Jan/13 ]

oops. the title is wrong. Should read "... can be eaten ..."

Comment by Luke Daley [ 14/Jan/13 ]

I cannot reproduce this with 1.3. Here is what I tried:

class SomePlugin implements Plugin {
    void apply(project) {
        throw new  java.lang.IllegalAccessError("!!")
    }
}

apply plugin: SomePlugin

This fails in the expected way.

If you can provide more information so that I can reproduce I'll happily reopen.

Comment by Xavier Ducrohet [ 14/Jan/13 ]

Indeed when I run this snippet, it fails as expected, but with my own project it doesn't.

It's open source so I could show you how to check it out and build it to see for yourself, but it's a bit involved.

I'm going to try to make a reproducible case first.

Comment by Luke Daley [ 14/Jan/13 ]

Hi Xavier,

I'm happy to check out your failing code an reproduce it there. Please post some steps I can follow to reproduce.

Comment by Xavier Ducrohet [ 14/Jan/13 ]

Hi Luke,

I tried to extract what my plugin does to make a reproducible case it's not happening.

I was looking at giving you all the steps to have you try it with my plugin but there's a dependency on an internal tools that should be removed in a few days. I'll let you know when you can try. thanks.

Comment by Luke Daley [ 15/Apr/13 ]

Hi Xavier,

Have you been able to reproduce this?

Comment by Xavier Ducrohet [ 02/May/13 ]

Hi Luke,

I haven't been able to reproduce though I just got something a bit similar (but not completely broken). My project has a configuration problem and the plugin throws a RuntimeException in the apply() method, after setting an afterEvaluate closure.

What happens is that the afterEvaluate closure is executed even though apply() threw an exception. Of course it fails, and dumps an exception of its own, which gets dump in the terminal. This is a strange behavior, but at least the error message shows also the original error message from the apply error which makes the the exception dump is misleading at first).

Here's the output:

Failed to notify ProjectEvaluationListener.afterEvaluate(), but primary configuration failure takes precedence.
org.gradle.listener.ListenerNotificationException: Failed to notify project evaluation listener.
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:90)
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:30)
at org.gradle.messaging.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:93)
at com.sun.proxy.$Proxy10.afterEvaluate(Unknown Source)
at org.gradle.configuration.LifecycleProjectEvaluator.notifyAfterEvaluate(LifecycleProjectEvaluator.java:67)
at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:61)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:465)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:76)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:31)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:142)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
at org.gradle.launcher.daemon.server.exec.ExecuteBuild.doBuild(ExecuteBuild.java:45)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.WatchForDisconnection.execute(WatchForDisconnection.java:42)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ResetDeprecationLogger.execute(ResetDeprecationLogger.java:24)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.StartStopIfBuildAndStop.execute(StartStopIfBuildAndStop.java:33)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ReturnResult.execute(ReturnResult.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:70)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput$2.call(ForwardClientInput.java:68)
at org.gradle.util.Swapper.swap(Swapper.java:38)
at org.gradle.launcher.daemon.server.exec.ForwardClientInput.execute(ForwardClientInput.java:68)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.LogToClient.doBuild(LogToClient.java:60)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.EstablishBuildEnvironment.doBuild(EstablishBuildEnvironment.java:59)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy$1.run(StartBuildOrRespondWithBusy.java:45)
at org.gradle.launcher.daemon.server.DaemonStateCoordinator.runCommand(DaemonStateCoordinator.java:186)
at org.gradle.launcher.daemon.server.exec.StartBuildOrRespondWithBusy.doBuild(StartBuildOrRespondWithBusy.java:49)
at org.gradle.launcher.daemon.server.exec.BuildCommandOnly.execute(BuildCommandOnly.java:34)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.HandleStop.execute(HandleStop.java:36)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.CatchAndForwardDaemonFailure.execute(CatchAndForwardDaemonFailure.java:32)
at org.gradle.launcher.daemon.server.exec.DaemonCommandExecution.proceed(DaemonCommandExecution.java:125)
at org.gradle.launcher.daemon.server.exec.DefaultDaemonCommandExecuter.executeCommand(DefaultDaemonCommandExecuter.java:48)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.handleCommand(DefaultIncomingConnectionHandler.java:155)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.receiveAndHandleCommand(DefaultIncomingConnectionHandler.java:128)
at org.gradle.launcher.daemon.server.DefaultIncomingConnectionHandler$ConnectionWorker.run(DefaultIncomingConnectionHandler.java:116)
at org.gradle.internal.concurrent.DefaultExecutorFactory$StoppableExecutorImpl$1.run(DefaultExecutorFactory.java:66)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.NullPointerException
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.createGroovyObjectGetPropertySite(AbstractCallSite.java:254)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.acceptGroovyObjectGetProperty(AbstractCallSite.java:239)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at com.android.build.gradle.BasePlugin.resolveDependencyForConfig(BasePlugin.groovy:1188)
at com.android.build.gradle.BasePlugin$resolveDependencyForConfig.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:153)
at com.android.build.gradle.BasePlugin.resolveDependencies(BasePlugin.groovy:1141)
at com.android.build.gradle.BasePlugin$resolveDependencies.callCurrent(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:141)
at com.android.build.gradle.LibraryPlugin.doCreateAndroidTasks(LibraryPlugin.groovy:119)
at com.android.build.gradle.BasePlugin.createAndroidTasks(BasePlugin.groovy:222)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:361)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.callCurrent(PogoMetaClassSite.java:66)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:46)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:133)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:137)
at com.android.build.gradle.BasePlugin$_apply_closure1.doCall(BasePlugin.groovy:178)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:90)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:233)
at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:272)
at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:877)
at groovy.lang.Closure.call(Closure.java:412)
at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:40)
at org.gradle.listener.ClosureBackedMethodInvocationDispatch.dispatch(ClosureBackedMethodInvocationDispatch.java:25)
at org.gradle.listener.BroadcastDispatch.dispatch(BroadcastDispatch.java:81)
... 54 more

FAILURE: Build failed with an exception.

  • Where:
    Build file '/Volumes/AndroidHD/ext/master2/tools/build/tests/repo/baseLibrary/build.gradle' line: 10
  • What went wrong:
    A problem occurred evaluating root project 'baseLibrary'.
    > SDK location not found. Define location with sdk.dir in the local.properties file or with an ANDROID_HOME environment variable.
  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Comment by Luke Daley [ 07/May/13 ]

> What happens is that the afterEvaluate closure is executed even though apply() threw an exception.

This is not surprising. The closure you give to afterEvaluate() is a callback, and fires even if evaluation failed.

You should check the project's state (http://www.gradle.org/docs/current/javadoc/org/gradle/api/Project.html#getState()) in your afterEvaluate callback and return if it's in a failed state.

Comment by Bruno Bowden [ 21/Nov/14 ]

Hi Luke,
can you provide an example code snippet for correct use of throw and getState() - after lots of experimentation, I've been unable to figure out the syntax. I've asked the question in StackOverflow but this was still the top search result in Google:

Question:
http://stackoverflow.com/questions/27068884/gradle-throwing-errors-during-plugin-apply-failed-to-notify-projectevaluati

Comment by Benjamin Muschko [ 15/Nov/16 ]

As announced on the Gradle blog we are planning to completely migrate issues from JIRA to GitHub.

We intend to prioritize issues that are actionable and impactful while working more closely with the community. Many of our JIRA issues are inactionable or irrelevant. We would like to request your help to ensure we can appropriately prioritize JIRA issues you’ve contributed to.

Please confirm that you still advocate for your JIRA issue before December 10th, 2016 by:

  • Checking that your issues contain requisite context, impact, behaviors, and examples as described in our published guidelines.
  • Leave a comment on the JIRA issue or open a new GitHub issue confirming that the above is complete.

We look forward to collaborating with you more closely on GitHub. Thank you for your contribution to Gradle!

Comment by Eric Wendelin [ 17/Nov/16 ]

Moved to https://github.com/gradle/gradle/issues/874

Generated at Wed Jun 30 12:26:48 CDT 2021 using Jira 8.4.2#804003-sha1:d21414fc212e3af190e92c2d2ac41299b89402cf.