From 1621b4f9fd473c7a405c5132c782c6be59562aae Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Thu, 2 Jan 2020 23:08:24 -0800 Subject: [PATCH 1/4] Link only generated Java or Kotlin as source to compile tasks. --- .../google/protobuf/gradle/ProtobufPlugin.groovy | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index c07b62bf..3c0047fd 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -64,7 +64,6 @@ class ProtobufPlugin implements Plugin { 'android-library', ] - private static final String USER_LANG_PROP = 'protobufGradlePluginAdditionalLanguages' private static final List SUPPORTED_LANGUAGES = [ 'java', 'kotlin', @@ -114,20 +113,9 @@ class ProtobufPlugin implements Plugin { } } - private static List getLanguages(Project project) { - List additionalLanguages = [] - if (project.hasProperty(USER_LANG_PROP)) { - additionalLanguages = (List) project.property(USER_LANG_PROP) - project.logger.log( - LogLevel.WARN, - "protobuf plugin is now using additional unsupported languages: " + additionalLanguages) - } - return SUPPORTED_LANGUAGES + additionalLanguages - } - private static void linkGenerateProtoTasksToTask(Task task, GenerateProtoTask genProtoTask) { task.dependsOn(genProtoTask) - task.source genProtoTask.getOutputSourceDirectorySet() + task.source genProtoTask.getOutputSourceDirectorySet().include("**/*.java", "**/*.kt") } private void doApply() { @@ -468,7 +456,7 @@ class ProtobufPlugin implements Plugin { } else { project.sourceSets.each { SourceSet sourceSet -> project.protobuf.generateProtoTasks.ofSourceSet(sourceSet.name).each { GenerateProtoTask genProtoTask -> - getLanguages(project).each { String lang -> + SUPPORTED_LANGUAGES.each { String lang -> linkGenerateProtoTasksToTaskName(sourceSet.getCompileTaskName(lang), genProtoTask) } } From de9a51484490232d6291f042306ac8a3c85fed80 Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Fri, 3 Jan 2020 00:14:27 -0800 Subject: [PATCH 2/4] Add description for non-Java/Kotlin projects. --- README.md | 18 ++++++++++++++++++ .../protobuf/gradle/ProtobufPlugin.groovy | 1 - 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d438518c..e8e7bbd3 100644 --- a/README.md +++ b/README.md @@ -456,6 +456,24 @@ changed by setting the ``outputSubDir`` property in the ``builtins`` or } ``` +#### For non-Java/Kotlin projects + +Java and Kotlin are the first class supported languages, generated code will be +automatically added for compilation. For projects in other languages, you need +to manually add generated code to the sourceSets based on the language plugin's +configuration. The following example adds generated Scala code (by +[ScalaPB](https://scalapb.github.io/)) to the `main` sourceSet with `scala` plugin: + +```gradle +sourceSets { + main { + scala { + srcDirs "${protobuf.generatedFilesBaseDir}/main/scalapb" + } + } +} +``` + ### Protos in dependencies If a Java project contains proto files, they will be packaged in the jar files diff --git a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy index 3c0047fd..20f7c20e 100644 --- a/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy +++ b/src/main/groovy/com/google/protobuf/gradle/ProtobufPlugin.groovy @@ -43,7 +43,6 @@ import org.gradle.api.file.SourceDirectorySet import org.gradle.api.internal.file.DefaultSourceDirectorySet import org.gradle.api.internal.file.FileResolver import org.gradle.api.internal.file.collections.DefaultDirectoryFileTreeFactory -import org.gradle.api.logging.LogLevel import org.gradle.api.plugins.AppliedPlugin import org.gradle.api.tasks.SourceSet From 9b059e58727f7d2c5d08bfa39be0265e4a3fff58 Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Fri, 10 Jul 2020 02:17:07 -0700 Subject: [PATCH 3/4] Clarify behaviors for generated non-Java/Kotlin in README. --- README.md | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index c51751e0..92086c7d 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,9 @@ files (``*.proto``) in your project. There are two pieces of its job: 2. It adds the generated Java source files to the input of the corresponding Java compilation unit (_sourceSet_ in a Java project; _variant_ in an Android project), so that they can be compiled along with your Java sources. + - Note if you are generating non-Java/Kotlin source files, they will not be + included for compilation automatically, you will need to add them to sources + for language-specific compilations. See details in [this section](#default-outputs). For more information about the Protobuf Compiler, please refer to [Google Developers Site](https://developers.google.com/protocol-buffers/docs/reference/java-generated?csw=1). @@ -330,6 +333,8 @@ protobuf { } ``` +Note the generated Python code will not be included for compilation, you will +need to add them as sources to Python's compilation tasks manually. See [this section](#change-where-files-are-generated) for details about where the code will be generated. @@ -456,24 +461,6 @@ changed by setting the ``outputSubDir`` property in the ``builtins`` or } ``` -#### For non-Java/Kotlin projects - -Java and Kotlin are the first class supported languages, generated code will be -automatically added for compilation. For projects in other languages, you need -to manually add generated code to the sourceSets based on the language plugin's -configuration. The following example adds generated Scala code (by -[ScalaPB](https://scalapb.github.io/)) to the `main` sourceSet with `scala` plugin: - -```gradle -sourceSets { - main { - scala { - srcDirs "${protobuf.generatedFilesBaseDir}/main/scalapb" - } - } -} -``` - ### Protos in dependencies If a Java project contains proto files, they will be packaged in the jar files From 676f6358f43c3997c4118b267ee2d3b94666e125 Mon Sep 17 00:00:00 2001 From: Chengyuan Zhang Date: Mon, 21 Sep 2020 12:12:28 -0700 Subject: [PATCH 4/4] Rephrase in-document reference. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 92086c7d..9eea5d51 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ files (``*.proto``) in your project. There are two pieces of its job: Android project), so that they can be compiled along with your Java sources. - Note if you are generating non-Java/Kotlin source files, they will not be included for compilation automatically, you will need to add them to sources - for language-specific compilations. See details in [this section](#default-outputs). + for language-specific compilations. See details in [Default options section](#default-outputs). For more information about the Protobuf Compiler, please refer to [Google Developers Site](https://developers.google.com/protocol-buffers/docs/reference/java-generated?csw=1).