-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathbuild.gradle.kts
More file actions
228 lines (204 loc) · 9.04 KB
/
Copy pathbuild.gradle.kts
File metadata and controls
228 lines (204 loc) · 9.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/*
* Copyright 2026 Google LLC
*
* 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
*
* http://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 {
// Define plugins but do not apply them to the root project
alias(libs.plugins.dokka)
kotlin("jvm") version "2.3.21" apply false
kotlin("multiplatform") version "2.3.21" apply false
id("com.android.library") version "9.3.1" apply false
id("com.android.application") version "9.3.1" apply false
id("com.android.kotlin.multiplatform.library") version "9.3.1" apply false
id("com.google.cloud.artifactregistry.gradle-plugin") version "2.2.4" apply false
kotlin("plugin.serialization") version "2.3.21" apply false
alias(libs.plugins.gradle.test.retry) apply false
alias(libs.plugins.google.services) apply false
// Compose compiler plugin, pinned to AGP's built-in Kotlin version (see examples/android).
alias(libs.plugins.compose.compiler) apply false
}
val jdkVersion = providers.gradleProperty("jdkVersion").getOrElse("17").toInt()
// Kotlin language and API level for emitted metadata/bytecode. Pinned below the
// compiler version so published artifacts stay consumable by projects on this
// Kotlin version and downstream apps aren't forced to upgrade.
val kotlinCompatVersion = org.jetbrains.kotlin.gradle.dsl.KotlinVersion.KOTLIN_2_1
// kotlin-stdlib version the Kotlin plugin adds and publishes transitively. Pinned
// to a 2.1 release so its metadata stays readable by consumers on the Kotlin 2.1
// compiler; without this the 2.3 compiler would leak a 2.3 stdlib into the POMs
// and break the kotlinCompatVersion promise above.
val kotlinCoreLibrariesVersion = "2.1.20"
// API 36: stable androidx.appsearch requires minCompileSdk=36 (minSdk unchanged).
val androidCompileSdk = providers.gradleProperty("androidCompileSdk").getOrElse("36").toInt()
val androidMinSdk = providers.gradleProperty("androidMinSdk").getOrElse("26").toInt()
// Expose the resolved Android SDK levels so subproject build scripts can reuse
// them as a single source of truth (e.g. `core` sets `targetSdk` from this).
extra["androidCompileSdk"] = androidCompileSdk
extra["androidMinSdk"] = androidMinSdk
// Shared so Android modules on AGP's built-in Kotlin (which don't apply the
// kotlin.jvm/multiplatform plugins configured below) can reuse the same pin.
extra["kotlinCoreLibrariesVersion"] = kotlinCoreLibrariesVersion
allprojects {
group = "com.google.adk"
version = "0.7.1-SNAPSHOT" // x-release-please-version
repositories {
mavenLocal()
mavenCentral()
google()
}
}
subprojects {
apply(plugin = "org.jetbrains.dokka")
plugins.withId("org.jetbrains.kotlin.jvm") {
configure<org.jetbrains.kotlin.gradle.dsl.KotlinJvmProjectExtension> {
jvmToolchain(jdkVersion)
coreLibrariesVersion = kotlinCoreLibrariesVersion
}
}
plugins.withId("org.jetbrains.kotlin.multiplatform") {
configure<org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension> {
jvmToolchain(jdkVersion)
coreLibrariesVersion = kotlinCoreLibrariesVersion
}
}
// AGP built-in Kotlin: the Android modules no longer apply kotlin-android, so
// pin the Java/Kotlin target via `compileOptions` (Kotlin's jvmTarget follows
// `targetCompatibility`).
val androidJavaVersion = JavaVersion.toVersion(jdkVersion)
plugins.withId("com.android.library") {
configure<com.android.build.api.dsl.LibraryExtension> {
compileSdk = androidCompileSdk
defaultConfig { minSdk = androidMinSdk }
compileOptions {
sourceCompatibility = androidJavaVersion
targetCompatibility = androidJavaVersion
}
packaging {
resources {
merges += "**/META-INF/INDEX.LIST"
merges += "**/META-INF/DEPENDENCIES"
}
}
}
}
plugins.withId("com.android.application") {
configure<com.android.build.api.dsl.ApplicationExtension> {
compileOptions {
sourceCompatibility = androidJavaVersion
targetCompatibility = androidJavaVersion
}
}
}
// Conscrypt, which Robolectric pulls in, calls System::load, which JDK 24 restricts (JEP 472).
// Keyed off the JVM that runs the tests, not the jdkVersion property, because the Android
// modules apply no Kotlin toolchain. The flag is not needed below 24.
tasks.withType<Test>().configureEach {
val launcher = javaLauncher
jvmArgumentProviders.add(
CommandLineArgumentProvider {
if (launcher.get().metadata.languageVersion.asInt() >= 24) {
listOf("--enable-native-access=ALL-UNNAMED")
} else {
emptyList()
}
}
)
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompilationTask<*>>().configureEach {
compilerOptions {
optIn.add("kotlin.time.ExperimentalTime")
// `explicitNulls` in adkJson and `@EncodeDefault` on FunctionCall / FunctionResponse are
// experimental, and the timing tests read `currentTime`.
optIn.add("kotlinx.serialization.ExperimentalSerializationApi")
optIn.add("kotlinx.coroutines.ExperimentalCoroutinesApi")
freeCompilerArgs.add("-Xskip-metadata-version-check")
// `expect`/`actual` classes are Beta (KT-61573); GoogleCredentials relies on them.
freeCompilerArgs.add("-Xexpect-actual-classes")
// Compile with the current Kotlin toolchain but emit metadata/bytecode
// for kotlinCompatVersion so downstream consumers aren't forced to upgrade.
languageVersion.set(kotlinCompatVersion)
apiVersion.set(kotlinCompatVersion)
}
}
// Publishing is configured once here for any subproject that applies
// Gradle's built-in `maven-publish` plugin. Per-module build files set the
// `artifactId` on the publications the Kotlin / Android plugins auto-create
// (see core/, a2a/, firebase/, processor/, webserver/). POM metadata,
// Dokka-fed javadoc jars, and GPG signing are configured centrally here.
plugins.withId("maven-publish") {
apply(plugin = "signing")
// Single Dokka-backed `-javadoc.jar`, attached to every JVM/KMP
// publication this project produces. AGP's Android single-variant
// publication (the firebase module) ships its own javadoc jar via
// `withJavadocJar()`; we skip the Dokka one there to avoid a
// duplicate-artifact error at publish time.
val dokkaJavadocJar =
tasks.register<Jar>("dokkaJavadocJar") {
archiveClassifier.set("javadoc")
from(tasks.named("dokkaGeneratePublicationHtml"))
}
configure<PublishingExtension> {
publications.withType<MavenPublication>().configureEach {
if (name != "release") {
artifact(dokkaJavadocJar)
}
pom {
name.set("Google Agent Development Kit")
description.set("Google Agent Development Kit (ADK) for Kotlin")
url.set("https://github.com/google/adk-kotlin")
licenses {
license {
name.set("The Apache License, Version 2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0")
}
}
developers {
developer {
organization.set("Google Inc.")
organizationUrl.set("https://www.google.com")
}
}
scm {
connection.set("scm:git:git@github.com:google/adk-kotlin.git")
developerConnection.set("scm:git:git@github.com:google/adk-kotlin.git")
url.set("https://github.com/google/adk-kotlin")
}
}
}
}
configure<SigningExtension> {
val signingKey: String? = providers.gradleProperty("signingInMemoryKey").orNull
val signingKeyId: String? = providers.gradleProperty("signingInMemoryKeyId").orNull
val signingPassword: String? = providers.gradleProperty("signingInMemoryKeyPassword").orNull
if (signingKey != null) {
if (signingKeyId != null) {
useInMemoryPgpKeys(signingKeyId, signingKey, signingPassword)
} else {
useInMemoryPgpKeys(signingKey, signingPassword)
}
sign(extensions.getByType<PublishingExtension>().publications)
}
}
// Work around a known Gradle quirk where Kotlin Multiplatform creates
// multiple publications per project but Gradle's task graph does not
// automatically wire each `publishXxxPublicationTo...` task to its
// corresponding `signXxxPublication`. Without this, parallel publish
// tasks observe each other's unsigned artifacts and Gradle errors out
// with an "implicit dependency" validation problem. See
// https://github.com/gradle/gradle/issues/26091
tasks.withType<AbstractPublishToMaven>().configureEach {
val signingTasks = tasks.withType<Sign>()
mustRunAfter(signingTasks)
}
}
}