raydac / mvn-golang

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

"Missing go.sum entry error" when building using Go 1.16 with modules #84

Closed steromano87 closed 3 years ago

steromano87 commented 3 years ago

Description

While using Go 1.15 with module support, any error in the go.sum file was automatically fixed during the build phase. However, with Go 1.16, this automatic fix was disabled (see here).

Unfortunately, during build time the go.sum file is deleted and never restored. As a result, building any project using the new Go version yields the following error during any stage of the build:

[ERROR] ---------Exec.Err---------
[ERROR] go: github.com/google/uuid@v1.2.0: missing go.sum entry; to add it:
[ERROR]     go mod download github.com/google/uuid

You can find the complete output of mvn clean compile command using a simple Maven project attached to this bug.

Here there is the parent POM of my project (defining the configuration of the mvn-golang-wrapper plugin):

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>mygroup</groupId>
    <artifactId>mygoproject</artifactId>
    <packaging>pom</packaging>
    <version>${revision}</version>

    <modules>
        <module>gomodule</module>
    </modules>

    <properties>
        <revision>0.0.1-SNAPSHOT</revision>

        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>

        <mvn.golang.version>2.3.7</mvn.golang.version>
        <mvn.golang.module.mode>true</mvn.golang.module.mode>
        <go.sdk.version>1.16.2</go.sdk.version>
    </properties>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>com.igormaznitsa</groupId>
                    <artifactId>mvn-golang-wrapper</artifactId>
                    <version>${mvn.golang.version}</version>
                    <extensions>true</extensions>

                    <configuration>
                        <goVersion>${go.sdk.version}</goVersion>
                        <disableSdkLoad>true</disableSdkLoad>
                        <goRoot>/usr/lib/go</goRoot>
                        <moduleMode>true</moduleMode>
                    </configuration>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>
</project>

This is the child POM that contains basic configuration for the specific module:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>mygroup</artifactId>
        <groupId>mygoproject</groupId>
        <version>${revision}</version>
    </parent>

    <modelVersion>4.0.0</modelVersion>

    <artifactId>gomodule</artifactId>
    <packaging>mvn-golang</packaging>

    <name>Go Module</name>

    <build>
        <sourceDirectory>${basedir}${file.separator}src</sourceDirectory>

        <plugins>
            <plugin>
                <groupId>com.igormaznitsa</groupId>
                <artifactId>mvn-golang-wrapper</artifactId>
                <configuration>
                    <resultName>gomodule</resultName>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

mvn-go-wrapper-error.txt

Expected result

The go.sum file is never deleted during any phase if the Go SDK version is equal or greater 1.16, because the file is not automatically restored.

Actual result

The go.sum file is always deleted during build time, yielding the mentioned error for Go SDK >= 1.16.

Temporary workaround

If the automatic download of the SDK is enabled and the version of the SDK is set to a version prior to 1.16 (namely: 1.15.8), the same configuration works because the missing go.sum file is autimatically handled during build time.

raydac commented 3 years ago

I have turned off default removing of go.sum (it can be still turned on through either <deleteSumFile>true</deleteSumFile> or <mvn.golang.delete.sum.file>true</mvn.golang.delete.sum.file> try please 2.3.8-SNAPSHOT

raydac commented 3 years ago

also in snapshot version added mod property for module aware commands so that it can be changed to <mod>mod</mod> to override default GoSDK 16 behavior readonly

steromano87 commented 3 years ago

Checked with version 2.3.8-SNAPSHOT (updated at commit 9467f6b7b0e8d304b366ea0e78fcd66e35e3b26a) and it works flawlessly using Go SDK 1.16. Now the go.sum file is correctly preserved.