Always use Gradle's Provider API when accessing project, system, or Gradle properties in your build configuration. This ensures proper handling of configuration cache and allows for dynamic property updates.
Always use Gradle’s Provider API when accessing project, system, or Gradle properties in your build configuration. This ensures proper handling of configuration cache and allows for dynamic property updates.
Instead of directly accessing properties:
// DON'T
val verbose = (project.hasProperty("kapt.verbose") &&
project.property("kapt.verbose").toString().toBoolean() == true)
// DO
val verbose = project.providers.gradleProperty("kapt.verbose")
.map { it.toBoolean() }
.orElse(false)
// DON'T
val systemProp = System.getProperty("my.property")
// DO
val systemProp = project.providers.systemProperty("my.property")
This approach:
When dealing with file paths or build directory locations, use ProjectLayout:
val layout = project.layout
val outputFile = layout.buildDirectory.file("output/file.txt")
Enter the URL of a public GitHub repository