I have two projects:
/myproject
/sharedproject
both of them are managed by dep, I have execute go get -u github.com/golang/dep/cmd/dep
in order to have latest dep version, and run dep ensure
on both projects.
When I run myproject
I get following error:
cannot use op (type *"myproject/vendor/github.com/go-openapi/spec".Operation) as type *"sharedproject/vendor/github.com/go-openapi/spec".Operation
What is wrong and how to fix this?
Looks like the situation is that sharedproject
vendors the github.com/go-openapi/spec
dependency while myproject
gets both sharedproject
and github.com/go-openapi/spec
dependencies from
GOPATH
.
Now when you refer to github.com/go-openapi/spec
in sharedproject
, it refers to
the package inside the vendor directory, which is technically different from the
same package in GOPATH
, even if both have the same content. So when you pass a
variable of type *github.com/go-openapi/spec.Operation
from myproject
to a
function in sharedproject
, the package of the type differs from what's expected and compilation fails.
To solve this, make sure sharedproject
is vendored inside myproject
. When
you do this, dep ensure
will put a copy of sharedproject
without its vendor
directory into myproject
's vendor directory. After this, both myproject
and sharedproject
will use the github.com/go-openapi/spec
package from myproject
's vendor directory.
That does make local development hard if you change sharedproject
often and want
to immediately use those changes in myproject
(can't use dep
till the changes are pushed to the Git remote). I'd work around that by copying
over sharedproject
into myproject
's vendor directory manually without using dep
(excluding the vendor directory of course). Be careful to not commit those manually copied changes to Git though!