From 527f584874fd935773817efd6866a0dcb491a524 Mon Sep 17 00:00:00 2001 From: Benoit Quenaudon Date: Tue, 29 Aug 2023 16:58:32 +0100 Subject: [PATCH] Adds warning when one defines a protoLibrary without source sets --- .../src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt index 87fdd70ffe..fb787feaa9 100644 --- a/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt +++ b/wire-gradle-plugin/src/main/kotlin/com/squareup/wire/gradle/WirePlugin.kt @@ -273,10 +273,15 @@ class WirePlugin : Plugin { if (extension.protoLibrary) { val sourceSets = project.extensions.getByType(SourceSetContainer::class.java) // Note that there are no source sets for some platforms such as native. - if (sourceSets.isNotEmpty()) { + // TODO(Benoit) Probably should be checking for other names than `main`. As well, source + // sets might be created 'afterEvaluate'. Does that mean we should do this work in + // `afterEvaluate` as well? See: https://kotlinlang.org/docs/multiplatform-dsl-reference.html#source-sets + if (sourceSets.findByName("main") != null) { sourceSets.getByName("main") { main: SourceSet -> main.resources.srcDir(protoOutputDirectory) } + } else { + project.logger.warn("${project.displayName} doesn't have a 'main' source sets. The .proto files will not automatically be added to the artifact.") } }