From 4e45bef1fad140e5194cf20b12ef64fa57f6f4de Mon Sep 17 00:00:00 2001 From: Faycal SKHIRI Date: Tue, 16 Jun 2026 14:25:55 +0200 Subject: [PATCH 1/4] fix(mavenBuild): use Maven 3.x altDeploymentRepository format (id::url) Drop the legacy ::default:: layout token. maven-deploy-plugin 3.x parses id::layout::url as id=::default, which never matches the entry in settings.xml, causing 401. The correct 3.x format is id::url only. --- cmd/mavenBuild.go | 2 +- cmd/mavenBuild_test.go | 2 +- resources/metadata/mavenBuild.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cmd/mavenBuild.go b/cmd/mavenBuild.go index 6080a3e2b3..b5421dc988 100644 --- a/cmd/mavenBuild.go +++ b/cmd/mavenBuild.go @@ -197,7 +197,7 @@ func runMavenBuild(config *mavenBuildOptions, _ *telemetry.CustomData, utils mav deployFlags = append(deployFlags, config.DeployFlags...) } if (len(config.AltDeploymentRepositoryID) > 0) && (len(config.AltDeploymentRepositoryURL) > 0) { - deployFlags = append(deployFlags, "-DaltDeploymentRepository="+config.AltDeploymentRepositoryID+"::default::"+config.AltDeploymentRepositoryURL) + deployFlags = append(deployFlags, "-DaltDeploymentRepository="+config.AltDeploymentRepositoryID+"::"+config.AltDeploymentRepositoryURL) } downloadClient := &piperhttp.Client{} diff --git a/cmd/mavenBuild_test.go b/cmd/mavenBuild_test.go index 0ad686891b..740f158281 100644 --- a/cmd/mavenBuild_test.go +++ b/cmd/mavenBuild_test.go @@ -104,7 +104,7 @@ func TestMavenBuild(t *testing.T) { assert.Nil(t, err) if assert.Equal(t, 2, len(mockedUtils.Calls), "Expected two Maven invocations (main and deploy)") { - assert.Contains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::default::http://sampleRepo.com") + assert.Contains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::http://sampleRepo.com") } }) diff --git a/resources/metadata/mavenBuild.yaml b/resources/metadata/mavenBuild.yaml index e30d3d4821..a52e1e1597 100644 --- a/resources/metadata/mavenBuild.yaml +++ b/resources/metadata/mavenBuild.yaml @@ -194,7 +194,7 @@ spec: param: custom/repositoryUrl - name: altDeploymentRepositoryID type: string - description: Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with tag + description: Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with tag. Note: Piper emits the flag in Maven 3.x format (-DaltDeploymentRepository=id::url); maven-deploy-plugin 3.0.0 or newer is required. The legacy three-token id::layout::url form is no longer used. scope: - GENERAL - PARAMETERS From b050804d0a89a992256d9a696929ef0cfae68f07 Mon Sep 17 00:00:00 2001 From: Faycal SKHIRI Date: Mon, 22 Jun 2026 15:57:18 +0200 Subject: [PATCH 2/4] refactor(mavenBuild): use idiomatic var declaration for deployFlags The slice was initialized with []string{} and immediately conditionally appended to. Go convention for zero-value slice initialization is 'var deployFlags []string', which is functionally identical but avoids allocating an empty slice header unnecessarily. --- cmd/mavenBuild.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/mavenBuild.go b/cmd/mavenBuild.go index b5421dc988..0bce878050 100644 --- a/cmd/mavenBuild.go +++ b/cmd/mavenBuild.go @@ -192,7 +192,7 @@ func runMavenBuild(config *mavenBuildOptions, _ *telemetry.CustomData, utils mav mavenOptions.ProjectSettingsFile = projectSettingsFilePath } - deployFlags := []string{} + var deployFlags []string if len(config.DeployFlags) > 0 { deployFlags = append(deployFlags, config.DeployFlags...) } From d09cb936e7342dc3ff96fd740bddcb990c5ae2fb Mon Sep 17 00:00:00 2001 From: Faycal SKHIRI Date: Mon, 22 Jun 2026 16:36:24 +0200 Subject: [PATCH 3/4] docs(mavenBuild): clarify altDeploymentRepositoryID uses Maven 3.x format The description previously lacked guidance on which maven-deploy-plugin version is required. Users on plugin 3.0.0+ were hitting failures because the old three-token id::layout::url form was silently dropped in that release. Add a note explaining that Piper emits -DaltDeploymentRepository=id::url (Maven 3.x two-token format) and that maven-deploy-plugin 3.0.0+ is required. Also quote the YAML description string to avoid any YAML parser ambiguity with the embedded colons. --- cmd/mavenBuild_generated.go | 2 +- resources/metadata/mavenBuild.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/mavenBuild_generated.go b/cmd/mavenBuild_generated.go index 489cca007f..2cf3edb1ee 100644 --- a/cmd/mavenBuild_generated.go +++ b/cmd/mavenBuild_generated.go @@ -301,7 +301,7 @@ func addMavenBuildFlags(cmd *cobra.Command, stepConfig *mavenBuildOptions) { cmd.Flags().StringVar(&stepConfig.AltDeploymentRepositoryPassword, "altDeploymentRepositoryPassword", os.Getenv("PIPER_altDeploymentRepositoryPassword"), "Password for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This password will be updated in settings.xml . When no settings.xml is provided a new one is created corresponding with tag") cmd.Flags().StringVar(&stepConfig.AltDeploymentRepositoryUser, "altDeploymentRepositoryUser", os.Getenv("PIPER_altDeploymentRepositoryUser"), "User for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This user will be updated in settings.xml . When no settings.xml is provided a new one is created corresponding with tag") cmd.Flags().StringVar(&stepConfig.AltDeploymentRepositoryURL, "altDeploymentRepositoryUrl", os.Getenv("PIPER_altDeploymentRepositoryUrl"), "Url for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This Url will be updated in settings.xml . When no settings.xml is provided a new one is created corresponding with tag") - cmd.Flags().StringVar(&stepConfig.AltDeploymentRepositoryID, "altDeploymentRepositoryID", os.Getenv("PIPER_altDeploymentRepositoryID"), "Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with tag") + cmd.Flags().StringVar(&stepConfig.AltDeploymentRepositoryID, "altDeploymentRepositoryID", os.Getenv("PIPER_altDeploymentRepositoryID"), "Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with tag. Note: Piper emits the flag in Maven 3.x format (-DaltDeploymentRepository=id::url); maven-deploy-plugin 3.0.0 or newer is required. The legacy three-token id::layout::url form is no longer used.") cmd.Flags().StringSliceVar(&stepConfig.CustomTLSCertificateLinks, "customTlsCertificateLinks", []string{}, "List of download links to custom TLS certificates. This is required to ensure trusted connections to instances with repositories (like nexus) when publish flag is set to true.") cmd.Flags().BoolVar(&stepConfig.Publish, "publish", false, "Configures maven to run the deploy plugin to publish artifacts to a repository.") cmd.Flags().StringVar(&stepConfig.JavaCaCertFilePath, "javaCaCertFilePath", os.Getenv("PIPER_javaCaCertFilePath"), "path to the cacerts file used by Java. When maven publish is set to True and customTlsCertificateLinks (to deploy the artifact to a repository with a self signed cert) are provided to trust the self signed certs, Piper will extend the existing Java cacerts to include the new self signed certs. if not provided Piper will search for the cacerts in $JAVA_HOME/jre/lib/security/cacerts") diff --git a/resources/metadata/mavenBuild.yaml b/resources/metadata/mavenBuild.yaml index a52e1e1597..90120654ea 100644 --- a/resources/metadata/mavenBuild.yaml +++ b/resources/metadata/mavenBuild.yaml @@ -194,7 +194,7 @@ spec: param: custom/repositoryUrl - name: altDeploymentRepositoryID type: string - description: Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with tag. Note: Piper emits the flag in Maven 3.x format (-DaltDeploymentRepository=id::url); maven-deploy-plugin 3.0.0 or newer is required. The legacy three-token id::layout::url form is no longer used. + description: "Id for the alternative deployment repository to which the project artifacts should be deployed ( other than those specified in ). This id will be updated in settings.xml and will be used as a flag with DaltDeploymentRepository along with mavenAltDeploymentRepositoryUrl during maven deploy . When no settings.xml is provided a new one is created corresponding with tag. Note: Piper emits the flag in Maven 3.x format (-DaltDeploymentRepository=id::url); maven-deploy-plugin 3.0.0 or newer is required. The legacy three-token id::layout::url form is no longer used." scope: - GENERAL - PARAMETERS From 6b3b7cd7fc0e557254f3c4601a6af76cb34d7e3c Mon Sep 17 00:00:00 2001 From: Faycal SKHIRI Date: Thu, 2 Jul 2026 10:16:44 +0200 Subject: [PATCH 4/4] test(mavenBuild): enforce altDeploymentRepository flag guard conditions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The existing test only covered the happy path (both ID and URL set). The production guard uses &&, meaning a partial config must silently skip the flag — but nothing prevented a future refactor from breaking that invariant. Add three subtests: - Publish=true, ID set, URL empty → flag must not appear - Publish=true, URL set, ID empty → flag must not appear - Publish=false, ID and URL set → deploy is skipped entirely --- cmd/mavenBuild_test.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/cmd/mavenBuild_test.go b/cmd/mavenBuild_test.go index 740f158281..eb8d3cdca4 100644 --- a/cmd/mavenBuild_test.go +++ b/cmd/mavenBuild_test.go @@ -108,6 +108,45 @@ func TestMavenBuild(t *testing.T) { } }) + t.Run("mavenBuild with deploy must not set altDeploymentRepository when URL is missing", func(t *testing.T) { + mockedUtils := newMavenMockUtils() + + options := mavenBuildOptions{Publish: true, Verify: false, AltDeploymentRepositoryID: "ID"} + + err := runMavenBuild(&options, nil, &mockedUtils, &cpe) + + assert.Nil(t, err) + if assert.Equal(t, 2, len(mockedUtils.Calls), "Expected two Maven invocations (main and deploy)") { + assert.NotContains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=ID::") + } + }) + + t.Run("mavenBuild with deploy must not set altDeploymentRepository when ID is missing", func(t *testing.T) { + mockedUtils := newMavenMockUtils() + + options := mavenBuildOptions{Publish: true, Verify: false, AltDeploymentRepositoryURL: "http://sampleRepo.com"} + + err := runMavenBuild(&options, nil, &mockedUtils, &cpe) + + assert.Nil(t, err) + if assert.Equal(t, 2, len(mockedUtils.Calls), "Expected two Maven invocations (main and deploy)") { + assert.NotContains(t, mockedUtils.Calls[1].Params, "-DaltDeploymentRepository=::http://sampleRepo.com") + } + }) + + t.Run("mavenBuild must not set altDeploymentRepository when Publish is false", func(t *testing.T) { + mockedUtils := newMavenMockUtils() + + options := mavenBuildOptions{Publish: false, AltDeploymentRepositoryID: "ID", AltDeploymentRepositoryURL: "http://sampleRepo.com"} + + err := runMavenBuild(&options, nil, &mockedUtils, &cpe) + + assert.Nil(t, err) + if assert.Equal(t, 1, len(mockedUtils.Calls), "Expected one Maven invocation (no deploy when Publish is false)") { + assert.NotContains(t, mockedUtils.Calls[0].Params, "-DaltDeploymentRepository=ID::http://sampleRepo.com") + } + }) + t.Run("mavenBuild should not create build artifacts metadata when CreateBuildArtifactsMetadata is false and Publish is true", func(t *testing.T) { mockedUtils := newMavenMockUtils() mockedUtils.AddFile("pom.xml", []byte{})