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

About using third-party dependencies locally #2705

Closed
sishui opened this issue Jan 12, 2024 · 1 comment
Closed

About using third-party dependencies locally #2705

sishui opened this issue Jan 12, 2024 · 1 comment

Comments

@sishui
Copy link

sishui commented Jan 12, 2024

#2622

test.proto content

syntax = "proto3";

package api;

option go_package = "github.com/mypkg/myproject/api";


import "status/status.proto";   # this 3rd-party deps

message MyMessage {
    status.Status status = 1;
}

I use buf generate proto

But after generating it(test.pb.go), the package name of the imported third library is wrong.

import (
	status "github.com/mypkg/myproject/api/status"
	....
)

status "github.com/mypkg/myproject/api/status" is its own package name, not the package name of a third party dependency, am I doing something wrong? Please help me. Thanks!

Here is the full test project

@doriable
Copy link
Member

doriable commented Jun 5, 2024

Thank you for including a repro, I've taken a look and basically you have managed mode enabled (https://buf.build/docs/generate/managed-mode) with the following configuration:

managed:
  enabled: true
  go_package_prefix:
    default: github.com/mypkg/myproject/api
    except:
      - buf.build/googleapis/googleapis

This default is set for your entire workspace, which includes the contents of your vendor directory, and will override the existing options set.

When using a v1 buf.gen.yaml, you cannot exclude a local directory from managed mode using except, you can only provide named modules (such as the buf.build/googleapis/googleapis you currently have configured). You have two options:

  1. Disable managed mode and manage all file options, such as option go_package manually in each file.
  2. Migrate to v2 buf.gen.yaml where you will be able to disable managed mode for the vendor directory (https://buf.build/docs/configuration/v2/buf-gen-yaml#disable). There is a command built into the current versions of buf that can help with this, full docs on the migration are available here: https://buf.build/docs/migration-guides/migrate-v2-config-files

I would suggest migrating and then disabling the file option for your vendor folder, since this will make it very explicit which files you are not managing with managed mode and still provide you with the convenience of managed mode for your own modules.

Closing this issue for now, please feel free to re-open if you run into additional problems. Thanks!

@doriable doriable closed this as completed Jun 5, 2024
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

2 participants