Maven dependencies are versioned
maven/dependencies-versioned@v1
Every dependency the POM and its modules declare takes a version from the checkout, whether from the entry itself, from <dependencyManagement>, from an imported BOM or from a property. A parent POM published elsewhere is not read here, so a version only that parent manages reads as unresolved.
| Id | maven/dependencies-versioned |
| Version | v1 |
| Category | maven |
| Default severity | warning |
| Interpreter | python3 |
| Timeout | 30 seconds |
| Violations tolerated | 0 |
| Collects | maven |
Collectors
This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.
| Collector | Gathers | Inputs it is given |
|---|---|---|
maven | The Maven build in the project directory: the root pom.xml coordinates, its modules, its properties and every dependency it and its modules declare, with the versions its imported BOMs supply. | projectDir |
The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.
Configuration
{
"guardrails": {
"failOn": "error",
"comment": true,
"checks": [
{
"use": "maven/dependencies-versioned@v1",
"severity": "warning",
"with": {
"projectDir": "."
},
"exemptions": []
}
]
}
}Inputs
| Input | Description | Default | Environment variable |
|---|---|---|---|
projectDir | Directory holding the project, relative to the directory the CLI runs in. | . | GUARDRAIL_INPUT_PROJECTDIR |
How to fix
Version the dependency where the build already decides versions, which for a dependency several modules share is <dependencyManagement> in the root POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>A dependency nothing in the checkout versions is versioned by something outside it, or by nothing at all and the build fails to resolve. Either way the code that is compiled in is not decided by this commit, so reading the diff does not tell you what changed.
The usual something outside it is a <parent> published elsewhere, spring-boot-starter-parent most often. That build resolves perfectly well, and the dependency reads as unversioned here only because the parent is not in the checkout to be read, which is why this is a warning rather than a gate.
More in maven
maven/coordinates-declared. The root POM names the group, the artifact and the version it publishes, declaring them itself or inheriting the group and the version from a<parent>.maven/no-snapshot-dependencies. No dependency the POM and its modules declare, and no BOM they import, is at a-SNAPSHOTversion.maven/pom-parses. The rootpom.xmlis well formed XML, so the build it describes can be read at all.