如何将任务添加到Gradle中的主“构建”任务 [英] How do I add a task to main 'build' task in gradle

查看:307
本文介绍了如何将任务添加到Gradle中的主“构建”任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



  rootProject.tasks.getByName( 'build')。dependsOn mytask 

当我运行 gradle(w )用输出生成

  *其中:
构建文件'... '行
:...

*出错:
评估项目':myapp'时发生问题。
>在根项目'main'中找不到名称为'build'的任务。

如何将任务添加到构建任务?

问题是你的构建没有构建任务,至少在上线被评估时。通常, build 任务被 java-base 插件添加,这些插件又被插件如 java groovy scala 。所以请确保首先应用其中一个插件。或者,如果您不使用任何一个,请声明您自己的 build 任务。


When I try to add a task to the main build task with the following code:

rootProject.tasks.getByName('build').dependsOn mytask

It complains when I run gradle(w) build with the output:

* Where:
Build file '...' line
: ...

* What went wrong:
A problem occurred evaluating project ':myapp'.
> Task with name 'build' not found in root project 'main'.

how do i add the task to the build task?

解决方案

The problem is that your build has no build task, at least at the time when above line gets evaluated. Usually, the build task gets added by the java-base plugin, which in turns gets applied by plugins such as java, groovy, or scala. So make sure to apply one of these plugins first. Or, if you don't use any of them, declare your own build task.

这篇关于如何将任务添加到Gradle中的主“构建”任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆