-
-
Notifications
You must be signed in to change notification settings - Fork 68
Migrate to Gradle KTS and Version Catalogs #122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ImaginativeShohag
wants to merge
1
commit into
dev
Choose a base branch
from
feat/gradle-kts-version-catalog
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * Copyright © 2025 Md. Mahmudul Hasan Shohag. All rights reserved. | ||
| */ | ||
|
|
||
|
|
||
| import org.jetbrains.dokka.gradle.DokkaMultiModuleTask // Keep this import | ||
|
|
||
| // Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
|
||
| plugins { | ||
| alias(libs.plugins.android.application) apply false | ||
| alias(libs.plugins.android.library) apply false | ||
| alias(libs.plugins.kotlin.android) apply false | ||
| alias(libs.plugins.ksp) apply false | ||
| alias(libs.plugins.spotless) | ||
| alias(libs.plugins.dokka) | ||
| } | ||
|
|
||
| // Configure Spotless for the root project (e.g., build.gradle.kts, settings.gradle.kts) | ||
| configure<com.diffplug.gradle.spotless.SpotlessExtension> { | ||
| // Optional: If you want to use the same ktlint version across kotlin and kotlinGradle | ||
| // val ktlintVersion = libs.versions.ktlint.get() // Assuming you add ktlint version to toml | ||
|
|
||
| kotlinGradle { | ||
| target("*.gradle.kts", "settings.gradle.kts") // Target root .gradle.kts files and settings.gradle.kts | ||
| targetExclude("**/build/**/*.kts", "build-logic/**/*.gradle.kts") // Exclude build dir & build-logic | ||
| ktlint() // .editorconfig() can be added if you have one at the root | ||
| licenseHeaderFile(rootProject.file("spotless/copyright.kts"), """(^(?![\\/ ]\\*).*$)""") // Regex for KTS license | ||
| } | ||
|
|
||
| // You might still want a general kotlin format for any .kt files directly in the root, if any. | ||
| // kotlin { | ||
| // target("*.kt") | ||
| // ktlint() | ||
| // licenseHeaderFile(rootProject.file("spotless/copyright.kt")) | ||
| // } | ||
| } | ||
|
|
||
| subprojects { | ||
| // Apply Spotless plugin to each subproject. | ||
| // The plugin's version is managed via the root project's plugins block. | ||
| apply(plugin = "com.diffplug.spotless") | ||
|
|
||
| // Configure Spotless for each subproject | ||
| configure<com.diffplug.gradle.spotless.SpotlessExtension> { | ||
| kotlin { | ||
| target("**/*.kt") | ||
| targetExclude("${layout.buildDirectory.get()}/**/*.kt", "bin/**/*.kt") | ||
| ktlint() | ||
| licenseHeaderFile(rootProject.file("spotless/copyright.kt")) | ||
| } | ||
| kotlinGradle { | ||
| target("build.gradle.kts") // Target build.gradle.kts in each subproject | ||
| ktlint() | ||
| licenseHeaderFile(rootProject.file("spotless/copyright.kts"), """(^(?![\\/ ]\\*).*$)""") | ||
| } | ||
| // Removed problematic format("kts") block. build.gradle.kts for subprojects will be handled by kotlinGradle. | ||
| format("xml") { | ||
| target("**/*.xml") | ||
| targetExclude("**/build/**/*.xml") | ||
| licenseHeaderFile(rootProject.file("spotless/copyright.xml"), "(<[^!?])") | ||
| } | ||
| } | ||
| } | ||
|
|
||
| tasks.withType<DokkaMultiModuleTask>().configureEach { | ||
| moduleName.set("Why Not! Image Carousel!") | ||
| outputDirectory.set(rootProject.file("docs/api")) | ||
| failOnWarning.set(true) | ||
|
|
||
| // dokkaPlugins is the modern way, but pluginsMapConfiguration might still work. | ||
| // If issues arise, this is an area to check. | ||
| // For now, keeping it similar to the original: | ||
| pluginsMapConfiguration.set( | ||
| mapOf( | ||
| "org.jetbrains.dokka.base.DokkaBase" to """{ | ||
| "footerMessage": "Copyright © 2021 Md. Mahmudul Hasan Shohag" | ||
| }""", | ||
| ), | ||
| ) | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| # This file defines the versions, libraries, and plugins used by the project. | ||
| # For more information, see: https://docs.gradle.org/current/userguide/platforms.html#sub:version-catalog-format | ||
|
|
||
| [versions] | ||
| agp = "8.10.1" | ||
| kotlin = "2.1.21" | ||
| ksp = "2.1.21-2.0.2" # Note: KSP version is often tightly coupled with Kotlin version | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| dokka = "2.0.0" | ||
| spotless = "7.0.4" | ||
| mavenPublish = "0.33.0" # Updated to latest version | ||
|
|
||
| # Android SDK versions | ||
| compileSdk = "36" | ||
| minSdk = "21" | ||
| targetSdk = "36" | ||
|
Comment on lines
+13
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| javaVersion = "17" | ||
|
|
||
| # Build tools / Linters | ||
| ktlintVersion = "0.45.2" # Bundled with Spotless 7.0.4 | ||
|
|
||
| # Dependencies | ||
| junit = "4.13.2" | ||
| androidxTestCore = "1.6.1" | ||
| androidxTestExtJunit = "1.2.1" | ||
| androidxTestRunner = "1.6.2" | ||
| androidxTestRules = "1.6.1" | ||
| androidxEspressoCore = "3.6.1" | ||
| # androidxEspressoIntents uses the same version as androidxEspressoCore | ||
| androidxAppcompat = "1.7.1" | ||
| androidxCoreKtx = "1.16.0" | ||
| androidxConstraintlayout = "2.2.1" | ||
| material = "1.12.0" | ||
| circleindicator = "2.1.6" | ||
| glide = "4.16.0" | ||
| androidxFragmentKtx = "1.8.8" | ||
| leakcanary = "2.14" | ||
| androidxRecyclerview = "1.4.0" | ||
|
|
||
|
|
||
| [libraries] | ||
| # Kotlin | ||
| kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" } | ||
|
|
||
| # AndroidX Test | ||
| androidx-test-coreKtx = { group = "androidx.test", name = "core-ktx", version.ref = "androidxTestCore" } | ||
| androidx-test-ext-junit = { group = "androidx.test.ext", name = "junit", version.ref = "androidxTestExtJunit" } | ||
| androidx-test-runner = { group = "androidx.test", name = "runner", version.ref = "androidxTestRunner" } | ||
| androidx-test-rules = { group = "androidx.test", name = "rules", version.ref = "androidxTestRules" } | ||
| androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "androidxEspressoCore" } | ||
| androidx-espresso-intents = { group = "androidx.test.espresso", name = "espresso-intents", version.ref = "androidxEspressoCore" } | ||
|
|
||
| # AndroidX UI & Core | ||
| androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version.ref = "androidxAppcompat" } | ||
| androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "androidxCoreKtx" } | ||
| androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "androidxConstraintlayout" } | ||
| androidx-fragment-ktx = { group = "androidx.fragment", name = "fragment-ktx", version.ref = "androidxFragmentKtx" } | ||
| androidx-recyclerview = { group = "androidx.recyclerview", name = "recyclerview", version.ref = "androidxRecyclerview" } | ||
|
|
||
| material = { group = "com.google.android.material", name = "material", version.ref = "material" } | ||
|
|
||
| # Third-party | ||
| circleindicator = { group = "me.relex", name = "circleindicator", version.ref = "circleindicator" } | ||
| glide = { group = "com.github.bumptech.glide", name = "glide", version.ref = "glide" } | ||
| leakcanary-android = { group = "com.squareup.leakcanary", name = "leakcanary-android", version.ref = "leakcanary" } | ||
| junit = { group = "junit", name = "junit", version.ref = "junit" } | ||
|
|
||
|
|
||
| [plugins] | ||
| android-application = { id = "com.android.application", version.ref = "agp" } | ||
| android-library = { id = "com.android.library", version.ref = "agp" } | ||
| kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } | ||
| ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } | ||
| spotless = { id = "com.diffplug.spotless", version.ref = "spotless" } | ||
| dokka = { id = "org.jetbrains.dokka", version.ref = "dokka" } | ||
| mavenPublish = { id = "com.vanniktech.maven.publish", version.ref = "mavenPublish" } | ||
|
|
||
| [bundles] | ||
| # Example: androidx-test-implementations = ["androidx-test-core", "androidx-test-ext-junit", ...] | ||
| # Can be added later if useful. | ||
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider centralizing the copyright year in
gradle.propertiesand referencing it here for consistency.