Command 'go mod tidy' fails to include plugin due to an ambigious import
Trying to run command
env XCADDY_GO_BUILD_FLAGS="-modcacherw" \
${RECIPE_SYSROOT_NATIVE}${bindir}/xcaddy build ${SRCREV} \
--with github.com/greenpau/[email protected]
fails due to an error message
| 2022/08/16 06:27:51 [INFO] exec (timeout=0s): /work/yocto/build/tmp/work/armv8a-poky-linux/caddy/2.5.2-r0/recipe-sysroot-native/usr/bin/go mod tidy -modcacherw
| go: downloading github.com/google/go-cmp v0.5.7
| go: downloading github.com/smallstep/assert v0.0.0-20200723003110-82e2b9b3b262
| go: downloading github.com/stretchr/testify v1.7.1
| go: downloading gopkg.in/yaml.v2 v2.4.0
| go: downloading go.uber.org/goleak v1.1.12
| go: downloading github.com/golang/mock v1.6.0
| go: downloading github.com/onsi/gomega v1.13.0
| go: downloading gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c
| go: downloading golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
| go: downloading github.com/benbjohnson/clock v1.1.0
| go: downloading github.com/aws/aws-sdk-go v1.37.0
| go: downloading cloud.google.com/go/kms v1.4.0
| go: downloading github.com/googleapis/gax-go/v2 v2.1.1
| go: downloading google.golang.org/api v0.70.0
| go: downloading github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1
| go: downloading github.com/cockroachdb/apd v1.1.0
| go: downloading github.com/gofrs/uuid v4.0.0+incompatible
| go: downloading github.com/go-stack/stack v1.8.0
| go: downloading github.com/jackc/pgmock v0.0.0-20210724152146-4ad1a8207f65
| go: downloading github.com/lib/pq v1.10.2
| go: downloading github.com/chzyer/logex v1.1.10
| go: downloading gotest.tools v2.2.0+incompatible
| go: downloading cloud.google.com/go v0.100.2
| go: downloading github.com/googleapis/gax-go v2.0.2+incompatible
| go: downloading github.com/pmezard/go-difflib v1.0.0
| go: downloading github.com/OneOfOne/xxhash v1.2.2
| go: downloading github.com/spaolacci/murmur3 v1.1.0
| go: downloading github.com/kr/pretty v0.3.0
| go: downloading github.com/davecgh/go-spew v1.1.1
| go: downloading github.com/rogpeppe/go-internal v1.8.0
| go: downloading github.com/kr/text v0.2.0
| go: downloading cloud.google.com/go/iam v0.1.0
| go: downloading github.com/jmespath/go-jmespath v0.4.0
| go: downloading golang.org/x/oauth2 v0.0.0-20211104180415-d3ed0bb246c8
| go: downloading cloud.google.com/go/compute v1.3.0
| go: downloading go.opencensus.io v0.23.0
| go: downloading google.golang.org/appengine v1.6.7
| go: downloading github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da
| go: downloading github.com/Masterminds/sprig v2.22.0+incompatible
| go: downloading github.com/Masterminds/semver v1.5.0
| go: downloading github.com/cpuguy83/go-md2man v1.0.10
| go: downloading github.com/jackc/pgproto3 v1.1.0
| go: downloading github.com/jackc/chunkreader v1.0.0
| caddy imports
| github.com/greenpau/caddy-security imports
| github.com/caddyserver/caddy/v2/modules/caddyhttp imports
| github.com/google/cel-go/parser imports
| github.com/antlr/antlr4/runtime/Go/antlr loaded from github.com/antlr/antlr4/runtime/Go/[email protected],
| but go 1.16 would fail to locate it:
| ambiguous import: found package github.com/antlr/antlr4/runtime/Go/antlr in multiple modules:
| github.com/antlr/antlr4 v0.0.0-20200503195918-621b933c7a7f (/work/yocto/build/tmp/work/armv8a-poky-linux/caddy/2.5.2-r0/build/pkg/mod/github.com/antlr/[email protected]/runtime/Go/antlr)
| github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20220816024939-bc8df83d7b9d (/work/yocto/build/tmp/work/armv8a-poky-linux/caddy/2.5.2-r0/build/pkg/mod/github.com/antlr/antlr4/runtime/!go/[email protected])
|
| To proceed despite packages unresolved in go 1.16:
| go mod tidy -e
| If reproducibility with go 1.16 is not needed:
| go mod tidy -compat=1.17
| For other options, see:
| https://golang.org/doc/modules/pruning
| 2022/08/16 06:27:59 [INFO] Cleaning up temporary folder: /tmp/buildenv_2022-08-16-0627.2744968765
| 2022/08/16 06:27:59 [FATAL] exit status 1
This seems to be related to a known issue related to go compiler 1.17. My environment is using go version 1.17.8.
I tried building the same plugin with more recent version 1.1.14 and received the same error.
The xcaddy does not support passing arguments to go mod tidy, which could resolve this issue for me so I could pass the -compat=1.17 to the command. The other solution that comes to mind would be to upgrade to go 1.18 but that will require more work than enforcing the compatibility.
Please use Go 1.18 or 1.19. At this point, we can't support Go 1.17 anymore. The next release of Caddy will be minimum 1.18.
We're aware of this issue but the answer really is just "upgrade Go".
Does this still happen if you use Go 1.18+ @akeskimo ?
I can try. It will require backporting recipes from the next release branch. I can comment on the issue whether it helps or not.
I'm certain it will work. We've seen this before. For example:
https://caddy.community/t/building-caddy-2-5-2-with-cgiv2-fails/16663/6
I backported to go version 1.19 and I was able to run our frontend with the plugin enabled. Thanks a lot!
That's great, thanks @akeskimo !