raydac / mvn-golang

maven plugin to automate GoSDK load and build of projects
Apache License 2.0
163 stars 31 forks source link

running go mod tidy under mvngolang-wrapper not update go.mod and go.sum file #102

Open dantran opened 4 months ago

dantran commented 4 months ago

I have the following maven profile

<profile>
  <id>go-mod-tidy</id>
  <build>
    <defaultGoal>initialize</defaultGoal>
    <plugins>
      <plugin>
        <groupId>com.igormaznitsa</groupId>
        <artifactId>mvn-golang-wrapper</artifactId>
        <executions>
          <execution>
            <id>go-mod</id>
            <phase>initialize</phase>
            <goals>
              <goal>mod</goal>
            </goals>
            <configuration>
              <command>tidy</command>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</profile>

Then I run mvn -Pgo-mod-tidy at any maven golang module, somehow the log show some type of dependency resolution, but go.mod does not get updated

[INFO] --- mvn-golang-wrapper:2.3.10:mod (go-mod) @ deploypatch ---
[INFO] Scanning maven dependencies
[INFO] mvn-golang dependency: com.xxxx.dpsg.search.client:search-client-common:mvn-golang:19.18.0-1-SNAPSHOT:compile
[INFO] Module mode is activated
[INFO] Dependencies are not added into GOPATH because module mode is on
[INFO] Executable file detected : /home/trand8/.mvnGoLang/go1.22.5.linux-amd64/bin/go
[INFO] Prepared command line : bin/go mod tidy
[INFO] Detected module folder '/home/trand8/dev/sources/search-client/golang/deploy-patch/src' in use as working folder
[INFO] Working directory: /home/trand8/dev/sources/search-client/golang/deploy-patch/src
[INFO]
[INFO] ....Environment vars....
[INFO]  $GOROOT = /home/trand8/.mvnGoLang/go1.22.5.linux-amd64
[INFO]  $GOPATH = /home/trand8/dev/sources/search-client/golang/deploy-patch/.external-resources/goPath:/home/trand8/dev/sources/search-client/golang/deploy-patch
[INFO]  $GOBIN = /home/trand8/dev/sources/search-client/golang/deploy-patch/target
[INFO]  $GOCACHE = /home/trand8/dev/sources/search-client/golang/deploy-patch/.external-resources/goCache
[INFO]  $PATH = /home/trand8/.mvnGoLang/go1.22.5.linux-amd64/bin:/home/trand8/.mvnGoLang/go1.22.5.linux-amd64/bin:/home/trand8/.mvnGoLang/go1.22.5.linux-amd64/bin:/home/trand8/dev/tools/bin:/home/trand8/dev/tools/mvnd/maven-mvnd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/wsl/lib:/mnt/c/Program:/home/trand8/dev/sources/search-client/golang/deploy-patch/target:/home/trand8/dev/sources/search-client/golang/deploy-patch/target
[INFO]  $GOMODCACHE = /home/trand8/dev/sources/search-client/golang/deploy-patch/.external-resources/goModCache
[INFO]  $GOPROXY = https://dps.artifactory.cec.lab.xxxx.com/artifactory/dps-go-public
[INFO]  $GOSUMDB = sum.golang.org ap.drm.ops.lab.xxxxx.com/artifactory/golang-sum
[WARNING] Forcing 'GO111MODULE = on' because module mode is activated
[INFO]  $GO111MODULE = on
[INFO] ........................
[WARNING]
[WARNING] ---------Exec.Err---------
[WARNING] go: finding module for package github.com/stretchr/testify/assert
[WARNING] go: finding module for package github.com/pkg/sftp
[WARNING] go: finding module for package golang.org/x/crypto/ssh
[WARNING] go: found github.com/pkg/sftp in github.com/pkg/sftp v1.13.6
[WARNING] go: found golang.org/x/crypto/ssh in golang.org/x/crypto v0.23.0
[WARNING] go: found github.com/stretchr/testify/assert in github.com/stretchr/testify v1.9.0
[WARNING]

however, If I run 'go mod tidy' command directly, with proper env setup. it works. go.mod updated

I intend to run mvn -Pgo-mod on maven multi-modules build, so that it can auto-update my go.mod and go.sum

dantran commented 4 months ago

I found a solution via debug log and read up the source , and have this property in my pom.xml

  <properties>
    <mvn.golang.restore.go.mod>false</mvn.golang.restore.go.mod>
  </properties>  

However, doing so, it leaves .#go.mod.mvn.orig file at the source. Can this plugin remove this file?