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

[BUG] error: package com.buf.validate does not exist #150

Closed
gigi opened this issue Jun 24, 2024 · 2 comments
Closed

[BUG] error: package com.buf.validate does not exist #150

gigi opened this issue Jun 24, 2024 · 2 comments
Labels
Bug Something isn't working

Comments

@gigi
Copy link

gigi commented Jun 24, 2024

Description

Hi. Trying to add compiled dependencies to my java project and got dependencies' issues

Steps to Reproduce

build.gradle.kts:

...
dependencies {
    implementation(libs.liquibase.core)
    implementation(libs.spring.modulith.starter.core)
    implementation(libs.grpc.server.spring.boot.starter)
    implementation("io.grpc:grpc-core:1.64.0")
    implementation("io.grpc:grpc-stub:1.64.0")
    implementation("io.grpc:grpc-protobuf:1.64.0")
    implementation("com.google.protobuf:protobuf-java:4.27.1")
    implementation("build.buf:protovalidate:0.2.1")
}
...

buf.gen.yaml:

version: v2
managed:
  enabled: true
plugins:
  - remote: buf.build/grpc/java:v1.64.0
    out: build/src/java
    opt: '@generated=omit'
  - remote: buf.build/protocolbuffers/java
    out: build/src/java

buf.yaml:

version: v2
modules:
  - path: proto
lint:
  disallow_comment_ignores: true
  use:
    - DEFAULT
    - COMMENT_ENUM
    - COMMENT_ENUM_VALUE
    - COMMENT_FIELD
    - COMMENT_MESSAGE
    - COMMENT_ONEOF
    - COMMENT_RPC
    - COMMENT_SERVICE
deps:
  - buf.build/bufbuild/protovalidate
  - buf.build/googleapis/googleapis
 ./gradlew clean build

> Task :compileJava
.../MyServiceProto.java:161: error: package com.buf.validate does not exist
          com.buf.validate.ValidateProto.getDescriptor(),

Expected Behavior

I'd like to generate java classes using buf generate command, add dependencies and it shoud work

Actual Behavior

Broken dependencies

Screenshots/Logs

Environment

  • Operating System: MacOS
  • Version: 14.5 (23F79)
  • Compiler/Toolchain: 21
  • Protobuf Compiler & Version: 4.27.1
  • Protoc-gen-validate Version:
  • Protovalidate Version: 0.2.1

Possible Solution

Additional Context

Maybe I missed something?

Thanks

@gigi gigi added the Bug Something isn't working label Jun 24, 2024
@pkwarren
Copy link
Member

pkwarren commented Jun 25, 2024

First off, you'll likely need to stay on 3.x version of protobuf-java (remote plugin 25.x). See #116 (comment) and grpc/grpc-java#11015 (comment) - neither the CEL interpreter or grpc-java have updated to the latest 4.x version of protobuf-java due to breaking changes.

To do so, update your buf.gen.yaml to specify remote: buf.build/protocolbuffers/java:25.3 instead of remote: buf.build/protocolbuffers/java.

Additionally, the protovalidate module specifies java_package so shouldn't be used with managed mode. The generated code is shipped with the build.buf:protovalidate artifact in the build.buf.validate package: https://github.com/bufbuild/protovalidate-java/tree/main/src/main/java/build/buf/validate. To disable managed mode, try adding this configuration under managed in your buf.gen.yaml file:

managed:
  disable:
    - module: buf.build/bufbuild/protovalidate

That should ensure that you can import the generated code from this artifact properly.

@gigi
Copy link
Author

gigi commented Jun 26, 2024

@pkwarren
Thanks a lot. This approach works now

version: v2
managed:
  enabled: true
  disable:
    - module: buf.build/bufbuild/protovalidate
plugins:
  - remote: buf.build/grpc/java:v1.64.0
    out: build/src/java
    opt: '@generated=omit'
  - remote: buf.build/protocolbuffers/java:v25.3
    out: build/src/java

I think this should be added to the documentation later :)

@gigi gigi closed this as completed Jun 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants