Java Collector
Analyze Java projects to collect build tool info, dependencies, CI/CD command tracking, test scope, and JaCoCo coverage. Supports Maven and Gradle.
java to your lunar-config.yml:uses: github://earthly/lunar-lib/collectors/java@v1.0.0
What This Integration Collects
This integration includes 7 collectors that gather metadata from your systems.
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.
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-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.
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.cicd.cmds.
gradle-cicd
Records Gradle commands executed in CI pipelines along with the Gradle version. Writes to .lang.java.cicd.cmds.
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.
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.
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 →Example Collected Data
This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:
{
"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", "tool": "java" },
{ "cmd": "mvn clean install", "version": "3.9.6", "tool": "maven" }
],
"source": { "tool": "java", "integration": "ci" }
},
"tests": {
"scope": "all",
"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" }
}
}
}
}
Documentation
View on GitHubJava Collector
Collects Java project information, CI/CD commands, dependencies, 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, and JaCoCo coverage metrics. It supports both Maven and Gradle build systems. Code hooks analyze project structure statically, while CI hooks observe build and test commands at runtime.
Note: The CI-hook collectors (test-coverage, test-scope, java-cicd, maven-cicd, gradle-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 | CI/CD command tracking with tool and version |
.lang.java.tests |
object | Test scope and JaCoCo coverage information |
.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 |
java-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 |
test-scope |
ci-before-command | Determines test scope (all vs module) |
test-coverage |
ci-after-command | Extracts JaCoCo coverage from XML reports |
Installation
Add to your lunar-config.yml:
collectors:
- uses: github://earthly/lunar-lib/collectors/java@v1.0.0
on: [java] # Or use domain: ["domain:your-domain"]
# include: [project, dependencies] # Only include specific subcollectors
Open Source
This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.
Common Use Cases
Explore guardrails that use data from Java Collector.
Ready to Automate Your Standards?
See how Lunar can turn your engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 100+ built-in guardrails.