为什么./gradlew clean build和./gradlew clean:build之间有区别? [英] Why is there a difference between ./gradlew clean build and ./gradlew clean :build

查看:1267
本文介绍了为什么./gradlew clean build和./gradlew clean:build之间有区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下情况:

我有一个包含多个子项目的项目.今天,我尝试通过命令行使用gradle构建项目.

I have a project with several subprojects. Today I tried to build the projects with gradle via command line.

当我执行./gradlew clean :build时,构建成功,但是对于./gradlew clean build而言,构建不成功.它会导致不同的错误,具体取决于激活了哪些子项目. 那是为什么?应该不一样吗?

The build was successful when I executed ./gradlew clean :build, but not with ./gradlew clean build. It causes different errors, depending on which subprojects are activated. Why is that? Shouldn't it be the same?

这两个命令是直接在彼此之间直接执行的,而无需更改代码,并且从同一目录(settings.gradle所在的基本目录.

Both commands are executed directly after each other, without changes in the code, and from the same directory (the base-directory, where settings.gradle is located.

Intellij的gradle-refresh工作正常,构建成功(但如果相关,则在构建服务器上失败).

The gradle-refresh of Intellij works, the build is successful (but fails on our build server, if that is relevant).

根据文档 https://docs.gradle.org/current /userguide/command_line_interface.html#executing_tasks_in_multi_project_builds 由于没有指定子项目,并且所有子模块都执行了构建任务,因此我认为它也会这样做.在根项目中没有名为build的文件夹,因此这不会引起混淆.我解释错了吗?

According to the documentation https://docs.gradle.org/current/userguide/command_line_interface.html#executing_tasks_in_multi_project_builds I assumed that it would do the same, since no subproject is specified, and the build task is executed for all submodules. There is no folder called build in the root project, so this should not cause confusion. Am I interpreting it wrong?

我在线搜索,但是找不到结果,因为大多数搜索引擎无法识别:,并且colon会导致不相关的结果,例如

I searched online, however, I could not find the result, since : is is not recognized by most search engines, and colon leads to not relevant results like What is the colon operator in Gradle?.

gradle版本为4.10.2

The gradle version is 4.10.2

如果您需要更多信息,请告诉我.

If you need more information, please let me know.

推荐答案

./gradlew clean :build./gradlew clean build之间是有区别的,这就是为什么您会有不同的行为的原因:在第一种情况下,您使用合格的任务名称,另一种情况是您使用简单的任务名称.这些文档此处

There is a difference between ./gradlew clean :build and ./gradlew clean build, that's why you have a different behavior: in the first case you are using qualified task name, in the other case you are using simple task name. These documentations here and here explain these two approaches for executing tasks:

  • 使用简单任务名称(./gradlew test):

第一种方法类似于单项目用例,但是在多项目构建的情况下,Gradle的工作方式略有不同. gradle test命令将在相对于具有该任务的当前工作目录的任何子项目中执行测试任务.因此,如果您从项目根目录运行命令,则将在api,shared,services:shared和services:webservice中运行测试.如果您在services项目目录中运行命令,则只会在services:shared和services:webservice中执行任务.

The first approach is similar to the single-project use case, but Gradle works slightly differently in the case of a multi-project build. The command gradle test will execute the test task in any subprojects, relative to the current working directory, that have that task. So if you run the command from the root project directory, you’ll run test in api, shared, services:shared and services:webservice. If you run the command from the services project directory, you’ll only execute the task in services:shared and services:webservice.

=>,因此在根项目目录中执行./gradlew build会触发对根项目和所有子项目执行build任务

=> so executing ./gradlew build in the root project directory will trigger execution of build task for root project and all subprojects

  • 使用合格的任务名称(./gradlew :build)

要对执行的内容进行更多控制,请使用限定名称(提到的第二种方法).这些路径与目录路径一样,但是使用:"代替"/"或"\".如果路径以:"开头,则相对于根项目解析路径.换句话说,开头的:"代表根项目本身.所有其他冒号都是路径分隔符.

For more control over what gets executed, use qualified names (the second approach mentioned). These are paths just like directory paths, but use ‘:’ instead of ‘/’ or ‘\’. If the path begins with a ‘:’, then the path is resolved relative to the root project. In other words, the leading ‘:’ represents the root project itself. All other colons are path separators.

=>执行./gradlew :build,您将仅"执行rootProjectbuild任务

=> executing ./gradlew :build , you will execute "only" the build task for rootProject

正如我在评论中所说,您的迁移在一个或多个子项目中存在一些问题,但是如果仅执行Root项目构建(./gradlew :build)

As I said in comment, you migth have some issues in one or more of your subproject, but you will not see these errors if you execute only Root project build ( ./gradlew :build )

这篇关于为什么./gradlew clean build和./gradlew clean:build之间有区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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