我想在不执行单元测试的情况下执行grade构建。我尝试了:

$ gradle -Dskip.tests build

这似乎没什么用。还有其他命令可以使用吗?


当前回答

公认的答案是正确的。

OTOH,我之前解决这个问题的方法是在所有项目中添加以下内容:

test.onlyIf { ! Boolean.getBoolean('skip.tests') }

使用-Dskip.tests=true运行生成,将跳过所有测试任务。

其他回答

Try:

gradle assemble

要列出项目的所有可用任务,请尝试:

gradle tasks

更新:

起初,这似乎不是最正确的答案,但仔细阅读任务输出或文档。

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.

在Java插件中:

$ gradle tasks

Build tasks
-----------
assemble - Assembles the outputs of this project.
build - Assembles and tests this project.
testClasses - Assembles test classes.

Verification tasks
------------------
test - Runs the unit tests.

分级构建而不进行测试,您有两种选择:

$ gradle assemble
$ gradle build -x test

但如果您想要编译测试:

$ gradle assemble testClasses
$ gradle testClasses

请尝试以下操作:

gradlew-DskipTests=真实构建

您可以排除任务

 gradle build --exclude-task test 

https://docs.gradle.org/current/userguide/command_line_interface.html#sec:command_line_executing_tasks

公认的答案是正确的。

OTOH,我之前解决这个问题的方法是在所有项目中添加以下内容:

test.onlyIf { ! Boolean.getBoolean('skip.tests') }

使用-Dskip.tests=true运行生成,将跳过所有测试任务。