Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Looking for mvn-golang example with multi-module using go-module dependency management #60

Closed
dantran opened this issue Jul 3, 2019 · 18 comments
Assignees
Labels

Comments

@dantran
Copy link

dantran commented Jul 3, 2019

My apology if this is asked at the wrong place.

basically my go-module A depends on mvn-golang package B, and mvn build fails with

 cannot find module providing package xxxxxx/yyyyyy  

xxxxx/yyyy is from my mvn-golang dependency

and xxxx/yyyy does show up under target/.dep/ dir

I do have GO111MODULE = on

@raydac
Copy link
Owner

raydac commented Jul 3, 2019

I have a multi-module example among examples. Am I correct that you have both maven dependencies and golang module dependencies in your project?

@raydac raydac self-assigned this Jul 3, 2019
@dantran
Copy link
Author

dantran commented Jul 3, 2019

Yes that is the example, without using mvn-golang dependency and with GO111MODULE=on

@raydac
Copy link
Owner

raydac commented Jul 5, 2019

making some experiments but still no success, single module works well but multi-module still can't process "on" , golang team made very strange stupid implementation of module mechanism. internet full of messages "how to read another module from local folder?!" and there is still no good answer for the question

@raydac raydac added the bug label Jul 5, 2019
@dantran
Copy link
Author

dantran commented Jul 6, 2019

Thank you for looking into this. I am able to create a POC

  • Use go.mod's 'replace' to provide path to depending module with the maven reactor
  • For external mvn-golang, use go.mod's 'replace' to provide path to depending module under target/.dep/artifact-xxxx/. This is not clean, but it works. Another way is use maven-dependency-plugin to unpack 'mvn-golang' dependencies to ${goPath}

@raydac
Copy link
Owner

raydac commented Jul 6, 2019

yes, it looks like that auto-generation of replacement in go.mod is only way to get it working, I will try today to make some autogenerator
replacement directly to depending module will not be working because sources and resources can be situated in different folders, not only in src, but with __dep__ it can work

@raydac
Copy link
Owner

raydac commented Jul 7, 2019

I have made some experiments with preprocessing of go.mod, it adds replace into all such files with relative path, visually looks good but still can't build with on flag
you can try with 2.3.3-snapshot, just add

  <properties>
    <mvn.golang.preprocess.gomod>true</mvn.golang.preprocess.gomod>
    <mvn.golang.restore.gomod>false</mvn.golang.restore.gomod>
  </properties>

to enable processing and disable removing of generated go.mod after build, may be you can give some recommendations what is wrong in my case

@dantran
Copy link
Author

dantran commented Jul 7, 2019

do you have a sample multi module maven project with GO Module, or I need to come up one?

@raydac
Copy link
Owner

raydac commented Jul 9, 2019

looks like that found some solution, may be today will get working version

@raydac
Copy link
Owner

raydac commented Jul 9, 2019

I made solution and now go.mod files are supported, there is example of maven-module mixed project, to activate module support you should either add <moduleMode>true</moduleMode> into configuration or add project property <mvn.golang.module.mode>true</mvn.golang.module.mode>, GO111MODULE non needed because plugin will turn on the mode and inject this environment value automatically

@dantran
Copy link
Author

dantran commented Jul 13, 2019

How does it work behind the scene?

@raydac
Copy link
Owner

raydac commented Jul 13, 2019

it is preprocessing all go.mod files to provide local paths to dependency modules through replace directive and restore all go.mod files from backup after work

@dantran
Copy link
Author

dantran commented Jul 13, 2019

this works from maven perspective, how it will confuse the IDE which would not be able to reference dependencies. Can we have an option to not restore. I am OK with commit changes of go.mod into source control

@raydac
Copy link
Owner

raydac commented Jul 13, 2019

restoration of go.mod can be turned off if project property mvn.golang.restore.go.mod is false

@dantran
Copy link
Author

dantran commented Jul 14, 2019

I build the provided examples Golang module build with -Dmvn.golang.restore.go.mod=false

do see this log

[WARNING] Restoring of go.mod from backup is disabled

but go.mod are not modified at end of build

also, can you set gitignore for go.sum?

@raydac
Copy link
Owner

raydac commented Jul 14, 2019

I have moved the message into debugging log
processing of git config files (as and IDE options) is out of bound of responsibility of the plugin, I will not be surprised if there is some maven git plugin which allows to modify gitignore

@dantran
Copy link
Author

dantran commented Jul 14, 2019

i am expecting go.mod updated by mvn-golang, but sofar i dont see any update

just want to see how you manage to get multi maven modules working with Go mod

@raydac
Copy link
Owner

raydac commented Jul 14, 2019

if you have maven mvn-golang dependencies to golang modules then your go.mod will be temporary changed from (example)

module main

require (
	com.igormaznitsa/testmixproxy v1.0.0
	com.igormaznitsa/testmixterminal v1.0.0
)

to

module main
require com.igormaznitsa/testmixproxy v1.0.0
require com.igormaznitsa/testmixterminal v1.0.0
replace com.igormaznitsa/testmixproxy => ../bin/.__deps__/mvn-go-test-mix-proxy-1.0.0-SNAPSHOT/src/com.igormaznitsa/testmixproxy
replace com.igormaznitsa/testmixterminal => ../bin/.__deps__/mvn-go-test-mix-terminal-1.0.0-SNAPSHOT/src/com.igormaznitsa/testmixterminal

in the end of work go.mod will be restored to the original one
if you want keep changes after work then use -Dmvn.golang.restore.go.mod=false as parameter of command line in maven or provide it as project property (but in the case you have to remove backup version else it will be restored automatically before work), keep changed file is very strange because paths to dependencies can be changed and it should be refreshed every time

@dantran
Copy link
Author

dantran commented Jul 14, 2019

Now I see why you have to restore go.mod file. I have developers :) insist on working with Go command line instead of maven. The only way is to setup go.mod and commit to source control. Best i can do is to have them run maven the first time to populate dependencies, then run Go and cli

@raydac raydac closed this as completed Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants