magefile / mage

a Make/rake-like dev tool using Go
https://magefile.org
Apache License 2.0
4.02k stars 250 forks source link

Mage fails if you run it in module mode w/o go.mod #235

Open natefinch opened 5 years ago

natefinch commented 5 years ago

If you run mage in a package outside gopath (i.e. using modules), when it tries to run go list to determine the files it needs to build, go list will fail with "go: cannot determine module path for source directory" . This then causes mage to fail with "unable to determine magefiles".

This can be fixed by having mage create a go.mod with just module magefile inside it... but then the go tool will hit the internet to look for the latest version of whatever imports you have. But that's probably better than just failing.

omadawn commented 4 years ago

I am currently experiencing this issue. I don't fully understand your workaround because I already have a go.mod file for the go code I'm building.

Is there a way to maintain two separate go.mod files without forcing the root of my project and the root of my code to be different?

natefinch commented 4 years ago

if there's already a go.mod in the folder tree you're working in (either in the same directory or a parent directory), then this doesn't apply. The only place it would apply is if you want to be able to run mage on a file where there's no go.mod and it's outside gopath.

leighst-anchorage commented 1 year ago

Kind of hurts the magefile for non- golang use case. I get I can use a magefiles directory, but would still be nice to find some workaround.

natefinch commented 1 year ago

We can probably have mage create the go.mod and go.sum if they don't exist. I think they would need to stick around and not get auto-deleted, though, since most go tooling won't work without them.