Support generating and maintaining buf.lock (buf dep update / buf dep prune)

Aperta
#504 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
kotlin

Direzione di ricerca

Start by reading the README’s dependency setup and the plugin’s BufExtension and copyBufConfig implementation, which the issue identifies as the current gaps. Trace how bufBuild, bufLint, and bufGenerate use the copied workspace and the pinned CLI. Done means dependency update and prune tasks manage buf.lock, dependent tasks resolve it, and the lock file is copied into the build workspace.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Motivation

A buf.yaml v2 workspace can declare BSR dependencies in deps:. The resolution of those dependencies is pinned in a buf.lock file, generated by the Buf CLI (buf dep update for v2 configs, buf mod update for v1 configs) and committed next to buf.yaml.

Today the plugin cannot produce or manage that lock file:

  • The README states: "If your buf.yaml declares any dependencies using the deps key, you must run buf mod update to create a buf.lock file manually. The buf-gradle-plugin does not (yet) support creating the dependency lock file."
  • BufExtension exposes no deps/lockFile properties, and the plugin registers no task that runs buf dep update/buf dep prune.
  • copyBufConfig copies only buf.yaml into build/bufbuild; buf.lock is never copied, so a build workspace whose config declares deps: cannot resolve imports from BSR modules at all.

For projects using this plugin together with BSR dependencies (for example buf.build/googleapis/googleapis or buf.build/bufbuild/protovalidate), lock file creation, refresh, and pruning are entirely manual out-of-band steps, and it is easy for buf.lock to drift from buf.yaml (or to be missing entirely, in which case imports fail with imported file does not exist).

Proposed API

Something along these lines (happy to adjust to whatever shape the maintainers prefer):

buf {
    deps {
        module("buf.build/googleapis/googleapis")
        module("buf.build/bufbuild/protovalidate")
    }

    // Optional: where the lock file lives/written. Defaults to <config dir>/buf.lock
    lockFileLocation = rootProject.file("buf.lock")
}

deps would let the plugin know that dependency resolution is required (and could also be used to generate a deps section when the plugin writes the workspace config), while lockFileLocation would allow the lock file to live outside the module directory, which is what multi-module setups typically want.

Proposed tasks
  • bufDepUpdate — runs buf dep update against the Buf config, creating or refreshing buf.lock (including transitive dependencies).
  • bufDepPrune — runs buf dep prune to drop lock entries that are no longer imported by any module.

Suggested behaviour:

  • When deps are declared, bufDepUpdate should be wired as a dependency of the tasks that need resolved dependencies: bufBuild, bufLint, and bufGenerate (the latter especially when generate { includeImports = true } is set, since generation reads buf.lock).
  • buf.lock should be declared as a task input/output so incremental builds behave correctly. buf dep update writes the file into the working directory, so without proper input/output declarations the dependent tasks would re-run on every build.
  • When the plugin copies the config into build/bufbuild, it should also copy buf.lock next to it, so the generated build workspace can resolve imports from BSR modules.
Workaround today
  • Run buf dep update by hand (or from CI) and commit buf.lock.
  • Add a custom Exec task that shells out to the CLI.
Additional notes
  • buf dep update requires network access to the BSR, and authentication for private registries; the plugin already downloads a pinned CLI (toolVersion), so the tasks should use that same binary rather than requiring one on PATH.
  • The README currently references the v1-era buf mod update; the v2 commands are buf dep update and buf dep prune.
  • Related prior art: kotlinx-rpc PR #739 (KRPC-585) added buf.deps plus a BufLockTask that either runs buf dep update or copies a provided lock file, and made buf.yaml/buf.gen.yaml/buf.lock task inputs for the same incremental-build reason.
Lingua principale
Kotlin
Stelle
56
Fork
17
Merge medio
2g 14h
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bufbuild/buf-gradle-plugin

Tutte le issue di bufbuild/buf-gradle-plugin

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.