Gradle Goodness: Excluding Tasks for Execution

本文介绍如何在Gradle中创建任务依赖,并演示了如何通过命令行选项排除特定任务及其依赖项,确保部署任务仍能执行其直接依赖。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In Gradle we can create dependencies between tasks. But we can also exclude certain tasks from those dependencies. We use the command-line option -x or --exclude-task and specify the name of task we don't want to execute. Any dependencies of this task are also excluded from execution. Unless another task depends on the same task and is executed. Let's see how this works with an example:

00. task copySources << {
01. println 'Copy sources.'
02. }
03.  
04. task copyResources(dependsOn: copySources) << {
05. println 'Copy resources.'
06. }
07.  
08. task jar(dependsOn: [copySources, copyResources]) << {
09. println 'Create JAR.'
10. }
11.  
12. task deploy(dependsOn: [copySources, jar]) << {
13. println 'Deploy it.'
14. }

We execute the deploy task:

$ gradle -q deploy
Copy sources.
Copy resources.
Create JAR.
Deploy it.

Now we exclude the jar task. Notice how the copySources task is still executed because of the dependency in the deploy task:

$ gradle -q deploy -x jar
Copy sources.
Deploy it.

转载于:https://www.cnblogs.com/GoAhead/p/4189133.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值