Skip to content

Commit

Permalink
Add dagger-spi as a Gradle project
Browse files Browse the repository at this point in the history
Also align Java project extension JVM target with Kotlin's in the JVM convention plugin and move explicit API config to the runtime project only.

RELNOTES=N/A
PiperOrigin-RevId: 715355555
  • Loading branch information
danysantiago authored and Dagger Team committed Jan 14, 2025
1 parent f115081 commit 9abeba7
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

package dagger.gradle.build

import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
Expand All @@ -30,7 +32,6 @@ class KotlinJvmConventionPlugin : Plugin<Project> {

project.plugins.withId(project.getPluginIdByName("kotlinJvm")) {
val kotlinProject = project.extensions.getByName("kotlin") as KotlinJvmProjectExtension
kotlinProject.explicitApi()
kotlinProject.jvmToolchain {
languageVersion.set(JavaLanguageVersion.of(project.getVersionByName("jdk")))
}
Expand All @@ -39,6 +40,10 @@ class KotlinJvmConventionPlugin : Plugin<Project> {
apiVersion.set(KotlinVersion.fromVersion(project.getVersionByName("kotlinTarget")))
jvmTarget.set(JvmTarget.fromTarget(project.getVersionByName("jvmTarget")))
}

val javaProject = project.extensions.getByName("java") as JavaPluginExtension
javaProject.sourceCompatibility = JavaVersion.toVersion(project.getVersionByName("jvmTarget"))
javaProject.targetCompatibility = JavaVersion.toVersion(project.getVersionByName("jvmTarget"))
}
}
}
4 changes: 4 additions & 0 deletions gradle-projects/dagger-runtime/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,8 @@ dependencies {
testImplementation(libs.junit)
testImplementation(libs.truth)
testImplementation(libs.guava.jre)
}

kotlin {
explicitApi()
}
32 changes: 32 additions & 0 deletions gradle-projects/dagger-spi/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import dagger.gradle.build.daggerSources

plugins {
alias(libs.plugins.dagger.kotlinJvm)
alias(libs.plugins.dagger.publish)
}

daggerSources {
main.setPackages(
listOf(
"dagger/internal/codegen/extension",
"dagger/model",
"dagger/spi",
"dagger/spi/model",
)
)
}

// TODO(danysantiago): Shadow / jarjar: 1. xprocessing, 2. auto-common and 3. kotlin-metadata-jvm
dependencies {
implementation(project(":dagger"))

implementation(libs.auto.common)
implementation(libs.auto.value.annotations)
annotationProcessor(libs.auto.value.compiler)
implementation(libs.findBugs)
implementation(libs.javaPoet)
implementation(libs.javax.inject)
implementation(libs.guava.failureAccess)
implementation(libs.guava.jre)
implementation(libs.ksp.api)
}
11 changes: 10 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,21 +1,30 @@
[versions]
autoValue = "1.9"
guava = "33.0.0-jre"
jdk = "18"
junit = "4.13"
jvmTarget = "1.8"
kotlin = "2.0.21"
kotlinTarget = "1.9"
ksp = "2.0.21-1.0.28"
publish = "0.30.0"
truth = "1.4.0"

[libraries]
auto-common = { module = "com.google.auto:auto-common", version = "1.2.1" }
auto-value-annotations = { module = "com.google.auto.value:auto-value-annotations", version.ref = "autoValue" }
auto-value-compiler = { module = "com.google.auto.value:auto-value", version.ref = "autoValue" }
findBugs = { module = "com.google.code.findbugs:jsr305", version = "3.0.1" }
guava-jre = { module = "com.google.guava:guava", version.ref = "guava" }
guava-failureAccess = { module = "com.google.guava:failureaccess", version = "1.0.1" }
jakarta-inject = { module = "jakarta.inject:jakarta.inject-api", version = "2.0.1" }
javaPoet = { module = "com.squareup:javapoet", version = "1.13.0" }
javax-inject = { module = "javax.inject:javax.inject", version = "1" }
jspecify = { module = "org.jspecify:jspecify", version = "1.0.0" }
junit = { module = "junit:junit", version.ref = "junit" }
kotlin-gradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" }
kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib", version.ref = "kotlin" }
ksp-api = { module = "com.google.devtools.ksp:symbol-processing-api", version.ref = "ksp" }
publishPlugin = { module = "com.vanniktech:gradle-maven-publish-plugin", version.ref = "publish" }
truth = { module = "com.google.truth:truth", version.ref = "truth" }

Expand All @@ -24,4 +33,4 @@ binaryCompatibilityValidator = { id = "org.jetbrains.kotlinx.binary-compatibilit
dagger-kotlinJvm = { id = "dagger.gradle.build.jvm" }
dagger-publish = { id = "dagger.gradle.build.publish" }
kotlinJvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
publish = { id = "com.vanniktech.maven.publish", version.ref = "publish" }
publish = { id = "com.vanniktech.maven.publish", version.ref = "publish" }
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ fun includeProject(name: String, path: String) {
}

includeProject(":dagger", "gradle-projects/dagger-runtime")
includeProject(":dagger-spi", "gradle-projects/dagger-spi")

0 comments on commit 9abeba7

Please sign in to comment.