2020-03-13 14:32:37 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/SAP/jenkins-library/pkg/command"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/log"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/maven"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/piperutils"
|
|
|
|
"github.com/SAP/jenkins-library/pkg/telemetry"
|
|
|
|
)
|
|
|
|
|
|
|
|
func mavenBuild(config mavenBuildOptions, telemetryData *telemetry.CustomData) {
|
|
|
|
c := command.Command{}
|
|
|
|
|
2020-05-06 13:35:40 +02:00
|
|
|
c.Stdout(log.Writer())
|
|
|
|
c.Stderr(log.Writer())
|
2020-03-13 14:32:37 +02:00
|
|
|
|
2020-03-26 09:23:21 +02:00
|
|
|
utils := piperutils.Files{}
|
|
|
|
|
|
|
|
err := runMavenBuild(&config, telemetryData, &c, &utils)
|
2020-03-13 14:32:37 +02:00
|
|
|
if err != nil {
|
|
|
|
log.Entry().WithError(err).Fatal("step execution failed")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 11:28:16 +02:00
|
|
|
func runMavenBuild(config *mavenBuildOptions, telemetryData *telemetry.CustomData, command command.ExecRunner, utils piperutils.FileUtils) error {
|
2020-03-13 14:32:37 +02:00
|
|
|
var flags = []string{"-update-snapshots", "--batch-mode"}
|
|
|
|
|
2020-03-26 09:23:21 +02:00
|
|
|
exists, _ := utils.FileExists("integration-tests/pom.xml")
|
2020-03-13 14:32:37 +02:00
|
|
|
if exists {
|
|
|
|
flags = append(flags, "-pl", "!integration-tests")
|
|
|
|
}
|
|
|
|
|
|
|
|
var defines []string
|
|
|
|
var goals []string
|
|
|
|
|
|
|
|
goals = append(goals, "org.jacoco:jacoco-maven-plugin:prepare-agent")
|
|
|
|
|
|
|
|
if config.Flatten {
|
|
|
|
goals = append(goals, "flatten:flatten")
|
|
|
|
defines = append(defines, "-Dflatten.mode=resolveCiFriendliesOnly", "-DupdatePomFile=true")
|
|
|
|
}
|
|
|
|
|
|
|
|
if config.Verify {
|
|
|
|
goals = append(goals, "verify")
|
|
|
|
} else {
|
|
|
|
goals = append(goals, "install")
|
|
|
|
}
|
|
|
|
|
|
|
|
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, command)
|
|
|
|
return err
|
|
|
|
}
|