Gradle Goodness: Skip Building Project Dependencies

If we use Gradle in a multi-module project we can define project dependencies between modules. Gradle uses the information from the project dependencies to determine which tasks need to be run. For example if module B depends on module A and we want to build module B, Gradle will also build module A for us, because module B depends on it. But if we know for sure that module A is up to date and has not changed, we can also instruct Gradle to skip building module A, when we build module B.

Let‘s start with the following module structure, where each module depends on the module above it. So module services depends on common and module web depends on services:

.

├── common

├── services

└── web

When we want to build the service module we go to the services directory and execute the build task and we get the following output:

$ gradle build

:common:compileJava

:common:processResources

:common:classes

:common:jar

:services:compileJava

:services:processResources

:services:classes

:services:jar

:services:assemble

:services:compileTestJava

:services:processTestResources

:services:testClasses

:services:test

:services:check

:services:build

BUILD SUCCESSFUL

Total time: 8.013 secs

We see in the output that first the common module is build, because the services module depends on it. But if we work on this project and we know for sure the common module is up to date and has not changed since the last build (for example we didn‘t checkout new sources from version control or changed sources in the common module ourselves), then we can skip building the common module. We use the command line option -a or --no-rebuild to tell Gradle to skip project dependencies.

When we run the build task from the services directory using the command line option -a we get the following output:

$ gradle -a build

:services:compileJava

:services:processResources

:services:classes

:services:jar

:services:assemble

:services:compileTestJava

:services:processTestResources

:services:testClasses

:services:test

:services:check

:services:build

BUILD SUCCESSFUL

Total time: 5.626 secs

This time only the services module is build, which also speeds up the build proces. Still this should only be used if we know ourselves the project dependencies are up to date.

Written with Gradle 2.2.1.

时间: 2024-10-19 17:26:41

Gradle Goodness: Skip Building Project Dependencies的相关文章

Windows下Android Studio长时间停留在Building "Project Name" Gradle project info画面的解决方法

问题描述: 创建好一个Android项目后,Android Studio长时间停留在Building [Project Name] Gradle project info画面不动. 原因: 此时Android Studio在下载gradle-X.XX-all.zip文件,但是下载过程中经常中断,导致重来(不支持断点续传?). 解决办法: 1. 首先查看gradle版本,路径:C:\Users\[用户名]\.gradle\wrapper\dists\gradle-X.XX-all 2. 然后去Gr

在android studio中新建android gradle project的时候connect refused:connect或者卡在building project...或Refreshing

在android studio中新建android gradle project的时候connect refused:connect或者卡在building project...或Refreshing xxx gradle project === 原因是: gradle在创建时需要联网,不然的话会失败,我虽然可以联网,但是不能访问gradle网站或者下载不了,所以不行. 感谢伟大的GFW,两种方法 1. 使用代理 --- 翻墙就可以了 - 启动XX门 - android studio -> se

Gradle Goodness: Display Available Tasks

To see which tasks are available for our build we can run Gradle with the command-line option -t or --tasks. Gradle outputs the available tasks from our build script. By default only the tasks which are dependencies on other tasks are shown. To see a

Gradle Goodness: Task Output Annotations Create Directory Automatically

Gradle Goodness: Task Output Annotations Create Directory Automatically One of the great features of Gradle is incremental build support. With incremental build support a task is only executed if it is really necessary. For example if a task generate

Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects

Gradle Goodness: Init Script for Adding Extra Plugins to Existing Projects Gradle is very flexible. One of the ways to alter the build configuration is with initialization or init scripts. These are like other Gradle scripts but are executed before t

Gradle Goodness: Copy Files with Filtering

Gradle Goodness: Copy Files with Filtering Gradle's copy task is very powerful and includes filtering capabilities. This means we can change the contents of the files that are copied before they reach their new destination. We use the filter() method

Gradle Goodness: Check Task Dependencies With a Dry Run

We can run a Gradle build without any of the task actions being executed. This is a so-called dry run of our build. We can use the dry run of a build to see if the task dependencies we have defined or are defined in a plugin are defined properly. Bec

Gradle Goodness: Group Similar Tasks

In Gradle we can assign a task to a group. Gradle uses the group for example in the output of $ gradle -t to output all the tasks of the same group together. We only have to set the group property with a value and our task belongs to a group. In the

Gradle Goodness: Working with Live Task Collection

Gradle support the definition of so called live collections. These collections are mostly created based on criteria like with a filter() or matching() method. The collection content can change if the content of the source collection changes. For exam