Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to disable/customize sourceSets for protoc plugins #759

Open
safeuq-xflowpay opened this issue Aug 14, 2024 · 0 comments
Open

Option to disable/customize sourceSets for protoc plugins #759

safeuq-xflowpay opened this issue Aug 14, 2024 · 0 comments

Comments

@safeuq-xflowpay
Copy link

Hi,

I am trying to migrate our codebase from Maven to Gradle. We are using the protoc-gen-jsonschema plugin to generate JSON Schema from the defined proto files. The configuration file looks like this:

protobuf {  
  protoc {
    artifact = "com.google.protobuf:protoc:3.18.1"
  }

  generateProtoTasks {
    ofSourceSet(sourceSets["main"].name).all {
      val jsonSchema by plugins.register("jsonschema") {
        outputSubDir = "jsonschema-res"

        option("prefix_schema_files_with_package")
        option("disallow_additional_properties")
        option("disallow_bigints_as_strings")
      }
  }
}

The above code seems to work, but the generated JSON schema files are included in the JAR generated by the jar task. Apparently, this plugin seems to add the protoc plugin's outputSubDir to sourceSets.java regardless of the content generated by the protoc plugin. So the workaround I had to do was to move all the generated JSON schemas into a separate directory and add it to the resources sourceSet.

protobuf {  
  generateProtoTasks {
    ofSourceSet(sourceSets["main"].name).all {
      // ...
      val outputBaseDir = file(outputBaseDir)
      val jsonSchemaDir = outputBaseDir.resolve(jsonSchema.outputSubDir)
      val jsonSchemaResDir = outputBaseDir.resolve("jsonschema")
      val jsonSchemaResSubDir = jsonSchemaResDir.resolve("jsonschema")
      sourceSets["main"].resources.srcDir(jsonSchemaResDir)

      doLast {
        copy { from(jsonSchemaDir); into(jsonSchemaResSubDir) }
        delete(jsonSchemaDir)
      }
      // ...
    }
  }
}

I was wondering if there is an option to disable/customize files added to the sourceSet on a per-plugin basis. I went through the plugin code and was not able to find anything that would allow me to do this. I was also wondering if there are any other better ways to achieve the same.

Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant