Skip to content

Commit 27df0ca

Browse files
bcorsoDagger Team
authored andcommitted
Update HiltGradlePlugin to AGP 9.
This required a number of changes: * Update Gradle 8.14.3 -> 9.2.0 * Update shadow plugin from `com.github.johnrengelman.shadow:8.1.1` to 'com.gradleup.shadow:9.2.2' (old artifact doesn't support Gradle 9). * Update HiltGradlePlugin to 9.0.0-beta02: * Migrate `BaseExtension` to `AndroidComponentsExtension` * Migrate `BaseVariant` to `Component` * Migrate `variant.javaCompileOutput.classpath` to `variant.compileClasspath` * Migrate `variant.javaCompileOutput.destinationDirectory` to `variant.artifacts.use(HiltCopyTask).toGet()` * Migrate `variant.javaCompileOutput.options.bootstrapClasspath` with `androidExtension.sdkComponents.bootClasspath` * Migrate `variant.javaCompileOutput.options.compilerArgumentProviders` with `variant.javaCompilation.annotationProcessor.argumentProviders` * `project.buildDir = ...` to `project.layout.buildDirectory.set(...)` * Update HiltGradlePlugin tests to use AGP 9.0.0-beta02: * Migrate to builtin kotlin * remove 'kotlin-android' * replace 'kotlin-kapt' with 'legacy-kapt' * Migrate javatests/artifacts/hilt-android/simple/app/build.gradle to kts and replace GradleVersion with custom AgpVersion. The GradleVersion does not work with APG versions like 9.0.0-beta02, so I had to do this with custom parsing. * remove `android.kotlinOptions` (removed in AGP 9) RELNOTES=N/A PiperOrigin-RevId: 837566667
1 parent 94ff5b7 commit 27df0ca

File tree

29 files changed

+390
-356
lines changed

29 files changed

+390
-356
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ concurrency:
1414
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
1515

1616
env:
17-
USE_AGP_VERSION: '8.13.0'
17+
USE_AGP_VERSION: '9.0.0-beta02'
1818
USE_JAVA_DISTRIBUTION: 'zulu'
1919
USE_JAVA_VERSION_FOR_BAZEL: '21'
2020
USE_JAVA_VERSION_FOR_GRADLE: '21'

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ concurrency:
1313
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}
1414

1515
env:
16-
USE_AGP_VERSION: '8.13.0'
16+
USE_AGP_VERSION: '9.0.0-beta02'
1717
USE_JAVA_DISTRIBUTION: 'zulu'
1818
USE_JAVA_VERSION_FOR_BAZEL: '21'
1919
USE_JAVA_VERSION_FOR_GRADLE: '21'

java/dagger/hilt/android/plugin/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
buildscript {
22
ext {
33
kotlin_version = "2.2.0"
4-
agp_version = System.getenv('AGP_VERSION')
4+
agp_version = System.getenv('AGP_VERSION') ?: "9.0.0-beta02"
55
ksp_version = "$kotlin_version-2.0.2"
66
pluginArtifactId = 'hilt-android-gradle-plugin'
77
pluginId = 'com.google.dagger.hilt.android'
@@ -12,7 +12,7 @@ plugins {
1212
id 'org.jetbrains.kotlin.jvm' version "$kotlin_version"
1313
id 'java-gradle-plugin'
1414
id 'maven-publish'
15-
id 'com.github.johnrengelman.shadow' version '8.1.1'
15+
id 'com.gradleup.shadow' version '9.2.2'
1616
id 'org.jetbrains.kotlin.android' version "$kotlin_version" apply false
1717
}
1818

@@ -24,10 +24,10 @@ allprojects {
2424
}
2525

2626
// Avoids conflict with BUILD file
27-
project.buildDir = 'buildOut'
27+
project.layout.buildDirectory.set(file('buildOut'))
2828

29-
subprojects {
30-
project.buildDir = 'buildOut'
29+
subprojects {subproject ->
30+
subproject.layout.buildDirectory.set(file('buildOut'))
3131
afterEvaluate {
3232
dependencies {
3333
// This is needed to align older versions of kotlin-stdlib.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.0-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

java/dagger/hilt/android/plugin/main/build.gradle

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,13 @@
1717
import dagger.hilt.android.plugin.task.ImportSharedLibTask
1818
import java.util.zip.ZipEntry
1919
import java.util.zip.ZipFile
20-
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
2120
import org.jetbrains.kotlin.gradle.dsl.KotlinVersion
2221

2322
plugins {
2423
id 'org.jetbrains.kotlin.jvm'
2524
id 'java-gradle-plugin'
2625
id 'maven-publish'
27-
id 'com.github.johnrengelman.shadow'
26+
id 'com.gradleup.shadow'
2827
}
2928

3029
configurations {
@@ -69,6 +68,7 @@ dependencies {
6968
// Use compile-only for other plugin dependencies to avoid brining those
7069
// to projects that don't use them.
7170
compileOnly "com.android.tools.build:gradle:$agp_version"
71+
compileOnly "com.android.legacy-kapt:com.android.legacy-kapt.gradle.plugin:$agp_version"
7272
compileOnly "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
7373
compileOnly "com.google.devtools.ksp:symbol-processing-gradle-plugin:$ksp_version"
7474

@@ -81,6 +81,7 @@ dependencies {
8181
testImplementation 'com.google.truth:truth:1.0.1'
8282
testImplementation 'org.javassist:javassist:3.26.0-GA'
8383
testPluginCompile "com.android.tools.build:gradle:$agp_version"
84+
testPluginCompile "com.android.legacy-kapt:com.android.legacy-kapt.gradle.plugin:$agp_version"
8485
testPluginCompile "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
8586
testPluginCompile "com.google.devtools.ksp:symbol-processing-gradle-plugin:$ksp_version"
8687
}
@@ -110,18 +111,19 @@ kotlin {
110111
tasks.register("importSharedLib", ImportSharedLibTask) {
111112
outputDir.set(file("${project.projectDir}/libs"))
112113
}
113-
tasks.getByName('compileKotlin').dependsOn('importSharedLib')
114+
tasks.named('compileKotlin').configure { it.dependsOn('importSharedLib') }
114115

115116
// Task that generates a top-level property containing the version of the
116117
// project so that it can be used in code and at runtime.
117-
def pluginVersionOutDir = file("$buildDir/generated/source/plugin-version/")
118+
def pluginVersionOutDir =
119+
project.layout.buildDirectory.map {file("$it/generated/source/plugin-version/") }
118120
tasks.register("generatePluginVersionSource").configure {
119121
def version = getPublishVersion()
120122
inputs.property('version', version)
121123
outputs.dir(pluginVersionOutDir)
122124
doLast {
123125
def versionFile =
124-
file("$pluginVersionOutDir/dagger/hilt/android/plugin/Version.kt")
126+
file("${pluginVersionOutDir.get()}/dagger/hilt/android/plugin/Version.kt")
125127
versionFile.parentFile.mkdirs()
126128
versionFile.text = """
127129
// Generated file. Do not edit!
@@ -132,14 +134,14 @@ tasks.register("generatePluginVersionSource").configure {
132134
}
133135
}
134136
sourceSets.main.java.srcDir pluginVersionOutDir
135-
tasks.getByName('compileKotlin').dependsOn('generatePluginVersionSource')
137+
tasks.named('compileKotlin').configure { it.dependsOn('generatePluginVersionSource') }
136138

137139
// Create sources Jar from main kotlin sources
138140
tasks.register("sourcesJar", Jar).configure {
139141
group = JavaBasePlugin.DOCUMENTATION_GROUP
140142
description = "Assembles sources JAR"
141143
archiveClassifier.set("sources")
142-
from(sourceSets["main"].allSource)
144+
from(sourceSets.named("main").map { it.allSource })
143145
dependsOn('generatePluginVersionSource')
144146
}
145147

@@ -153,7 +155,7 @@ tasks.register("javadocJar", Jar).configure {
153155
}
154156

155157
// Disable Gradle metadata publication.
156-
tasks.withType(GenerateModuleMetadata) {
158+
tasks.withType(GenerateModuleMetadata).configureEach {
157159
enabled = false
158160
}
159161

@@ -254,7 +256,7 @@ def getPublishVersion() {
254256
return (publishVersion != null) ? publishVersion : "LOCAL-SNAPSHOT"
255257
}
256258

257-
def checkJarFile(File jarFile, String... allowedPrefixes) {
259+
static def checkJarFile(File jarFile, String... allowedPrefixes) {
258260
def zip = new ZipFile(jarFile)
259261
try {
260262
Enumeration<ZipEntry> list = zip.entries()

0 commit comments

Comments
 (0)