atlassian / go-artifactory

Go library for artifactory REST API
Apache License 2.0
23 stars 28 forks source link

dep: unable to solve the dependency graph / mod: error loading module requirements #10

Open universam1 opened 5 years ago

universam1 commented 5 years ago

Describe the bug When I try to include this library, dep errors because of malformed code

To Reproduce

  1. create new go file
  2. import "github.com/atlassian/go-artifactory/artifactory"
  3. run dep init

Expected behavior to resolve this library

Log Output

dep init
init failed: unable to solve the dependency graph: Solving failure: No versions of github.com/atlassian/go-artifactory met constraints:
    v2.2.0: "github.com/atlassian/go-artifactory/artifactory" imports "github.com/atlassian/go-artifactory/v2/artifactory/client", which contains malformed code: no package exists at "github.com/atlassian/go-artifactory/v2/artifactory/client"
    v2.1.1: "github.com/atlassian/go-artifactory/artifactory" imports "github.com/atlassian/go-artifactory/v2/artifactory/client", which contains malformed code: unknown error for "github.com/atlassian/go-artifactory/v2/artifactory/client", if you get this error see https://github.com/golang/dep/issues/351
    v2.1.0: "github.com/atlassian/go-artifactory/artifactory" imports "github.com/atlassian/go-artifactory/v2/artifactory/client", which contains malformed code: unknown error for "github.com/atlassian/go-artifactory/v2/artifactory/client", if you get this error see https://github.com/golang/dep/issues/351
    v2.0.0: "github.com/atlassian/go-artifactory/artifactory" imports "github.com/atlassian/go-artifactory/v2/artifactory/client", which contains malformed code: unknown error for "github.com/atlassian/go-artifactory/v2/artifactory/client", if you get this error see https://github.com/golang/dep/issues/351
    v1.2.0: Could not introduce github.com/atlassian/go-artifactory@v1.2.0, as its subpackage github.com/atlassian/go-artifactory/artifactory is missing. (Package is required by (root).)
    v1.1.0: Could not introduce github.com/atlassian/go-artifactory@v1.1.0, as its subpackage github.com/atlassian/go-artifactory/artifactory is missing. (Package is required by (root).)
    v1.0.1: Could not introduce github.com/atlassian/go-artifactory@v1.0.1, as its subpackage github.com/atlassian/go-artifactory/artifactory is missing. (Package is required by (root).)
    v1.0.0: Could not introduce github.com/atlassian/go-artifactory@v1.0.0, as its subpackage github.com/atlassian/go-artifactory/artifactory is missing. (Package is required by (root).)
    v2.0.0-beta: "github.com/atlassian/go-artifactory/artifactory" imports "github.com/atlassian/go-artifactory/v2/artifactory/v2", which contains malformed code: no package exists at "github.com/atlassian/go-artifactory/v2/artifactory/v2"
    v2.0.0-alpha: Could not introduce github.com/atlassian/go-artifactory@v2.0.0-alpha, as its subpackage github.com/atlassian/go-artifactory/artifactory is missing. (Package is required by (root).)
    v2: "github.com/atlassian/go-artifactory/artifactory" imports "github.com/atlassian/go-artifactory/v2/artifactory/client", which contains malformed code: unknown error for "github.com/atlassian/go-artifactory/v2/artifactory/client", if you get this error see https://github.com/golang/dep/issues/351
    master: Could not introduce github.com/atlassian/go-artifactory@master, as its subpackage github.com/atlassian/go-artifactory/artifactory is missing. (Package is required by (root).)

Desktop (please complete the following information):

dillon-giacoppo commented 5 years ago

A known issue is that this repo is at V2 and has interesting behaviour with go.mod, so as a fix I made the main branch V2 which I think may affect dep. I would like to rebase it and make master the main branch but I need to merge all the outstanding PRs before this can happen - this should fix this. I would note however that this repo guarantees compatibility with the go module system only so YMMV with dep.

dillon-giacoppo commented 5 years ago

Looks like it is an upstream bug https://github.com/golang/dep/issues/1962, https://github.com/golang/dep/issues/2139

Note: creating a new branch is not required. If instead you have been previously releasing on master and would prefer to tag v3.0.0 on master, that is a viable option. (However, be aware that introducing an incompatible API change in master can cause issues for non-modules users who issue a go get -u given the go tool is not aware of semver prior to Go 1.11 or when module mode is not enabled in Go 1.11+). Pre-existing dependency management solutions such as dep currently can have problems consuming a v2+ module created in this way. See for example dep#1962.

https://github.com/golang/go/wiki/Modules#releasing-modules-v2-or-higher

universam1 commented 5 years ago

I'm not sure @dillon-giacoppo how modules should work better, I do get following result "unknown import path \"github.com/atlassian/go-artifactory/artifactory\": cannot find module providing package github.com/atlassian/go-artifactory/artifactory"

Could you please elaborate how this should work as a module?

universam1 commented 5 years ago

if I try to forcefully load the latest module I get the following error:

╰─➤  go get github.com/atlassian/go-artifactory@v2.3.0                                                                                                                                          
go: finding github.com/atlassian/go-artifactory v2.3.0
go: github.com/atlassian/go-artifactory@v0.0.0-20190429001105-3369e1c17e23: go.mod has post-v0 module path "github.com/atlassian/go-artifactory/v2" at revision 3369e1c17e23
go: error loading module requirements

I believe your module setup @dillon-giacoppo is broken

If I start from scratch it only resolves up to 1.2.0

go: finding github.com/atlassian/go-artifactory/artifactory latest
go: extracting github.com/atlassian/go-artifactory v1.2.0
dillon-giacoppo commented 5 years ago

Please checkout my previous comment and attached tickets, dep is not compatible with go modules that use tags to do major versioning (single master branch). This is because the pseudo major version in the module path does not correspond to an actual directory. v1 works because it does not go looking for a v1/ directory.

Modules are now the official way to do dependency management so I don't plan on supporting dep.

universam1 commented 5 years ago

I understand @dillon-giacoppo your point that dep is not supported but you are using module.

Please see above error message that is related to module usage, not dep

dillon-giacoppo commented 5 years ago

Can you please give steps to reproduce. i.e go version, exact command run etc.

universam1 commented 5 years ago

compiled a Dockerfile for your convenience, run docker build .

FROM golang:1.12

WORKDIR /src

RUN echo 'package main\n\
import "github.com/atlassian/go-artifactory/artifactory"\n\
func main() { artifactory.NewClient(client, nil) }\n' > test.go

RUN go mod init test

# also try this:
# RUN go get github.com/atlassian/go-artifactory@v2.3.0

RUN go build .

Try the commented statement too, see how module is unable to resolve the latest version

dillon-giacoppo commented 5 years ago

You are trying to use a major version >= 2 without adding a v2 to the module path. The correct Dockerfile would be

FROM golang:1.12

WORKDIR /src

RUN echo 'package main\n\
import "github.com/atlassian/go-artifactory/v2/artifactory"\n\
func main() { artifactory.NewClient("", nil) }\n' > test.go

RUN go mod init test

# RUN go get github.com/atlassian/go-artifactory/v2 @v2.3.0

RUN go build .

The examples also have correct usage.

HQ1363 commented 4 years ago

I encountered the same problem, really difficult to use, simply unable to install the latest version of the package, directly give up.