Skip to content

[ANE] Add Bazel strategy for MODULE.bazel and maven_install.json#1655

Draft
jagonalez wants to merge 4 commits intomasterfrom
jg/feat/bazel
Draft

[ANE] Add Bazel strategy for MODULE.bazel and maven_install.json#1655
jagonalez wants to merge 4 commits intomasterfrom
jg/feat/bazel

Conversation

@jagonalez
Copy link
Contributor

Summary

Adds Bazel project support to fossa-cli, focused on the modern Bzlmod system (MODULE.bazel). Bazel 9 removed WORKSPACE entirely, making MODULE.bazel the only dependency management approach.

What's analyzed:

  • bazel_dep() entries from MODULE.bazel — dependencies from the Bazel Central Registry
  • maven_install.json — Coursier-resolved Maven artifacts with full transitive dependency graph
  • maven.install(artifacts=[...]) from MODULE.bazel — direct Maven coordinates when no lockfile exists

New files:

  • src/Strategy/Bazel.hs — discovery, static analysis, project types
  • src/Strategy/Bazel/ModuleBazel.hs — Megaparsec parser for the restricted Starlark subset in MODULE.bazel
  • src/Strategy/Bazel/MavenInstall.hs — Aeson parser for maven_install.json lockfiles
  • src/Strategy/Bazel/Errors.hs — error types and documentation URLs
  • test/Bazel/ModuleBazelSpec.hs — parser unit tests with multiple fixture variants
  • test/Bazel/MavenInstallSpec.hs — lockfile parser and graph building tests
  • docs/references/strategies/languages/bazel/bazel.md — strategy documentation

Modified files:

  • src/Types.hsBazelProjectType added to DiscoveredProjectType
  • src/DepTypes.hsBazelRegistryType added to DepType
  • src/App/Fossa/Analyze/Discover.hs — registered Bazel discovery

Tested against real-world projects:

  • rules_oci — 13 bazel deps
  • bazel-examples/bzlmod — 5 bazel deps
  • rules_jvm_external — 16 bazel deps + 11 maven deps

What's not yet implemented

  • Dynamic analysis (bazel mod graph --output json) — follow-up PR
  • Transitive resolution of bazel_dep modules (static analysis only sees direct deps)

Test plan

  • cabal build — no warnings
  • cabal test unit-tests -m Bazel — all parser and graph tests pass
  • Manual: fossa list-targets shows bazel@./ for MODULE.bazel projects
  • Manual: fossa analyze -o against rules_oci, bazel-examples/bzlmod, rules_jvm_external
  • make lint (fourmolu + hlint)

🤖 Generated with Claude Code

jagonalez and others added 4 commits February 20, 2026 15:20
Add support for Bazel's modern Bzlmod dependency management system.
This parses MODULE.bazel files for bazel_dep() entries and maven
extension artifacts, maven_install.json lockfiles for transitive
Maven dependencies, and optionally runs `bazel mod graph` for full
resolved module graphs.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add strategy documentation at docs/references/strategies/languages/bazel/.
Add BazelModGraphSpec tests for `bazel mod graph` JSON parsing.
Improve MavenInstallSpec with GraphUtil edge/direct assertions,
v1 fallback tests, and coordinate format edge cases (jar, classifier).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The parser was failing on real projects (rules_jvm_external, rules_oci)
due to Starlark features it couldn't skip past: bare string docstrings,
list comprehensions, .format()/.replace() method chains, string
concatenation with +/%, parenthesized expressions, and function calls
used as values (e.g. use_repo_rule(...)). Also fixed otherStatement
consuming subsequent top-level statements via a greedy skip loop.

Tested against rules_oci (13 deps), bazel-examples (5 deps), and
rules_jvm_external (16 bazel + 11 maven deps from maven_install.json).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@zlav
Copy link
Member

zlav commented Feb 25, 2026

Whats the motivating reason for this?

@chad-fossa
Copy link
Contributor

Re: #1655 (comment)

Preparation for Java ecosystem expansion deeper into enterprise customer environments -- supporting the known monorepo tooling for our primary languages

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

Successfully merging this pull request may close these issues.

3 participants