From 2892688f79146476e421220ee84681296e99fb36 Mon Sep 17 00:00:00 2001 From: rougsig Date: Mon, 27 Jun 2022 22:48:40 +0300 Subject: [PATCH] Add AndroidSourceSet.proto extension for agp 7+ More details can be found here: https://github.com/google/protobuf-gradle-plugin/issues/540 --- .../gradle/ProtobufConfiguratorExts.kt | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt b/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt index 7270b672..08824f06 100644 --- a/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt +++ b/src/main/kotlin/com/google/protobuf/gradle/ProtobufConfiguratorExts.kt @@ -1,6 +1,7 @@ package com.google.protobuf.gradle -import com.android.build.gradle.api.AndroidSourceSet +import com.android.build.api.dsl.AndroidSourceSet +import com.android.build.gradle.api.AndroidSourceSet as DeprecatedAndroidSourceSet import org.gradle.api.NamedDomainObjectContainer import org.gradle.api.Project import org.gradle.api.file.SourceDirectorySet @@ -64,7 +65,7 @@ fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) { /** * Applies the supplied action to the "proto" [SourceDirectorySet] extension on - * a receiver of type [AndroidSourceSet] for Android builds. + * a receiver of type [DeprecatedAndroidSourceSet] for Android builds. * * @since 0.8.15 * @usage @@ -80,6 +81,38 @@ fun SourceSet.proto(action: SourceDirectorySet.() -> Unit) { * } * ``` * + * @receiver [DeprecatedAndroidSourceSet] The Android source set for which the "proto" + * [SourceDirectorySet] extension will be configured + * + * @param action A configuration lambda to apply on a receiver of type [SourceDirectorySet] + * @return [Unit] + */ +fun DeprecatedAndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) { + (this as? ExtensionAware) + ?.extensions + ?.getByName("proto") + ?.let { it as? SourceDirectorySet } + ?.apply(action) +} + +/** + * Applies the supplied action to the "proto" [SourceDirectorySet] extension on + * a receiver of type [AndroidSourceSet] for Android builds. + * + * @since 0.8.19 + * @usage + * ``` + * android { + * sourceSets { + * create("sample") { + * proto { + * srcDir("src/sample/protobuf") + * } + * } + * } + * } + * ``` + * * @receiver [AndroidSourceSet] The Android source set for which the "proto" * [SourceDirectorySet] extension will be configured * @@ -90,7 +123,7 @@ fun AndroidSourceSet.proto(action: SourceDirectorySet.() -> Unit) { (this as? ExtensionAware) ?.extensions ?.getByName("proto") - ?.let { it as? SourceDirectorySet } + ?.let { it as? SourceDirectorySet } ?.apply(action) }