Skip to content

Commit

Permalink
Add kotlin compile depends on generate proto task
Browse files Browse the repository at this point in the history
  • Loading branch information
rougsig committed Jul 17, 2022
1 parent a74e97d commit ca818fd
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,14 @@ class ProtobufPlugin implements Plugin<Project> {
}
}
postConfigure.add {
// This cannot be called once task execution has started.
// This cannot be called once task execution has start
variant.registerJavaGeneratingTask(generateProtoTask, generateProtoTask.getOutputSourceDirectories())

// registerJavaGeneratingTask do nothing with kotlin tasks. It's works only with java.
project.tasks.named("compile${variant.name.capitalize()}Kotlin").configure {
it.dependsOn(generateProtoTask)
it.source(generateProtoTask.getOutputSourceDirectories())
}
}
}

Expand Down Expand Up @@ -442,28 +448,21 @@ class ProtobufPlugin implements Plugin<Project> {
// The generated javalite sources have lint issues. This is fixed upstream but
// there is still no release with the fix yet.
// https://github.com/google/protobuf/pull/2823
if (isAndroid) {
// variant.registerJavaGeneratingTask called earlier already registers the generated
// sources for normal variants, but unit test variants work differently and do not
// use registerJavaGeneratingTask. Let's call addJavaSourceFoldersToModel for all tasks
// to ensure all variants (including unit test variants) have sources registered.
project.tasks.withType(GenerateProtoTask).each { GenerateProtoTask generateProtoTask ->
generateProtoTask.variant.addJavaSourceFoldersToModel(generateProtoTask.getOutputSourceDirectories())
}

// TODO(zpencer): add gen sources from cross project GenerateProtoTasks
// This is an uncommon project set up but it is possible.
// We must avoid using private android APIs to find subprojects that the variant depends
// on, such as by walking through
// variant.variantData.variantDependency.compileConfiguration.allDependencies
// Gradle.getTaskGraph().getDependencies() should allow us to walk the task graph,
// but unfortunately that API is @Incubating. We can revisit it when it becomes stable.
// https://docs.gradle.org/4.8/javadoc/org/gradle/api/execution/
// TaskExecutionGraph.html#getDependencies-org.gradle.api.Task-

// TODO(zpencer): find a way to make android studio aware of the .proto files
// Simply adding the .proto dirs via addJavaSourceFoldersToModel does not seem to work.
} else {
// TODO(zpencer): add gen sources from cross project GenerateProtoTasks
// This is an uncommon project set up but it is possible.
// We must avoid using private android APIs to find subprojects that the variant depends
// on, such as by walking through
// variant.variantData.variantDependency.compileConfiguration.allDependencies
// Gradle.getTaskGraph().getDependencies() should allow us to walk the task graph,
// but unfortunately that API is @Incubating. We can revisit it when it becomes stable.
// https://docs.gradle.org/4.8/javadoc/org/gradle/api/execution/
// TaskExecutionGraph.html#getDependencies-org.gradle.api.Task-

// TODO(zpencer): find a way to make android studio aware of the .proto files
// Simply adding the .proto dirs via addJavaSourceFoldersToModel does not seem to work.

if (!isAndroid) {
// Make the proto source dirs known to IDEs
project.sourceSets.each { sourceSet ->
SourceDirectorySet protoSrcDirSet = sourceSet.proto
Expand Down

0 comments on commit ca818fd

Please sign in to comment.