google / protobuf-gradle-plugin

Protobuf Plugin for Gradle
Other
1.77k stars 273 forks source link

Generated files base directory should be exposed as public property or at least a provider #722

Open grossws opened 1 year ago

grossws commented 1 year ago

The com.google.protobuf plugin (as of version 0.9.3) has ProtobufExtension#getGeneratedFilesBaseDirProperty method with @PackageScope. This prevents at least Kotlin DSL users from modifying this directory except via deprecated setter method.

I would expect this method to be public and return DirectoryProperty (or Provider<Directory> if you intend to prevent modification). To allow user to address its subdirectories.

Also the plugin use generated/source/proto/<sourceSet> instead of more conventional generated/sources/proto/<sourceSet> (word sources in plural) alongside annotation processors output.

I currently have 3 cases where I want to access this property:

grossws commented 1 year ago

Looking at #33 and #636 I could guess that users (ab)used this parameter to put generated files under <projectDir>/src/ so I totally understand reluctance to expose it as a property but Provider<Directory> would still be safe in that case.

ejona86 commented 1 year ago

What's needed here is a new property completely separate from that old thing. The new thing would clear the directory before generating output. Also, as we see below, maybe this doesn't need configuration to change the output dir.

to mark relevant directories as generated sources in the IDE

This should be addressed by adding the idle or eclipse plugins to your build. That is detected by this plugin to eagerly create the tasks and eagerly create the directories. That's the biggest issue with the IDEs: they expect the source directories to exist before the tasks are run.

to add them to the sources jar

https://github.com/google/protobuf-gradle-plugin/issues/714 may fix that, since we're actually about to use source sets for Kotlin now. You might not to do anything after the next release.

to place them under generated/sources/

That's just a change to the plugin. The plugin is quite old, so may actually predate that convention.