Skip to content

Instantly share code, notes, and snippets.

@benigumocom
Last active August 26, 2024 17:08
Show Gist options
  • Save benigumocom/b5fa94749aef302fdb09089f6ba0dfc8 to your computer and use it in GitHub Desktop.
Save benigumocom/b5fa94749aef302fdb09089f6ba0dfc8 to your computer and use it in GitHub Desktop.
// Hilt + KSP
// build.gradle.kts (Project)
plugins {
id("com.google.devtools.ksp") version "1.8.10-1.0.9" apply false
id("com.google.dagger.hilt.android") version "2.44" apply false
}
// build.gradle.kts (Module)
plugins {
id("com.google.devtools.ksp")
id("com.google.dagger.hilt.android")
}
dependencies {
implementation("com.google.dagger:hilt-android:2.44")
ksp("com.google.dagger:hilt-android-compiler:2.44")
}
@C2R-C
Copy link

C2R-C commented Aug 26, 2024

I thank benigumocom very much for his great contribution. In a very respectful way I want to leave the following contribution for all of us who use the versions catalog.

In the file libs.versions.toml, section [versions], add hilt = "2.51" Taking into account that the version of kotlin would be in 2.0.20 and ksp in 2.0 .20-1.0.24.

In the [libraries] section register
google-hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" } and hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }

In the [plugins] section add hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }, ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } remaining as follows:

[versions]
... Other versions
kotlin = "2.0.20"
ksp = "2.0.20-1.0.24"
hilt = "2.51"

[libraries]
... Other libraries
google-hilt-android = { group = "com.google.dagger", name = "hilt-android", version.ref = "hilt" }
hilt-compiler = { group = "com.google.dagger", name = "hilt-compiler", version.ref = "hilt" }

[plugins]
... Other plugins
ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" }
hilt-android = { id = "com.google.dagger.hilt.android", version.ref = "hilt" }

In build.gradle.kts file at module level, It would look like this:

plugins {
    ...
    alias(libs.plugins.ksp)
    alias(libs.plugins.hilt.android)
}

android {
    .... android settings
}

ksp {
    arg("room.schemaLocation", "$projectDir/schemas")
}

dependencies {
    ... Other dependencies
    // Hilt
    implementation(libs.google.hilt.android)
    ksp(libs.hilt.compiler)
}

In the build.gradle.kts file at the project level, it would look like this:

plugins {
    ... Other plugins
    alias(libs.plugins.ksp) apply false
    alias(libs.plugins.hilt.android) apply false
}

That would be my contribution in a respectful way.

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