build: convert build.gradle from Groovy to Kotlin DSL - #36
Open
soloturn wants to merge 1 commit into
Open
Conversation
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>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.applicationis applied viaapply(plugin = ...)rather than theplugins{}block (its version comes from the buildscript classpath, not the plugin portal), so the type-safeandroid{}accessor is never generated. Configured the extension explicitly viaconfigure<ApplicationExtension>{}instead — and specifically the moderncom.android.build.api.dsl.ApplicationExtension, not the legacycom.android.build.gradle.AppExtension: AGP 9.x defaults toandroid.newDsl=true, under which only the modern extension gets registered as a project extension at all.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()→ thedirectoriesmutable set,packagingOptions{}→packaging{}, its top-levelexcludes/merges/pickFirsts→ nested underresources.,lintOptions{}'sisAbortOnError→lint{}'sabortOnError, and the group/name/version dependency notation → single-string notation.defaultConfig{}/android{}, bare references tocompileSdk/minSdk/targetSdkresolve to those DSL blocks' own (nullable, initially-unset) same-named properties rather than this script's top-levelvals 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 tocompileSdkNumber/minSdkNumber/targetSdkNumberto make the two unambiguous.signingConfigs { release { ... } }relies on Groovy's container DSL sugar to create the "release" signing config, since none exists by default (unlikebuildTypes, where "release" is a default AGP build type). Kotlin'sgetByName()requires it to already exist and throws; switched tocreate("release").AndroidComponentsExtension<*, *, *>(the generic base type) isn't registered as a project extension; only the concreteApplicationAndroidComponentsExtensionis, 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.ktsinto a Kotlin DSL-converted checkout of DestinationSol (MovingBlocks/DestinationSol#737) and rangradlew :android:compileDebugJavaWithJavacsuccessfully, in addition to:android:helpconfiguring the full variant/module-dexing task graph (androidComponents{}, per-module dex/export tasks) without error.