Hamburger Cross Icon
Min Coverage
+
Java Collector

Min Coverage + Java Collector

✓ Guardrail ↓ Collector Stable Testing And Quality

Enforce Min Coverage using data collected by Java Collector. Automatically check testing and quality standards on every PR.

Guardrail: Enforces a minimum code coverage threshold (default 80%). Fails if coverage data is not available.
Data Source: Analyze Java projects to collect build tool info, dependencies, CI/CD command tracking, test scope, JUnit test results, and JaCoCo coverage. Supports Maven and Gradle.

How Java Collector Powers This Guardrail

The Java Collector gathers metadata from your languages, build systems. This data flows into Lunar's Component JSON, where the Min Coverage guardrail evaluates it against your standards.

When enabled, this check runs automatically on every PR and in AI coding workflows, providing real-time enforcement with actionable feedback.

1
↓ Java Collector Gathers Data Collector
Extracts metadata from code, configs, and tool outputs
2
{ } Component JSON
Data centralized in structured format for evaluation
3
✓ Min Coverage Checks Guardrail
Pass/fail result with actionable feedback in PRs

Quick Start Configuration

Add both the collector and policy to your lunar-config.yml to enable this guardrail.

📄 lunar-config.yml
# Step 1: Enable the Java Collector
collectors:
  - uses: github://earthly/lunar-lib/collectors/java@v1.0.5
    # with: ...

# Step 2: Enable the Testing Guardrails
policies:
  - uses: github://earthly/lunar-lib/policies/testing@v1.0.5
    include: [min-coverage]
    # with: ...

What Java Collector Collects

This collector gathers the following data that the Min Coverage guardrail evaluates.

Collector code

project

Detects Java project structure including build tools (Maven/Gradle), Java version from build config, wrapper scripts, and static analysis tool configuration. Writes project metadata to .lang.java.

Collector code

dependencies

Extracts direct dependencies from pom.xml (using Python XML parsing with property resolution) or gradle.lockfile. Writes dependency data to .lang.java.dependencies.

Collector ci-before-command

cicd

Records java/javac commands executed in CI pipelines along with the Java version. Writes command strings and version info to .lang.java.cicd.cmds.

Collector ci-before-command

maven-cicd

Records Maven commands executed in CI pipelines along with the Maven version. Detects version from installation path, wrapper properties, or mvn --version. Writes to .lang.java.maven.cicd.cmds.

Example Data Flow

Here's an example of the data that Java Collector writes to the Component JSON, which Min Coverage then evaluates.

{ } component.json From Java Collector
{
  "lang": {
    "java": {
      "version": "17",
      "build_systems": ["maven"],
      "pom_xml_exists": true,
      "build_gradle_exists": false,
      "mvnw_exists": true,
      "gradlew_exists": false,
      "gradle_lockfile_exists": false,
      "checkstyle_configured": true,
      "spotbugs_configured": false,
      "source": { "tool": "java", "integration": "code" },
      "cicd": {
        "cmds": [
          { "cmd": "java -jar app.jar", "version": "17.0.2" }
        ]
      },
      "maven": {
        "cicd": {
          "cmds": [
            { "cmd": "mvn clean install", "version": "3.9.6" }
          ]
        }
      },
      "sbt": {
        "cicd": {
          "cmds": [
            { "cmd": "sbt test", "version": "1.9.7" }
          ]
        }
      },
      "tests": {
        "scope": "all",
        "results": {
          "total": 156,
          "passed": 152,
          "failed": 1,
          "skipped": 3,
          "source": { "tool": "maven", "integration": "ci" }
        },
        "coverage": {
          "percentage": 72.5,
          "source": { "tool": "jacoco", "integration": "ci" }
        }
      },
      "dependencies": {
        "direct": [
          { "path": "org.springframework:spring-core", "version": "6.1.3", "indirect": false }
        ],
        "transitive": [],
        "source": { "tool": "maven", "integration": "code" }
      }
    }
  },
  "testing": {
    "source": { "tool": "maven-surefire", "integration": "ci" },
    "results": { "total": 156, "passed": 152, "failed": 1, "skipped": 3 },
    "all_passing": false,
    "runs": [
      {
        "pipeline": "CI",
        "run_id": "36909154652",
        "attempt": 1,
        "job": "build",
        "step": 4,
        "total": 156,
        "passed": 152,
        "failed": 1,
        "skipped": 3,
        "all_passing": false
      }
    ],
    "coverage": {
      "percentage": 72.5,
      "source": { "tool": "jacoco", "integration": "ci" }
    }
  }
}

Configuration Options

Testing Guardrails Inputs

Input Required Default Description
required_languages Required — Comma-separated list of languages to check (e.g., "go,python,nodejs,java"). If empty, applies to all components with any detected language project. Components without .lang.* are always skipped (e.g., docs-only repos).
min_coverage Optional 80 Minimum required coverage percentage (for min-coverage check)

Ready to Automate Your Standards?

See how Lunar can turn your AGENTS.md, engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 300+ built-in guardrails.

Works with any process
check AI agent rules & prompt files
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Auto-ID My Guardrails
Paste your AGENTS.md or manual process doc and get guardrails in minutes
Book a Demo