I am having the requirement of running a maven
built using go lang
without installing maven
to the running system. With the use of os.exec
package in go
I am able to run any program which is already defined in my PATH
variable. But setting M2_HOME
in PATH
variable is not an option here and I am having the maven
distribution extracted in specific location. According to the answer given in here it is possible to run a maven
build by providing the specific location of mvn
, how do I achieve the same from go
.
Thanks in advance
As with the comment by @putu and with specifying the required maven
goals one by one as separate arguments to the exe.Command()
I was able to run maven
build without installing maven
or setting M2_HOME
in $PATH
variable. Below is the code snippet for anyone trying to achieve the same.
// Use os package to run the maven build using location where maven(headless) resides
func updateDistribution() error {
command := exec.Command("apache-maven-3.5.2/bin/mvn", "clean", "install")
command.Dir = "."
output, err := command.Output()
if err != nil {
return err
}
fmt.Printf("%s", output)
return nil
}