Gradle:如何定义依赖于ant目标的任务

时间:2012-10-05 19:41:10

标签: ant gradle taskdef

如果我列出了gradle testGradle个任务的所有任务 - 我只看到了所有导入的ant任务,但是当我尝试创建依赖于ant任务的任务时,我得到了#34;不能确定任务':testGradle'。

的依赖关系

问题的一行:task testGradle(dependsOn: 'init' ) - 它显然没有看到ant init任务。

我做错了什么?

的build.gradle

println "this will always runs  first"
task buildM << {
  println "Importing ..."
  ant.importBuild  'build.xml'
  println "Done importing"
}

task testGradle(dependsOn : init ) << {
  println tasks.getByPath('init').path
}

gradle tasks all

其他任务

所有     compile - 编译主源树java文件

deploy - deploy WAR file
**init** - Prepare for running compiling artifacts
....

byWorld5 copyTestConfiguration - 复制单元测试配置 deployLoggerProperties - 将logging.properties部署到tomcat execMoped importTasks 安装 - 在Tomcat中安装应用程序 list - 列出Tomcat应用程序 init - 准备运行编译工件 重新加载 - 在Tomcat中重新加载应用程序 start - 启动Tomcat应用程序 停止 - 停止Tomcat应用程序 test - 运行junit测试     compile - 编译主源树java文件

init - Prepare for running compiling artifacts

&GT; gradle -v

Gradle 1.1

Gradle构建时间:2012年7月31日星期二下午1:24:32 UTC Groovy:1.8.6 Ant:2012年5月22日编译的Apache Ant(TM)版本1.8.4 常春藤:2.2.0 JVM:1.6.0_24(Sun Microsystems Inc. 20.0-b12) 操作系统:Linux 2.6.32-220.23.1.el6.x86_64 amd64

&gt; gradle -c

org.gradle.api.GradleScriptException:评估根项目&#m; moped_gradle&#39;时出现问题。     在org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory $ ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:54)     at org.gradle.configuration.DefaultScriptPluginFactory $ ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:127)     在org.gradle.configuration.BuildScriptProcessor.evaluate(BuildScriptProcessor.java:38)     在org.gradle.configuration.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:43)     在org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:463)     在org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:75)     在org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:23)     在org.gradle.configuration.ProjectEvaluationConfigurer.execute(ProjectEvaluationConfigurer.java:21)     在org.gradle.configuration.DefaultBuildConfigurer $ 1.execute(DefaultBuildConfigurer.java:38)     在org.gradle.configuration.DefaultBuildConfigurer $ 1.execute(DefaultBuildConfigurer.java:35)     在org.gradle.api.internal.project.AbstractProject.configure(AbstractProject.java:439)     在org.gradle.api.internal.project.AbstractProject.allprojects(AbstractProject.java:434)     在org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)     在org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:139)     在org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:110)     在org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:78)     在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)     在org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)     在org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:30)     在org.gradle.launcher.cli.ActionAdapter.execute(ActionAdapter.java:22)     在org.gradle.launcher.cli.CommandLineActionFactory $ ParseAndBuildAction.execute(CommandLineActionFactory.java:200)     在org.gradle.launcher.cli.CommandLineActionFactory $ ParseAndBuildAction.execute(CommandLineActionFactory.java:173)     在org.gradle.launcher.cli.CommandLineActionFactory $ WithLogging.execute(CommandLineActionFactory.java:169)     在org.gradle.launcher.cli.CommandLineActionFactory $ WithLogging.execute(CommandLineActionFactory.java:138)     在org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)     在org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)     在org.gradle.launcher.Main.doAction(Main.java:48)     在org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)     在org.gradle.launcher.Main.main(Main.java:39)     在org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)     在org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)     在org.gradle.launcher.GradleMain.main(GradleMain.java:26) 引起:groovy.lang.MissingPropertyException:找不到属性&#39; init&#39;在根项目&#m; moped_gradle&#39;。     at org.gradle.api.internal.AbstractDynamicObject.propertyMissingException(AbstractDynamicObject.java:43)     在org.gradle.api.internal.AbstractDynamicObject.getProperty(AbstractDynamicObject.java:35)     在org.gradle.api.internal.CompositeDynamicObject.getProperty(CompositeDynamicObject.java:60)     在org.gradle.groovy.scripts.BasicScript.propertyMissing(BasicScript.java:70)     在build_62g86rvs7k0vqsu3ssgdsrobsc.run(/home/natalik/MyInstalls/moped_gradle/build.gradle:14)     在org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory $ ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:52)     ......还有33个

1 个答案:

答案 0 :(得分:1)

必须在配置阶段调用ant.importBuild语句才能工作。 我在执行期间做到了。