Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions pkg/languages/java/maven/maven_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1395,6 +1395,39 @@ func TestMaven_Update_DependencyPropertyMissingInPomAndParentErrors(t *testing.T
}
}

func TestMaven_Update_DependencyWithProjectVersionSkipsGracefully(t *testing.T) {
tmpDir := t.TempDir()

writeFile(t, filepath.Join(tmpDir, "pom.xml"), `<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>parent</artifactId>
<version>1.0.0</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>internal-lib</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</project>`)

m := &Maven{}
cfg := &languages.UpdateConfig{
RootDir: tmpDir,
ManifestFile: filepath.Join(tmpDir, "pom.xml"),
Dependencies: []languages.Dependency{
{Name: "com.example:internal-lib", Version: "2.0.0"},
},
}

if err := m.Update(context.Background(), cfg); err != nil {
t.Fatalf("Maven.Update() error = %v, want nil", err)
}
}

func TestMaven_Update_PropertiesSplitBetweenCurrentAndParent(t *testing.T) {
tmpDir := t.TempDir()
parentPom := filepath.Join(tmpDir, "pom.xml")
Expand Down
8 changes: 8 additions & 0 deletions pkg/languages/java/maven/updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ func dependencyPropertyUpdates(ctx context.Context, pomPath string, patches []Pa
continue
}

// project.version is a Maven built-in that mirrors the project's own <version>
// tag; skip with an informational message instead of failing.
if propertyName == "project.version" {
clog.InfoContextf(ctx, "Skipping %s:%s: uses ${project.version} which is the project's own version tag, not a configurable property",
patch.GroupID, patch.ArtifactID)
continue
}

// Reuse the existing resolver so current-vs-parent ownership stays consistent.
propertyPomPath, err := resolvePropertyPomPath(ctx, pomPath, propertyName)
if err != nil {
Expand Down
Loading