Skip to content

build: convert build.gradle from Groovy to Kotlin DSL - #36

Open
soloturn wants to merge 1 commit into
developfrom
build/gradle-kotlin-dsl
Open

build: convert build.gradle from Groovy to Kotlin DSL#36
soloturn wants to merge 1 commit into
developfrom
build/gradle-kotlin-dsl

Conversation

@soloturn

Copy link
Copy Markdown
Contributor

Description

Converts the repo's build.gradle from Groovy DSL to Kotlin DSL (build.gradle -> build.gradle.kts). No intended behavior change. Companion to MovingBlocks/DestinationSol#737.

Notable non-mechanical changes

  • com.android.application is applied via apply(plugin = ...) rather than the plugins{} block (its version comes from the buildscript classpath, not the plugin portal), so the type-safe android{} accessor is never generated. Configured the extension explicitly via configure<ApplicationExtension>{} instead — and specifically the modern com.android.build.api.dsl.ApplicationExtension, not the legacy com.android.build.gradle.AppExtension: AGP 9.x defaults to android.newDsl=true, under which only the modern extension gets registered as a project extension at all.
  • Several android{} DSL calls that Groovy's dynamic typing let slide are ERROR-level deprecated from Kotlin (AGP marks them @Deprecated(level = ERROR), which Groovy's dynamic dispatch never checks but Kotlin enforces as a hard compile failure): sourceSet .setSrcDirs() → the directories mutable set, packagingOptions{}packaging{}, its top-level excludes/merges/pickFirsts → nested under resources., lintOptions{}'s isAbortOnErrorlint{}'s abortOnError, and the group/name/version dependency notation → single-string notation.
  • Two genuine Kotlin-only pitfalls from property-name collisions: inside defaultConfig{}/android{}, bare references to compileSdk/minSdk/targetSdk resolve to those DSL blocks' own (nullable, initially-unset) same-named properties rather than this script's top-level vals of the same name, since Kotlin's implicit-receiver member lookup shadows the outer scope. Groovy's dynamic property resolution doesn't have this failure mode. Renamed the top-level vals to compileSdkNumber/minSdkNumber/targetSdkNumber to make the two unambiguous.
  • signingConfigs { release { ... } } relies on Groovy's container DSL sugar to create the "release" signing config, since none exists by default (unlike buildTypes, where "release" is a default AGP build type). Kotlin's getByName() requires it to already exist and throws; switched to create("release").
  • AndroidComponentsExtension<*, *, *> (the generic base type) isn't registered as a project extension; only the concrete ApplicationAndroidComponentsExtension is, for application modules.

Testing

Verified end-to-end against a real Android SDK (not just a compile-only smoke test): built a local copy of this build.gradle.kts into a Kotlin DSL-converted checkout of DestinationSol (MovingBlocks/DestinationSol#737) and ran gradlew :android:compileDebugJavaWithJavac successfully, in addition to :android:help configuring the full variant/module-dexing task graph (androidComponents{}, per-module dex/export tasks) without error.

Converts the repo's only Gradle file to build.gradle.kts. No intended
behavior change.

Notable non-mechanical changes required along the way:
- com.android.application is applied via apply(plugin = ...) rather than
  the plugins{} block (its version comes from the buildscript classpath,
  not the plugin portal), so the type-safe android{} accessor is never
  generated. Configured the extension explicitly via
  configure<ApplicationExtension>{} instead - and specifically the
  modern com.android.build.api.dsl.ApplicationExtension, not the legacy
  com.android.build.gradle.AppExtension: AGP 9.x defaults to
  android.newDsl=true, under which only the modern extension gets
  registered as a project extension at all.
- Several android{} DSL calls that Groovy's dynamic typing let slide are
  ERROR-level deprecated from Kotlin (AGP marks them
  @deprecated(level = ERROR), which Groovy's dynamic dispatch never
  checks but Kotlin enforces as a hard compile failure): sourceSet
  .setSrcDirs() -> the `directories` mutable set, packagingOptions{} ->
  packaging{}, its top-level excludes/merges/pickFirsts -> nested under
  resources., lintOptions{} isAbortOnError -> lint{} abortOnError, and
  the group/name/version dependency notation -> single-string notation.
- Two genuine Kotlin-only pitfalls from property-name collisions: inside
  defaultConfig{}/android{}, bare references to compileSdk/minSdk/
  targetSdk resolve to those DSL blocks' own (nullable, initially unset)
  same-named properties rather than this script's top-level vals of the
  same name, since Kotlin's implicit-receiver member lookup shadows the
  outer scope. Groovy's dynamic property resolution doesn't have this
  failure mode. Renamed the top-level vals to compileSdkNumber/
  minSdkNumber/targetSdkNumber to make the two unambiguous.
- signingConfigs { release { ... } } relies on Groovy's container DSL
  sugar to create the "release" signing config, since none exists by
  default (unlike buildTypes, where "release" is a default AGP build
  type). Kotlin's getByName() requires it to already exist and throws;
  switched to create("release").
- AndroidComponentsExtension<*, *, *> (the generic base type) isn't
  registered as a project extension; only the concrete
  ApplicationAndroidComponentsExtension is, for application modules.

Verified end-to-end against a real Android SDK (not just a compile-only
smoke test): built a local copy of this build.gradle.kts into a Kotlin
DSL-converted checkout of DestinationSol (github.com/MovingBlocks/
DestinationSol/pull/737) and ran gradlew :android:compileDebugJavaWithJavac
successfully, in addition to :android:help configuring the full variant/
module-dexing task graph (androidComponents{}, per-module dex/export
tasks) without error.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Aug 23, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 94504c3d-7c15-4389-bae9-e177e5f29953


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant