dongyilai4214 2019-03-31 08:00
浏览 405
已采纳

如何使用Maven构建GO可执行文件

I have my Go source code, after go build, an executable is generated, which accepts some parameters to produce the output. Is there any way build the executable from maven build with any plugins?

  • 写回答

2条回答 默认 最新

  • dongzha3058 2019-04-01 12:59
    关注

    You can just put your go build command into a shell script and run it with this plugin:

    <plugin>
      <artifactId>exec-maven-plugin</artifactId>
      <groupId>org.codehaus.mojo</groupId>
      <executions>
        <execution>
          <id>Build Go binary</id>
          <phase>generate-sources</phase>
          <goals>
            <goal>exec</goal>
          </goals>
          <configuration>
            <executable>${basedir}/build-golang-app.sh</executable>
          </configuration>
        </execution>
      </executions>
    </plugin>
    

    Other option is this Golang plugin which is more feature-rich and specific to this problem. However for simple use cases I would still go with Shell script.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?