Skip to content

Commit 1fe953a

Browse files
committed
Do not use compileClasspath as source of proto files
1 parent e20df5b commit 1fe953a

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy

+16-4
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ import org.gradle.api.file.SourceDirectorySet
5252
import org.gradle.api.plugins.AppliedPlugin
5353
import org.gradle.api.provider.Provider
5454
import org.gradle.api.tasks.SourceSet
55+
import org.gradle.api.tasks.SourceSetContainer
56+
import org.gradle.api.tasks.TaskProvider
5557
import org.gradle.language.jvm.tasks.ProcessResources
5658
import org.gradle.util.GradleVersion
5759

@@ -237,10 +239,20 @@ class ProtobufPlugin implements Plugin<Project> {
237239
Configuration compileProtoPath, Collection<Closure> postConfigure) {
238240
Provider<ProtobufExtract> extractProtosTask =
239241
setupExtractProtosTask(sourceSet.name, protobufConfig)
240-
// In Java projects, the compileClasspath of the 'test' sourceSet includes all the
241-
// 'resources' of the output of 'main', in which the source protos are placed. This is
242-
// nicer than the ad-hoc solution that Android has, because it works for any extended
243-
// configuration, not just 'testCompile'.
242+
243+
// Pass include proto files from main to test.
244+
// Process resource task contains all source proto files from a proto source set.
245+
FileCollection testClassPathConfig = project.objects.fileCollection()
246+
if (Utils.isTest(sourceSet.name)) {
247+
TaskProvider<ProcessResources> mainProcessResources = project.tasks.named(
248+
project.extensions.getByType(SourceSetContainer)
249+
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
250+
.processResourcesTaskName,
251+
ProcessResources
252+
)
253+
testClassPathConfig.from(mainProcessResources)
254+
}
255+
244256
Provider<ProtobufExtract> extractIncludeProtosTask = setupExtractIncludeProtosTask(
245257
sourceSet.name, compileProtoPath, sourceSet.compileClasspath)
246258
Provider<GenerateProtoTask> generateProtoTask = addGenerateProtoTask(

0 commit comments

Comments
 (0)