Upgrade to latest protobuf gradle plugin

- Update source jars to use a lazy api to retrieve source
  directories
- Use updated way to add protobuf generated code into sources

Test: ./gradlew bOS --dry-run
Change-Id: Ifcb540b44dfe73ba2efb195566997ac2d5342291
diff --git a/buildSrc/private/src/main/kotlin/androidx/build/SourceJarTaskHelper.kt b/buildSrc/private/src/main/kotlin/androidx/build/SourceJarTaskHelper.kt
index cca0bf6..8b2d56d 100644
--- a/buildSrc/private/src/main/kotlin/androidx/build/SourceJarTaskHelper.kt
+++ b/buildSrc/private/src/main/kotlin/androidx/build/SourceJarTaskHelper.kt
@@ -93,14 +93,14 @@
             // not to have "main".  Eventually, we should stop expecting to grab sourceSets by name
             // (b/235828421)
             extension.sourceSets.findByName("main")?.let {
-                task.from(it.allSource.srcDirs)
+                task.from(it.allSource.sourceDirectories)
             }
         }
 
         extensions.findByType(KotlinMultiplatformExtension::class.java)?.let { extension ->
             for (sourceSetName in listOf("commonMain", "jvmMain")) {
                 extension.sourceSets.findByName(sourceSetName)?.let { sourceSet ->
-                    task.from(sourceSet.kotlin.srcDirs)
+                    task.from(sourceSet.kotlin.sourceDirectories)
                 }
             }
         }
diff --git a/datastore/datastore-preferences-proto/build.gradle b/datastore/datastore-preferences-proto/build.gradle
index 32535ef..a958754 100644
--- a/datastore/datastore-preferences-proto/build.gradle
+++ b/datastore/datastore-preferences-proto/build.gradle
@@ -47,6 +47,15 @@
     }
 }
 
+afterEvaluate {
+    lint {
+        lintOptions {
+            // protobuf generates unannotated and synthetic accessor methods
+            disable("UnknownNullness", "SyntheticAccessor")
+        }
+    }
+}
+
 // Create export artifact for for JarJaring
 def preferencesProtoJarJarTask = tasks.register("exportJar", Jar) {
     archiveBaseName.set("export")
diff --git a/datastore/datastore-proto/build.gradle b/datastore/datastore-proto/build.gradle
index 7341958..c5f600c 100644
--- a/datastore/datastore-proto/build.gradle
+++ b/datastore/datastore-proto/build.gradle
@@ -40,9 +40,6 @@
     protoc {
         artifact = libs.protobufCompiler.get()
     }
-    // Generates the java proto-lite code for the protos in this project. See
-    // https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
-    // for more information.
     generateProtoTasks {
         all().each { task ->
             task.builtins {
@@ -65,4 +62,7 @@
 
 android {
     namespace "androidx.datastore.protodatastore"
+    lintOptions {
+        disable("SyntheticAccessor")
+    }
 }
diff --git a/glance/glance-appwidget-proto/build.gradle b/glance/glance-appwidget-proto/build.gradle
index ef4f144..3ab64a8 100644
--- a/glance/glance-appwidget-proto/build.gradle
+++ b/glance/glance-appwidget-proto/build.gradle
@@ -48,6 +48,15 @@
     }
 }
 
+afterEvaluate {
+    lint {
+        lintOptions {
+            // protobuf generates unannotated and synthetic accessor methods
+            disable("UnknownNullness", "SyntheticAccessor")
+        }
+    }
+}
+
 // Create export artifact for for JarJaring
 def preferencesProtoJarJarTask = tasks.register("exportJar", Jar) {
     archiveBaseName.set("export")
diff --git a/glance/glance-wear-tiles/build.gradle b/glance/glance-wear-tiles/build.gradle
index cd8d37f..7c09cd6 100644
--- a/glance/glance-wear-tiles/build.gradle
+++ b/glance/glance-wear-tiles/build.gradle
@@ -77,6 +77,8 @@
     lintOptions {
         // TODO(b/191286558): Remove when lint is fixed.
         disable "UnsafeOptInUsageError", "UnsafeOptInUsageWarning"
+        // protobuf generates unannotated methods
+        disable "UnknownNullness"
     }
 
     sourceSets {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 3c7aa7a..0c0c17b 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -203,7 +203,7 @@
 paparazziNativeMacOsX64 = { module = "app.cash.paparazzi:layoutlib-native-macosx", version.ref = "paparazziNative" }
 protobuf = { module = "com.google.protobuf:protobuf-java", version.ref = "protobuf" }
 protobufCompiler = { module = "com.google.protobuf:protoc", version.ref = "protobuf" }
-protobufGradlePluginz = { module = "com.google.protobuf:protobuf-gradle-plugin", version = "0.8.18" }
+protobufGradlePluginz = { module = "com.google.protobuf:protobuf-gradle-plugin", version = "0.9.0" }
 protobufLite = { module = "com.google.protobuf:protobuf-javalite", version.ref = "protobuf" }
 reactiveStreams = { module = "org.reactivestreams:reactive-streams", version = "1.0.0" }
 retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }
diff --git a/gradle/verification-metadata.xml b/gradle/verification-metadata.xml
index b700dd4..805dbeb 100644
--- a/gradle/verification-metadata.xml
+++ b/gradle/verification-metadata.xml
@@ -84,7 +84,10 @@
             <trusting group="io.reactivex.rxjava2"/>
             <trusting group="io.reactivex.rxjava3"/>
          </trusted-key>
-         <trusted-key id="1dbb44e80f61493d6369b5fb95c15058a5eda4f1" group="com.google.protobuf" name="protobuf-gradle-plugin"/>
+         <trusted-key id="1dbb44e80f61493d6369b5fb95c15058a5eda4f1">
+            <trusting group="com.google.protobuf" name="protobuf-gradle-plugin"/>
+            <trusting group="com.google.gradle"/>
+         </trusted-key>
          <trusted-key id="1f47744c9b6e14f2049c2857f1f111af65925306" group="io.github.classgraph" name="classgraph"/>
          <trusted-key id="1f8cf885d537a431" group="com.nhaarman.mockitokotlin2"/>
          <trusted-key id="1fa37fbe4453c1073e7ef61d6449005f96bc97a3" group="de.undercouch"/>
diff --git a/health/connect/connect-client-proto/build.gradle b/health/connect/connect-client-proto/build.gradle
index 507a245..79350e1 100644
--- a/health/connect/connect-client-proto/build.gradle
+++ b/health/connect/connect-client-proto/build.gradle
@@ -38,26 +38,11 @@
     protoc {
         artifact = libs.protobufCompiler.get()
     }
-
-    // Generates the java proto-lite code for the protos in this project. See
-    // https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
-    // for more information.
     generateProtoTasks {
+        ofSourceSet("main").each { task ->
+            sourceSets.main.java.srcDir(task)
+        }
         all().each { task ->
-            project.tasks.named("sourceJar").configure {
-                it.dependsOn(task)
-            }
-            project.tasks.named("runErrorProne").configure {
-                it.dependsOn(task)
-            }
-            project.tasks.named("lint").configure {
-                it.dependsOn(task)
-                it.enabled = false
-            }
-            project.tasks.named("lintAnalyze").configure {
-                it.dependsOn(task)
-                it.enabled = false
-            }
             task.builtins {
                 java {
                     option "lite"
@@ -67,6 +52,15 @@
     }
 }
 
+afterEvaluate {
+    lint {
+        lintOptions {
+            // protobuf generates unannotated and synthetic accessor methods
+            disable("UnknownNullness", "SyntheticAccessor")
+        }
+    }
+}
+
 // Create export artifact for for JarJaring
 def preferencesProtoJarJarTask = tasks.register("exportJar", Jar) {
     archiveBaseName.set("export")
diff --git a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt
index a5ff9d6..5ba8684 100644
--- a/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt
+++ b/inspection/inspection-gradle-plugin/src/main/kotlin/androidx/inspection/gradle/InspectionPlugin.kt
@@ -20,10 +20,8 @@
 import com.android.build.api.variant.Variant
 import com.android.build.gradle.LibraryExtension
 import com.google.protobuf.gradle.GenerateProtoTask
-import com.google.protobuf.gradle.ProtobufConvention
+import com.google.protobuf.gradle.ProtobufExtension
 import com.google.protobuf.gradle.ProtobufPlugin
-import com.google.protobuf.gradle.generateProtoTasks
-import com.google.protobuf.gradle.protoc
 import org.gradle.api.Plugin
 import org.gradle.api.Project
 import org.gradle.api.artifacts.Configuration
@@ -32,7 +30,6 @@
 import org.gradle.kotlin.dsl.apply
 import org.gradle.kotlin.dsl.create
 import org.gradle.kotlin.dsl.dependencies
-import org.gradle.kotlin.dsl.getPlugin
 import java.io.File
 import org.gradle.api.GradleException
 import org.gradle.api.artifacts.MinimalExternalModuleDependency
@@ -98,15 +95,13 @@
         project.apply(plugin = "com.google.protobuf")
         project.plugins.all {
             if (it is ProtobufPlugin) {
-                // https://github.com/google/protobuf-gradle-plugin/issues/505
-                @Suppress("DEPRECATION")
-                val protobufConvention = project.convention.getPlugin<ProtobufConvention>()
-                protobufConvention.protobuf.apply {
+                val protobufExtension = project.extensions.getByType(ProtobufExtension::class.java)
+                protobufExtension.apply {
                     protoc {
-                        this.artifact = project.getLibraryByName("protobufCompiler").toString()
+                        it.artifact = project.getLibraryByName("protobufCompiler").toString()
                     }
                     generateProtoTasks {
-                        all().forEach { task: GenerateProtoTask ->
+                        it.all().forEach { task: GenerateProtoTask ->
                             task.builtins.create("java") { options ->
                                 options.option("lite")
                             }
diff --git a/wear/tiles/tiles-proto/build.gradle b/wear/tiles/tiles-proto/build.gradle
index 90f691b..b2ebf91 100644
--- a/wear/tiles/tiles-proto/build.gradle
+++ b/wear/tiles/tiles-proto/build.gradle
@@ -80,25 +80,11 @@
         artifact = libs.protobufCompiler.get()
     }
 
-    // Generates the java proto-lite code for the protos in this project. See
-    // https://github.com/google/protobuf-gradle-plugin#customizing-protobuf-compilation
-    // for more information.
     generateProtoTasks {
+        ofSourceSet("main").each { task ->
+            sourceSets.main.java.srcDir(task)
+        }
         all().each { task ->
-            project.tasks.named("sourceJar").configure {
-                it.dependsOn(task)
-            }
-            project.tasks.named("runErrorProne").configure {
-                it.dependsOn(task)
-            }
-            project.tasks.named("lint").configure {
-                it.dependsOn(task)
-                it.enabled = false
-            }
-            project.tasks.named("lintAnalyze").configure {
-                it.dependsOn(task)
-                it.enabled = false
-            }
             task.builtins {
                 java {
                     option 'lite'
@@ -108,6 +94,15 @@
     }
 }
 
+afterEvaluate {
+    lint {
+        lintOptions {
+            // protobuf generates unannotated and synthetic accessor methods
+            disable("UnknownNullness", "SyntheticAccessor")
+        }
+    }
+}
+
 androidx {
     name = "Wear Tiles Proto"
     publish = Publish.SNAPSHOT_AND_RELEASE