Skip to content

Commit

Permalink
Do not use compileClasspath as source of proto files
Browse files Browse the repository at this point in the history
  • Loading branch information
rougsig committed Oct 27, 2022
1 parent e20df5b commit 1fe953a
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ import org.gradle.api.file.SourceDirectorySet
import org.gradle.api.plugins.AppliedPlugin
import org.gradle.api.provider.Provider
import org.gradle.api.tasks.SourceSet
import org.gradle.api.tasks.SourceSetContainer
import org.gradle.api.tasks.TaskProvider
import org.gradle.language.jvm.tasks.ProcessResources
import org.gradle.util.GradleVersion

Expand Down Expand Up @@ -237,10 +239,20 @@ class ProtobufPlugin implements Plugin<Project> {
Configuration compileProtoPath, Collection<Closure> postConfigure) {
Provider<ProtobufExtract> extractProtosTask =
setupExtractProtosTask(sourceSet.name, protobufConfig)
// In Java projects, the compileClasspath of the 'test' sourceSet includes all the
// 'resources' of the output of 'main', in which the source protos are placed. This is
// nicer than the ad-hoc solution that Android has, because it works for any extended
// configuration, not just 'testCompile'.

// Pass include proto files from main to test.
// Process resource task contains all source proto files from a proto source set.
FileCollection testClassPathConfig = project.objects.fileCollection()
if (Utils.isTest(sourceSet.name)) {
TaskProvider<ProcessResources> mainProcessResources = project.tasks.named(
project.extensions.getByType(SourceSetContainer)
.getByName(SourceSet.MAIN_SOURCE_SET_NAME)
.processResourcesTaskName,
ProcessResources
)
testClassPathConfig.from(mainProcessResources)
}

Provider<ProtobufExtract> extractIncludeProtosTask = setupExtractIncludeProtosTask(
sourceSet.name, compileProtoPath, sourceSet.compileClasspath)
Provider<GenerateProtoTask> generateProtoTask = addGenerateProtoTask(
Expand Down

0 comments on commit 1fe953a

Please sign in to comment.