Skip to content

Commit

Permalink
Update to Hilt 2.48.1 and use the KSP version
Browse files Browse the repository at this point in the history
* Moved protobuf to separate module to avoid having to wire KSP's Plugin with the Protobuf Plugin.
* `@Binds` function cannot be an extension function.
* Commented `kotlin.compiler.execution.strategy=in-process` in CI to circumvent OOMs due to increased metaspace usage.
  • Loading branch information
danysantiago committed Nov 10, 2023
1 parent 5f5bd91 commit c908f98
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 40 deletions.
1 change: 0 additions & 1 deletion .github/ci-gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ org.gradle.parallel=true
org.gradle.workers.max=2

kotlin.incremental=false
kotlin.compiler.execution.strategy=in-process

# Controls KotlinOptions.allWarningsAsErrors.
# This value used in CI and is currently set to false.
Expand Down
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,6 @@ dependencies {
testImplementation(libs.accompanist.testharness)
testImplementation(libs.work.testing)
testImplementation(kotlin("test"))
kaptTest(libs.hilt.compiler)
kspTest(libs.hilt.compiler)

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ class AndroidHiltConventionPlugin : Plugin<Project> {
override fun apply(target: Project) {
with(target) {
with(pluginManager) {
apply("com.google.devtools.ksp")
apply("dagger.hilt.android.plugin")
// KAPT must go last to avoid build warnings.
// See: https://stackoverflow.com/questions/70550883/warning-the-following-options-were-not-recognized-by-any-processor-dagger-f
apply("org.jetbrains.kotlin.kapt")
}

dependencies {
"implementation"(libs.findLibrary("hilt.android").get())
"kapt"(libs.findLibrary("hilt.compiler").get())
"kaptAndroidTest"(libs.findLibrary("hilt.compiler").get())
"kaptTest"(libs.findLibrary("hilt.compiler").get())
"ksp"(libs.findLibrary("hilt.compiler").get())
"kspAndroidTest"(libs.findLibrary("hilt.compiler").get())
"kspTest"(libs.findLibrary("hilt.compiler").get())
}

}
Expand Down
55 changes: 55 additions & 0 deletions core/datastore-proto/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2023 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.protobuf)
}

android {
namespace = "com.google.samples.apps.nowinandroid.core.datastore.proto"
}

// Setup protobuf configuration, generating lite Java and Kotlin classes
protobuf {
protoc {
artifact = libs.protobuf.protoc.get().toString()
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
register("java") {
option("lite")
}
register("kotlin") {
option("lite")
}
}
}
}
}

androidComponents.beforeVariants {
android.sourceSets.register(it.name) {
val buildDir = layout.buildDirectory.get().asFile
java.srcDir(buildDir.resolve("generated/source/proto/${it.name}/java"))
kotlin.srcDir(buildDir.resolve("generated/source/proto/${it.name}/kotlin"))
}
}

dependencies {
implementation(libs.protobuf.kotlin.lite)
}
29 changes: 1 addition & 28 deletions core/datastore/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.library.jacoco)
alias(libs.plugins.nowinandroid.android.hilt)
alias(libs.plugins.protobuf)
}

android {
Expand All @@ -33,34 +32,8 @@ android {
}
}

// Setup protobuf configuration, generating lite Java and Kotlin classes
protobuf {
protoc {
artifact = libs.protobuf.protoc.get().toString()
}
generateProtoTasks {
all().forEach { task ->
task.builtins {
register("java") {
option("lite")
}
register("kotlin") {
option("lite")
}
}
}
}
}

androidComponents.beforeVariants {
android.sourceSets.register(it.name) {
val buildDir = layout.buildDirectory.get().asFile
java.srcDir(buildDir.resolve("generated/source/proto/${it.name}/java"))
kotlin.srcDir(buildDir.resolve("generated/source/proto/${it.name}/kotlin"))
}
}

dependencies {
api(projects.core.datastoreProto)
implementation(projects.core.common)
implementation(projects.core.model)
implementation(libs.androidx.dataStore.core)
Expand Down
4 changes: 2 additions & 2 deletions core/domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
plugins {
alias(libs.plugins.nowinandroid.android.library)
alias(libs.plugins.nowinandroid.android.library.jacoco)
kotlin("kapt")
id("com.google.devtools.ksp")
}

android {
Expand All @@ -30,7 +30,7 @@ dependencies {
implementation(libs.kotlinx.coroutines.android)
implementation(libs.kotlinx.datetime)

kapt(libs.hilt.compiler)
ksp(libs.hilt.compiler)

testImplementation(projects.core.testing)
}
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ gmsPlugin = "4.4.0"
googleOss = "17.0.1"
googleOssPlugin = "0.10.6"
hilt = "2.48.1"
hiltExt = "1.0.0"
hiltExt = "1.1.0"
jacoco = "0.8.7"
junit4 = "4.13.2"
kotlin = "1.9.10"
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ include(":core:data")
include(":core:data-test")
include(":core:database")
include(":core:datastore")
include(":core:datastore-proto")
include(":core:datastore-test")
include(":core:designsystem")
include(":core:domain")
Expand Down
2 changes: 1 addition & 1 deletion sync/work/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ dependencies {

prodImplementation(libs.firebase.cloud.messaging)

kapt(libs.hilt.ext.compiler)
ksp(libs.hilt.ext.compiler)

testImplementation(projects.core.testing)

Expand Down

0 comments on commit c908f98

Please sign in to comment.