@@ -52,6 +52,8 @@ import org.gradle.api.file.SourceDirectorySet
52
52
import org.gradle.api.plugins.AppliedPlugin
53
53
import org.gradle.api.provider.Provider
54
54
import org.gradle.api.tasks.SourceSet
55
+ import org.gradle.api.tasks.SourceSetContainer
56
+ import org.gradle.api.tasks.TaskProvider
55
57
import org.gradle.language.jvm.tasks.ProcessResources
56
58
import org.gradle.util.GradleVersion
57
59
@@ -237,10 +239,20 @@ class ProtobufPlugin implements Plugin<Project> {
237
239
Configuration compileProtoPath , Collection<Closure > postConfigure ) {
238
240
Provider<ProtobufExtract > extractProtosTask =
239
241
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
+
244
256
Provider<ProtobufExtract > extractIncludeProtosTask = setupExtractIncludeProtosTask(
245
257
sourceSet. name, compileProtoPath, sourceSet. compileClasspath)
246
258
Provider<GenerateProtoTask > generateProtoTask = addGenerateProtoTask(
0 commit comments