Skip to content

Commit 47e3ca2

Browse files
authored
fix(maven): skip dependencies using \${project.version} instead of failing (#96)
When a dependency version references \${project.version}, omnibump was failing with an error because it could not locate where the property is set. \${project.version} is a Maven built-in that refers to the project's own <version> tag, not a configurable property, so the dependency cannot be bumped this way. Instead of erroring, log an informational message and continue. Closes https://linear.app/chainguard/issue/AUTO-655/
1 parent cfbb6e3 commit 47e3ca2

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

pkg/languages/java/maven/maven_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,6 +1395,39 @@ func TestMaven_Update_DependencyPropertyMissingInPomAndParentErrors(t *testing.T
13951395
}
13961396
}
13971397

1398+
func TestMaven_Update_DependencyWithProjectVersionSkipsGracefully(t *testing.T) {
1399+
tmpDir := t.TempDir()
1400+
1401+
writeFile(t, filepath.Join(tmpDir, "pom.xml"), `<?xml version="1.0" encoding="UTF-8"?>
1402+
<project xmlns="http://maven.apache.org/POM/4.0.0">
1403+
<modelVersion>4.0.0</modelVersion>
1404+
<groupId>com.example</groupId>
1405+
<artifactId>parent</artifactId>
1406+
<version>1.0.0</version>
1407+
<packaging>pom</packaging>
1408+
<dependencies>
1409+
<dependency>
1410+
<groupId>com.example</groupId>
1411+
<artifactId>internal-lib</artifactId>
1412+
<version>${project.version}</version>
1413+
</dependency>
1414+
</dependencies>
1415+
</project>`)
1416+
1417+
m := &Maven{}
1418+
cfg := &languages.UpdateConfig{
1419+
RootDir: tmpDir,
1420+
ManifestFile: filepath.Join(tmpDir, "pom.xml"),
1421+
Dependencies: []languages.Dependency{
1422+
{Name: "com.example:internal-lib", Version: "2.0.0"},
1423+
},
1424+
}
1425+
1426+
if err := m.Update(context.Background(), cfg); err != nil {
1427+
t.Fatalf("Maven.Update() error = %v, want nil", err)
1428+
}
1429+
}
1430+
13981431
func TestMaven_Update_PropertiesSplitBetweenCurrentAndParent(t *testing.T) {
13991432
tmpDir := t.TempDir()
14001433
parentPom := filepath.Join(tmpDir, "pom.xml")

pkg/languages/java/maven/updater.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ func dependencyPropertyUpdates(ctx context.Context, pomPath string, patches []Pa
152152
continue
153153
}
154154

155+
// project.version is a Maven built-in that mirrors the project's own <version>
156+
// tag; skip with an informational message instead of failing.
157+
if propertyName == "project.version" {
158+
clog.InfoContextf(ctx, "Skipping %s:%s: uses ${project.version} which is the project's own version tag, not a configurable property",
159+
patch.GroupID, patch.ArtifactID)
160+
continue
161+
}
162+
155163
// Reuse the existing resolver so current-vs-parent ownership stays consistent.
156164
propertyPomPath, err := resolvePropertyPomPath(ctx, pomPath, propertyName)
157165
if err != nil {

0 commit comments

Comments
 (0)