Skip to content

Commit

Permalink
Simply mvn build command (#5143)
Browse files Browse the repository at this point in the history
  • Loading branch information
D074360 authored Oct 10, 2024
1 parent 3225a7d commit 430bb9b
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions cmd/mavenBuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,7 @@ func mavenBuild(config mavenBuildOptions, telemetryData *telemetry.CustomData, c
}
}

func executeMavenGoals(config *mavenBuildOptions, utils maven.Utils, flags []string, goals []string, defines []string, mavenOptions *maven.ExecuteOptions) error {
_, err := maven.Execute(mavenOptions, utils)
return err
}

func runMakeBOMGoal(config *mavenBuildOptions, utils maven.Utils, mavenOptions *maven.ExecuteOptions) error {
func runMakeBOMGoal(config *mavenBuildOptions, utils maven.Utils) error {
var flags = []string{"-update-snapshots", "--batch-mode"}
if len(config.Profiles) > 0 {
flags = append(flags, "--activate-profiles", strings.Join(config.Profiles, ","))
Expand Down Expand Up @@ -78,7 +73,19 @@ func runMakeBOMGoal(config *mavenBuildOptions, utils maven.Utils, mavenOptions *
defines = append(defines, "-Dflatten.mode=resolveCiFriendliesOnly", "-DupdatePomFile=true")
}

return executeMavenGoals(config, utils, flags, goals, defines, mavenOptions)
mavenOptions := maven.ExecuteOptions{
Flags: flags,
Goals: goals,
Defines: defines,
PomPath: config.PomPath,
ProjectSettingsFile: config.ProjectSettingsFile,
GlobalSettingsFile: config.GlobalSettingsFile,
M2Path: config.M2Path,
LogSuccessfulMavenTransfers: config.LogSuccessfulMavenTransfers,
}

_, err := maven.Execute(&mavenOptions, utils)
return err
}

func runMavenBuild(config *mavenBuildOptions, telemetryData *telemetry.CustomData, utils maven.Utils, commonPipelineEnvironment *mavenBuildCommonPipelineEnvironment) error {
Expand Down Expand Up @@ -139,13 +146,14 @@ func runMavenBuild(config *mavenBuildOptions, telemetryData *telemetry.CustomDat
LogSuccessfulMavenTransfers: config.LogSuccessfulMavenTransfers,
}

if err := executeMavenGoals(config, utils, flags, goals, defines, &mavenOptions); err != nil {
_, err := maven.Execute(&mavenOptions, utils)
if err != nil {
return errors.Wrapf(err, "failed to execute maven build for goal(s) '%v'", goals)
}

if config.CreateBOM {
// Separate run for makeBOM goal
if err := runMakeBOMGoal(config, utils, &mavenOptions); err != nil {
if err := runMakeBOMGoal(config, utils); err != nil {
return errors.Wrap(err, "failed to execute makeBOM goal")
}
}
Expand Down

0 comments on commit 430bb9b

Please sign in to comment.