Gradle is smart enough to skip running tasks if there haven’t been any changes compared to the previous build. This post shows how to override the default optimisation to ensure the given task is executed every single time.

Let’s create a sample project:

mkdir hello-gradle && cd $_ && gradle init --type java-library

Build it:

gradle build
...
:test
:check
:build
BUILD SUCCESSFUL

Now let’s pick the test task and run just that one with a debug option on:

gradle test -d
...
0:46:52.653 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Skipping task ':test' as it is up-to-date (took 0.073 secs).
10:46:52.654 [DEBUG] [org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter] Finished executing task ':test'
10:46:52.654 [LIFECYCLE] [class org.gradle.TaskExecutionLogger] :test UP-TO-DATE

The task was skipped as expected. Removing the build destroys the cache and makes the tests re-run:

gradle clean test -d
...
10:50:01.966 [INFO] [org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter] Executing task ':test'

The project cleanup however can be avoided by applying the rerun-tasks flag:

gradle test --rerun-tasks

The tests will run again, but without the need to clean the build first.


Tomas Zezula

Hello! I'm a technology enthusiast with a knack for solving problems and a passion for making complex concepts accessible. My journey spans across software development, project management, and technical writing. I specialise in transforming rough sketches of ideas to fully launched products, all the while breaking down complex processes into understandable language. I believe a well-designed software development process is key to driving business growth. My focus as a leader and technical writer aims to bridge the tech-business divide, ensuring that intricate concepts are available and understandable to all. As a consultant, I'm eager to bring my versatile skills and extensive experience to help businesses navigate their software integration needs. Whether you're seeking bespoke software solutions, well-coordinated product launches, or easily digestible tech content, I'm here to make it happen. Ready to turn your vision into reality? Let's connect and explore the possibilities together.