Gradle daemon causing issues with plugin execution


(Harsha Ramesh) #1

Hi,

I wrote a plugin for internal consumption. It is a plugin for integrating with Jenkins and executing / configuring jobs. In short, the plugin does the following,

  • Create the extension on the project.
  • In the target.afterEvaluate { // read some configuration files and then create additional tasks }
  • During the task execution, the plugin might want to acquire user input - So I get hold of System.console and, if available, acquire the user input.

After upgrading to 3.1, I noticed a few issues,

Inconsistent errors / failures

  • IllegalStateException: Cannot locate service of type DependencyMetaDataProvider, as ProjectScopeServices has been closed.
  • System.console is null - which makes sense if the process is running on the daemon, but doesn’t help my case.

But, when I explicitly disable the daemon (via command line) it works perfectly fine.

Here is a sample stacktrace for issue 1

Caused by: java.lang.IllegalStateException: Cannot locate service of type DependencyMetaDataProvider, as ProjectScopeServices has been closed.
at org.gradle.internal.service.DefaultServiceRegistry.doGet(DefaultServiceRegistry.java:422)
at org.gradle.internal.service.DefaultServiceRegistry.get(DefaultServiceRegistry.java:410)
at org.gradle.api.internal.project.DefaultProject.getModule(DefaultProject.java:901)
at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.getProperties(BeanDynamicObject.java:349)
at org.gradle.internal.metaobject.BeanDynamicObject.getProperties(BeanDynamicObject.java:160)
at org.gradle.internal.metaobject.CompositeDynamicObject.getProperties(CompositeDynamicObject.java:77)
at org.gradle.api.internal.project.DefaultProject$4.create(DefaultProject.java:841)
at org.gradle.api.internal.project.DefaultProject$4.create(DefaultProject.java:839)
at org.gradle.util.SingleMessageLogger.whileDisabled(SingleMessageLogger.java:182)
at org.gradle.api.internal.project.DefaultProject.getProperties(DefaultProject.java:839)
at org.gradle.internal.metaobject.BeanDynamicObject$MetaClassAdapter.getProperty(BeanDynamicObject.java:197)
at org.gradle.internal.metaobject.BeanDynamicObject.getProperty(BeanDynamicObject.java:150)
at org.gradle.internal.metaobject.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:55)
at org.gradle.internal.metaobject.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:60)
at org.gradle.api.internal.project.DefaultProject_Decorated.getProperty(Unknown Source)
at com.xxx.integration.jenkins.tasks.AbstractJenkinsTask.getJenkinsHelper(AbstractJenkinsTask.groovy:51)

So, I would like to know if there are any FAQs / Guidelines for developer to verify that their plugin would work well against the new version?

What is the preferred way for a Gradle plugin to acquire user input? The execution environment of the plugin can be controlled, so I can make a few changes to it. For example, if there is a way to identify that the plugin code is being executed in the daemon, I can provide a warning / update the user’s property file and inform them to run it again.

Looking forward to your responses.

Thanks,
Harsha