in cmd/java/maven/main.go [65:130]
func buildFn(ctx *gcp.Context) error {
m2CachedRepo, err := ctx.Layer(m2Layer, gcp.CacheLayer, gcp.LaunchLayerIfDevMode)
if err != nil {
return fmt.Errorf("creating %v layer: %w", m2Layer, err)
}
if err := java.CheckCacheExpiration(ctx, m2CachedRepo); err != nil {
return fmt.Errorf("validating the cache: %w", err)
}
homeM2 := filepath.Join(ctx.HomeDir(), ".m2")
// Symlink the m2 layer into ~/.m2. If ~/.m2 already exists, delete it first.
// If it exists as a symlink, RemoveAll will remove the link, not anything it's linked to.
// We can't just use `-Dmaven.repo.local`. It does set the path to `m2/repo` but it fails
// to set the path to `m2/wrapper` which is used by mvnw to download Maven.
if err := ctx.RemoveAll(homeM2); err != nil {
return err
}
if err := ctx.Symlink(m2CachedRepo.Path, homeM2); err != nil {
return err
}
if err := addJvmConfig(ctx); err != nil {
return err
}
mvn, err := provisionOrDetectMaven(ctx)
if err != nil {
return err
}
command := []string{mvn, "clean", "package", "--batch-mode", "-DskipTests", "-Dhttp.keepAlive=false"}
pomPath, err := pomFilePath(ctx)
if err != nil {
return err
}
if pomPath != "" {
command = append(command, fmt.Sprintf("-f=%s", pomPath))
}
if buildArgs := os.Getenv(env.BuildArgs); buildArgs != "" {
if strings.Contains(buildArgs, "maven.repo.local") {
ctx.Warnf("Detected maven.repo.local property set in GOOGLE_BUILD_ARGS. Maven caching may not work properly.")
}
command = append(command, strings.Fields(buildArgs)...)
}
if mvnBuildArgs := os.Getenv(java.MavenBuildArgs); mvnBuildArgs != "" {
command = append([]string{mvn}, strings.Fields(mvnBuildArgs)...)
}
if !ctx.Debug() && !devmode.Enabled(ctx) {
command = append(command, "--quiet")
}
if _, err := ctx.Exec(command, gcp.WithStdoutTail, gcp.WithUserAttribution); err != nil {
return err
}
// Store the build steps in a script to be run on each file change.
if devmode.Enabled(ctx) {
devmode.WriteBuildScript(ctx, m2CachedRepo.Path, "~/.m2", command)
}
return nil
}