Hamburger Cross Icon
Java Collector - Lunar Collector

Java Collector

↓ Collector Beta LanguagesBuild

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.

Add java to your lunar-config.yml:
uses: github://earthly/lunar-lib/collectors/java@v1.0.5

What This Integration Collects

This integration includes 9 collectors that gather metadata from your systems.

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.

java project maven gradle pom.xml build.gradle
Book a demo
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.

java dependencies maven dependencies gradle dependencies supply chain
Book a demo
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.

java ci java version ci commands build tracking
Book a demo
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.

maven ci mvn version maven wrapper build tracking
Book a demo
Collector ci-before-command

gradle-cicd

Records Gradle commands executed in CI pipelines along with the Gradle version. Writes to .lang.java.gradle.cicd.cmds.

gradle ci gradle version gradle wrapper build tracking
Book a demo
Collector ci-before-command

sbt-cicd

Records sbt commands executed in CI pipelines along with the sbt version. Detects version from sbt --version or project/build.properties. Writes to .lang.java.sbt.cicd.cmds. Sister of the scala collector's cicd sub-collector — both fire on the same sbt invocation, each writing into its own language namespace for mixed Scala/Java sbt repos.

sbt ci sbt version sbt build build tracking
Book a demo
Collector ci-before-command

test-scope

Determines whether Maven/Gradle test commands run all modules or a subset. Writes scope to .lang.java.tests.scope as "all" or "module" and signals test execution via .testing.source.

java test test scope maven test gradle test
Book a demo
Collector ci-after-command

test-coverage

Extracts JaCoCo coverage percentage from XML reports after test runs. Parses coverage from standard Maven/Gradle report locations and writes results to both .lang.java.tests.coverage and .testing.coverage.

code coverage jacoco test coverage coverage metrics
Book a demo
Collector ci-after-command

test-results

When a Maven or Gradle build finishes, reads the JUnit XML reports it wrote (Surefire, Failsafe, Gradle test tasks) and records how many tests passed, failed and were skipped. Writes the totals to .lang.java.tests.results and .testing.results, whether every test passed to .testing.all_passing, and one entry per build to .testing.runs.

junit test results surefire failsafe gradle test test reports
Book a demo

How Collectors Fit into Lunar

Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.

Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.

Learn How Lunar Works →
1
↓ Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
✓ Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "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" }
    }
  }
}

Documentation

View on GitHub

Java Collector

Collects Java project information, CI/CD commands, dependencies, test results, and test coverage.

Overview

This collector gathers metadata about Java projects including build tool detection (Maven/Gradle), dependency graphs, CI/CD command tracking, test scope, JUnit test results, and JaCoCo coverage metrics. It supports Maven, Gradle, and sbt build systems (the sbt sub-collector covers Java-only sbt repos and sits alongside the scala collector for mixed Scala/Java). Code hooks analyze project structure statically, while CI hooks observe build and test commands at runtime.

Note: The CI-hook collectors (test-results, test-coverage, test-scope, cicd, maven-cicd, gradle-cicd, sbt-cicd) don't run builds or tests—they observe and collect data from commands that your CI pipeline already runs.

Collected Data

This collector writes to the following Component JSON paths:

Path Type Description
.lang.java object Java project metadata (version, build systems, file existence)
.lang.java.dependencies object Direct dependencies from pom.xml or gradle.lockfile
.lang.java.cicd object Java runtime CI/CD command tracking with version
.lang.java.maven.cicd object Maven CI/CD command tracking with version
.lang.java.gradle.cicd object Gradle CI/CD command tracking with version
.lang.java.sbt.cicd object sbt CI/CD command tracking with version
.lang.java.tests object Test scope, JUnit test results, and JaCoCo coverage information
.testing.results object Normalized test totals: total, passed, failed, skipped (dual-write from JUnit XML)
.testing.all_passing boolean false if any test failed or errored
.testing.runs array One entry per build (CI run, attempt, job, step, totals, all_passing)
.testing.coverage object Normalized cross-language coverage (dual-write from JaCoCo)
.testing.source object Normalized testing indicator

Collectors

This plugin provides the following collectors (use include to select a subset):

Collector Hook Type Description
project code Detects Java project structure, build tools, Java version, wrappers
dependencies code Extracts dependencies from pom.xml or gradle.lockfile
cicd ci-before-command Tracks java/javac commands in CI with version
maven-cicd ci-before-command Tracks Maven commands in CI with version
gradle-cicd ci-before-command Tracks Gradle commands in CI with version
sbt-cicd ci-before-command Tracks sbt commands in CI with version
test-scope ci-before-command Determines test scope (all vs module)
test-coverage ci-after-command Extracts JaCoCo coverage from XML reports
test-results ci-after-command Totals passed/failed/skipped tests from Surefire, Failsafe, and Gradle JUnit XML reports

Test results

test-results runs when a Maven or Gradle build finishes. mvn, mvnw, gradle and gradlew all exec into the build's JVM, so the hook is on that java process, whose exit is the end of the build. It reads the TEST-*.xml files in target/surefire-reports/ and target/failsafe-reports/ (Maven) or build/test-results/<task>/ (Gradle) under the build's directory, and writes nothing when there are none. If the reports can't be parsed it exits with an error rather than recording partial totals.

  • It counts each <testcase>: a failure or error fails it, <skipped> skips it, and a test that passed on a Surefire rerun counts as passed.
  • Gradle's test-retry plugin lists every attempt as its own test, so a test that passed on retry still counts its failed attempt. Set reports.junitXml.mergeReruns = true to report it the way Surefire does.
  • .testing.results and .testing.all_passing hold the last build to finish at a commit. .testing.runs keeps every build, and testing.passing fails if the latest attempt of any of them failed, so a passing job can't hide a failing one.
  • Reports left over from an earlier build are counted too. CI checkouts start clean by default; a reused workspace needs mvn clean / gradle clean.

Installation

Add to your lunar-config.yml:

collectors:
  - uses: github://earthly/lunar-lib/collectors/java@v1.0.0
    on: ["domain:your-domain"]  # replace with your own domain or tags
    include:
      - project        # Build tools and Java version
      - dependencies   # Maven and Gradle dependencies
      - cicd           # java and javac commands in CI
      - maven-cicd     # Maven commands in CI
      - gradle-cicd    # Gradle commands in CI
      - sbt-cicd       # sbt commands in CI
      - test-scope     # Test scope in CI
      - test-coverage  # JaCoCo coverage
      - test-results   # JUnit XML test results

Open Source

This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.

View Repository

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