Hi, Using plugins with modules has become very restrictive. All common dependencies between plugins and binary that loads them, must be exactly at the same version. With GOPATH, to avoid that, we can use vendoring because import paths are rewritten. (Ex: gopkg.yaml.v2 is rewritten to package/sub/vendor/gopkg.in/yaml.v2) But with modules and vendoring, import paths are preserved.
Is this the desired behavior? If so, then the plugins are difficult to use by other users. Maybe it would be possible to accept that module import paths are rewritten for better modularity, even if it increases the number of dependencies? In addition, if the vendoring is removed, this feature will be removed too. Example: main/main.go : to load plugins p1/p1.go : plugin p2/p2.go : like p1.go (only print differs) script.sh : builds plugins using GOPATH, or modules, and prints import path of gopkg.in/yaml.v2 dependency. p1/p1.go package main import ( "fmt" yaml "gopkg.in/yaml.v2" ) var e = yaml.Encoder{} func init() { fmt.Printf("p1: Type: %T\n", e) } func main() {} main/main.go package main import "plugin" func main() { if _, err := plugin.Open("../p1/p1.so"); err != nil { panic(err) } if _, err := plugin.Open("../p2/p2.so"); err != nil { panic(err) } } script.sh #!/bin/bash set -e GOPATH=~/go p1=$PWD/p1 p2=$PWD/p2 main=$PWD/main rm -f $p1/p1.so $p2/p2.so GO111MODULE=on go clean -modcache go clean -cache # init vendoring cd $p1 && GO111MODULE=on go mod vendor cd $p2 && GO111MODULE=on go mod vendor echo -e "package yaml\n\nimport \"fmt\"\nfunc init() { fmt.Println(\"Init yaml (p1)\") }" > $p1/vendor/gopkg.in/yaml.v2/init.go echo -e "package yaml\n\nimport \"fmt\"\nfunc init() { fmt.Println(\"Init yaml (p2)\") }" > $p2/vendor/gopkg.in/yaml.v2/init.go # GOPATH + vendoring echo -n "GOPATH+vendoring:" cd $p1 && GO111MODULE=off go build -buildmode=plugin -n 2>&1 | grep '#' | grep gopkg.in/yaml cd $p1 && GO111MODULE=off go build -buildmode=plugin 2>/dev/null >/dev/null cd $p2 && GO111MODULE=off go build -buildmode=plugin 2>/dev/null >/dev/null cd $main && GO111MODULE=off go run main.go # GOMOD + vendoring echo -n "GOMOD+vendoring:" cd $p1 && GO111MODULE=on go build -buildmode=plugin -mod=vendor -n 2>&1 | grep '#' | grep gopkg.in/yaml cd $p1 && GO111MODULE=on go build -buildmode=plugin -mod=vendor 2>/dev/null >/dev/null cd $p2 && GO111MODULE=on go build -buildmode=plugin -mod=vendor 2>/dev/null >/dev/null cd $main && GO111MODULE=off go run main.go output: go: finding gopkg.in/yaml.v2 v2.2.1 go: finding gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 go: downloading gopkg.in/yaml.v2 v2.2.1 go: finding gopkg.in/yaml.v2 v2.2.0 go: downloading gopkg.in/yaml.v2 v2.2.0 GOPATH+vendoring:# plugin/p1/vendor/gopkg.in/yaml.v2 Init yaml (p1) p1: Type: yaml.Encoder Init yaml (p2) p2: Type: yaml.Encoder GOMOD+vendoring:# gopkg.in/yaml.v2 Init yaml (p1) p1: Type: yaml.Encoder panic: plugin.Open("../p2/p2"): plugin was built with a different version of package gopkg.in/yaml.v2 goroutine 1 [running]: main.main() /home/oszika/go/src/plugin/main/main.go:10 +0x97 exit status 2 Thank you, -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.