Why can't I make tasks of type:Delete in a plugin?


(Jamie Olson) #1

In a build.gradle, this works fine:

task clean(type:Delete) {

delete “${project.buildDir}/${project.name}” }

but if I want to generalize this with a plugin:

… project.task(‘clean’,type:Delete) {

delete “${project.buildDir}/${project.name}” } …

when I execute the clean task:

No such property: Delete for class: MyPlugin

  • Try: Run with --info or --debug option to get more log output.

  • Exception is: org.gradle.api.GradleScriptException: A problem occurred evaluating project ‘my-tools-r’.

at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)

at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)

at org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)

at org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)

at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:463)

at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)

at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)

at org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)

at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:38)

at org.gradle.configuration.DefaultBuildConfigurer$1.execute(DefaultBuildConfigurer.java:35)

at org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:439)

at org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:434)

at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)

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.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:38)

at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:39)

at org.gradle.launcher.exec.InProcessGradleLauncherActionExecuter.execute(InProcessGradleLauncherActionExecuter.java:25)

at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)

at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)

at org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:200)

at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:173)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)

at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:138)

at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)

at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)

at org.gradle.launcher.Main.doAction(Main.java:48)

at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)

at org.gradle.launcher.Main.main(Main.java:39)

at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)

at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)

at org.gradle.launcher.GradleMain.main(GradleMain.java:26) Caused by: groovy.lang.MissingPropertyException: No such property: Delete for class: MyPlugin

at MyPlugin.apply(MyPlugin.groovy:15)

at MyPlugin.apply(MyPlugin.groovy)

at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.providePlugin(DefaultProjectsPluginContainer.java:107)

at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.addPluginInternal(DefaultProjectsPluginContainer.java:71)

at org.gradle.api.internal.plugins.DefaultProjectsPluginContainer.apply(DefaultProjectsPluginContainer.java:37)

at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyPlugin(DefaultObjectConfigurationAction.java:101)

at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:32)

at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:72)

at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:114)

at org.gradle.api.internal.project.AbstractProject.apply(AbstractProject.java:841)

at org.gradle.api.Project$apply.call(Unknown Source)

at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)

at org.gradle.api.Script$apply.callCurrent(Unknown Source)

at build_7gphij4a9hktl6k55b8hjq62qm.run(/build.gradle:13)

at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)

… 33 more


(Peter Niederwieser) #2

Builds scripts have a number of default imports. In a plugin class you’ll have to import class ‘org.gradle.api.tasks.Delete’.


(Jamie Olson) #3

Great, thanks!


(Jamie Olson) #4

FWIW I’d suggest adding something about the default imports, since right now there doesn’t appear to be any discussion of this in either the section on custom plugins or the section that talks about how the project are imported by default. It was particularly surprising for me since I’d gotten tasks of type:Exec to work, since that’s apparently loaded by default in plugins.


(Peter Niederwieser) #5

As soon as you write a class, it’s just plain Java/Groovy/etc. development, and Gradle won’t interfere at all. I have no explanation why ‘Exec’ would work without an import. Maybe you had an import and weren’t aware of it. Or maybe you put your own class into the same package.


(Peter Niederwieser) #6

Or maybe you put your own class into a build script. Then you should still get the default imports.


(Jamie Olson) #7

Ha! Indeed I’m a liar. There’s the import right at the top, but I never noticed because I’d pasted it in from an example.