diff --git a/buildpack.toml b/buildpack.toml index 10759c6..2d5cc3d 100644 --- a/buildpack.toml +++ b/buildpack.toml @@ -43,6 +43,12 @@ api = "0.7" description = "the additionnal arguments (appended to BP_MAVEN_BUILD_ARGUMENTS) to pass to Maven" name = "BP_MAVEN_ADDITIONAL_BUILD_ARGUMENTS" + [[metadata.configurations]] + build = true + default = "" + description = "the active profiles (comma separated: such as: p1,!p2,?p3) to pass to Maven" + name = "BP_MAVEN_ACTIVE_PROFILES" + [[metadata.configurations]] build = true default = "target/*.[ejw]ar" diff --git a/maven/build.go b/maven/build.go index 6d7246e..76e1a55 100644 --- a/maven/build.go +++ b/maven/build.go @@ -200,6 +200,15 @@ func (b Build) configureMaven(context libcnb.BuildContext) (libbs.ArtifactResolv args = append(args, additionalArgs...) } + profiles, err := libbs.ResolveArguments("BP_MAVEN_ACTIVE_PROFILES", b.configResolver) + if err != nil { + return libbs.ArtifactResolver{}, map[string]interface{}{}, []string{}, + fmt.Errorf("unable to resolve profiles build arguments\n%w", err) + } else if len(profiles) > 0 { + profiles = append([]string{"-P"}, profiles...) + args = append(args, profiles...) + } + return libbs.ArtifactResolver{ ArtifactConfigurationKey: "BP_MAVEN_BUILT_ARTIFACT", ConfigurationResolver: b.configResolver, diff --git a/maven/build_test.go b/maven/build_test.go index 6becc5c..122d2af 100644 --- a/maven/build_test.go +++ b/maven/build_test.go @@ -155,6 +155,37 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { }) }) + context("BP_MAVEN_ACTIVE_PROFILES adds active profiles", func() { + it.Before(func() { + Expect(os.Setenv("BP_MAVEN_BUILD_ARGUMENTS", "--batch-mode user-provided-argument")).To(Succeed()) + Expect(os.Setenv("BP_MAVEN_ADDITIONAL_BUILD_ARGUMENTS", "-Dgpg.skip -Dmaven.javadoc.skip=true")).To(Succeed()) + Expect(os.Setenv("BP_MAVEN_ACTIVE_PROFILES", "native,?prod,!aot,-dev")).To(Succeed()) + }) + + it.After(func() { + Expect(os.Unsetenv(("BP_MAVEN_BUILD_ARGUMENTS"))).To(Succeed()) + Expect(os.Unsetenv(("BP_MAVEN_ADDITIONAL_BUILD_ARGUMENTS"))).To(Succeed()) + Expect(os.Unsetenv(("BP_MAVEN_ACTIVE_PROFILES"))).To(Succeed()) + }) + it("the profiles native,?prod,!aot,-dev got appended after all the other maven arguments", func() { + Expect(os.WriteFile(mvnwFilepath, []byte{}, 0644)).To(Succeed()) + ctx.StackID = "test-stack-id" + mavenBuild.TTY = false + + result, err := mavenBuild.Build(ctx) + Expect(err).NotTo(HaveOccurred()) + + Expect(result.Layers[1].(libbs.Application).Arguments).To(Equal([]string{ + "--batch-mode", + "user-provided-argument", + "-Dgpg.skip", + "-Dmaven.javadoc.skip=true", + "-P", + "native,?prod,!aot,-dev", + })) + }) + }) + context("BP_MAVEN_SETTINGS_PATH configuration is set", func() { it.Before(func() { ctx.Buildpack.Metadata = map[string]interface{}{