Skip to content

Replace Gradle delegated properties with direct assignments#9267

Open
3flex wants to merge 3 commits intodetekt:mainfrom
3flex:claude/remove-gradle-delegated-properties-P1Omi
Open

Replace Gradle delegated properties with direct assignments#9267
3flex wants to merge 3 commits intodetekt:mainfrom
3flex:claude/remove-gradle-delegated-properties-P1Omi

Conversation

@3flex
Copy link
Copy Markdown
Member

@3flex 3flex commented Apr 21, 2026

Use of Kotlin delegated properties (the by keyword) in build scripts will be deprecated from Gradle 9.6. See gradle/gradle#37555.

Gradle discourages the use of Kotlin delegated properties (the `by`
keyword) in build scripts because the delegation mixes registration
semantics with eager/lazy lookups in non-obvious ways and interferes
with upcoming Gradle features. See gradle/gradle#37555 for motivation.

Convert every `val x by tasks.registering(...)` /
`val x by configurations.{registering,dependencyScope,resolvable,
consumable}` declaration in the repo's build scripts and convention
plugins to the non-delegated form `val x = tasks.register<T>("x") {}`
/ `val x = configurations.register("x")` etc. The resulting variables
hold the container's `(Named)DomainObjectProvider<T>` directly, so a
few call sites needed `.get()` to unwrap the provider:

- `Configuration.extendsFrom(...)` requires a realized `Configuration`,
  so `extendsFrom(fooProvider.get())` replaces `extendsFrom(fooProvider)`
  in detekt-cli, detekt-generator, and releasing.gradle.kts.
- `JavaExec.classpath` is assigned via `files(detektCliClasspath)` in
  detekt-generator so the provider is adapted to a FileCollection.
- `pluginsJarFiles.files.joinToString(...)` becomes
  `pluginsJarFiles.get().files.joinToString(...)` in detekt-cli.

The unused `val test` in detekt-sample-extensions' `suites { }` block
is dropped in favor of `named<JvmTestSuite>("test") { ... }`.

No task names, configuration names, or behavior change.

Co-authored-by: Claude <claude@anthropic.com>
@3flex 3flex added the housekeeping Marker for housekeeping tasks and refactorings label Apr 21, 2026
extendsFrom(releaseArtifacts)
val releaseArtifacts = configurations.dependencyScope("releaseArtifacts")
val releaseAssetFiles = configurations.resolvable("releaseAssetFiles") {
extendsFrom(releaseArtifacts.get())
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should be able to get rid of the get() again when we update to Gradle 9.4.

https://docs.gradle.org/current/release-notes.html#configurationextendsfrom-accepts-providers

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 21, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@162d9c9). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #9267   +/-   ##
=======================================
  Coverage        ?   84.83%           
  Complexity      ?     4433           
=======================================
  Files           ?      569           
  Lines           ?    12319           
  Branches        ?     2719           
=======================================
  Hits            ?    10451           
  Misses          ?      689           
  Partials        ?     1179           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@3flex 3flex enabled auto-merge (squash) April 28, 2026 00:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

build housekeeping Marker for housekeeping tasks and refactorings

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants