My project-level (aka top-level, not module-level) build.gradle
contains the following:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.5.2'
classpath("de.mannodermaus.gradle.plugins:android-junit5:1.8.2.1")
classpath("org.mockito:mockito-inline:5.2.0")
}
}
allprojects {
repositories {
gradlePluginPortal()
mavenCentral()
google()
}
}
It works fine but an "old book" (circa Android Studio Arctic Fox, 2020.3.1) that discusses Gradle says that is should contain a clean
task.
Then again, after a few paragraphs it also says
As written, this task is almost useless, and it is unclear why Google includes it, other than perhaps to point out that you are able to define custom tasks.
So I am unsure whether it must be there or not. Perhaps in the latest & greatest Android Studio (Koala, 2024.1.1) it is implied and is no longer needed?
How does this work?
The information in the seems a bit outdated when it comes to the clean
task in the top-level build.gradle
:
Old Gradle Behavior:
Modern Gradle Behavior:
Gradle now automatically includes a clean task that targets the buildDir
directory in each project (including the top-level project).
This means the build artifacts for the entire project get cleaned when you run gradle clean
.
The comment in the book may refer to the fact that the default clean task only cleans the buildDir
. Depending on your project structure, it might not catch all the potential build artifacts.
For example, if you manually copy artifacts to a different location outside the buildDir
, the clean task won't remove them.
If you have custom build artifacts outside the buildDir, you can either: