buf
buf copied to clipboard
Unable to disable default java_package_prefix with managed mode
With the below buf.gen.yaml
, a default java_package_prefix
value of com
is always set when managed mode is enabled.
Can you please add functionality to disable the default java_package_prefix
from being applied?
version: v1
managed:
enabled: true
plugins:
- name: java
out: gen/proto/java
Setting to an empty string unfortunately does not remove/disable the prefix
version: v1
managed:
enabled: true
java_package_prefix:
default: ""
plugins:
- name: java
out: gen/proto/java
My workaround was to give my local module a name and make an exception for it.
# proto/buf.yaml
version: v1
name: buf.build/my/protos
breaking:
use:
- FILE
lint:
use:
- BASIC
# buf.gen.yaml
version: v1
managed:
enabled: true
java_package_prefix:
default: com.pletelyirrelevant
except:
- buf.build/my/protos
plugins:
- plugin: java
out: gen/proto/java
This disabled the java_package
behavior that wasn't needed because my .proto
packages were already prefixed with reverse domain name. I understand that is not best practice per Files and packages, but you don't always have the luxury to change things.
Hi, I want to use the reverse domain of "xxx.co.jp". I'd like to simply generate codes with the proto package below:
- proto
syntax = "proto3";
package jp.co.xxx;
...
- buf.gen.yaml
version: v1
managed:
enabled: true
plugins:
- plugin: buf.build/grpc/kotlin:v1.4.1
out: gen
- plugin: buf.build/protocolbuffers/kotlin
out: gen
- plugin: buf.build/grpc/java
out: gen
I cannot avoid the default behavior. It will generate codes with the package of com.jp.co.xxx
. What can I do?
In buf.gen.yaml
v2, you can now disable an option in managed mode:
version: v2
plugins:
# ...
managed:
disable:
- file_option: java_package
This prevents java_package
from being modified by managed mode.
You can upgrade your buf.gen.yaml
by running:
buf config migrate
or
buf config migrate --buf-gen-yaml path/to/buf.gen.yaml
if your buf.gen.yaml
is not at the current directory or named differently. Use the --diff
flag to only display the difference between your upgraded and current file.