Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/raydac/mvn-golang
maven plugin to automate GoSDK load and build of projects
https://github.com/raydac/mvn-golang
golang java maven-plugin mojo
Last synced: about 1 month ago
JSON representation
maven plugin to automate GoSDK load and build of projects
- Host: GitHub
- URL: https://github.com/raydac/mvn-golang
- Owner: raydac
- License: apache-2.0
- Created: 2016-03-24T06:47:08.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-02-21T00:16:18.000Z (11 months ago)
- Last Synced: 2024-07-31T20:52:38.403Z (6 months ago)
- Topics: golang, java, maven-plugin, mojo
- Language: Java
- Homepage:
- Size: 100 MB
- Stars: 161
- Watchers: 11
- Forks: 31
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - mvn-golang - plugin that provides way for auto-loading of Golang SDK, dependency management and start build environment in Maven project infrastructure. (Package Management / HTTP Clients)
- zero-alloc-awesome-go - mvn-golang - plugin that provides way for auto-loading of Golang SDK, dependency management and start build environment in Maven project infrastructure. (Package Management / HTTP Clients)
README
![mvn-golang](assets/git_banner.png)
[![License Apache 2.0](https://img.shields.io/badge/license-Apache%20License%202.0-green.svg)](http://www.apache.org/licenses/LICENSE-2.0)
[![Java 8.0+](https://img.shields.io/badge/java-8.0%2b-green.svg)](http://www.oracle.com/technetwork/java/javase/downloads/index.html)
[![Maven central](https://maven-badges.herokuapp.com/maven-central/com.igormaznitsa/mvn-golang-wrapper/badge.svg)](http://search.maven.org/#artifactdetails|com.igormaznitsa|mvn-golang-wrapper|2.3.10|jar)
[![Maven 3.0.3+](https://img.shields.io/badge/maven-3.0.3%2b-green.svg)](https://maven.apache.org/)
[![PayPal donation](https://img.shields.io/badge/donation-PayPal-cyan.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=AHWJHJFBAWGL2)
[![YooMoney donation](https://img.shields.io/badge/donation-Yoo.money-blue.svg)](https://yoomoney.ru/to/41001158080699)# Changelog
__2.3.10 (08-jun-2022)__
- updated dependencies
- default GoSDK version is 1.19__2.3.9 (04-jul-2021)__
- fix for clean fail for multi-module project if some artifacts
unresolvable [#90](https://github.com/raydac/mvn-golang/issues/90)
- fix for seldom error "Can't create temp folder" when building modules
concurrently [#88](https://github.com/raydac/mvn-golang/issues/88)
- default GoSDK version is 1.16.5
- added autodetect for aarch64 [#87](https://github.com/raydac/mvn-golang/issues/87)[full changelog](https://github.com/raydac/mvn-golang/blob/master/CHANGELOG.md)
# GO start!
__Taste Go in just two commands!__
```
mvn archetype:generate -B -DarchetypeGroupId=com.igormaznitsa -DarchetypeArtifactId=mvn-golang-hello -DarchetypeVersion=2.3.10 -DgroupId=com.go.test -DartifactId=gohello -Dversion=1.0-SNAPSHOT
mvn -f ./gohello/pom.xml package
```
The First command in th snippet above generates a maven project with some test files and the second command builds the project.
[Also you can take a look at the example `Hello world` project using the plugin](https://github.com/raydac/mvn-golang-example)If you want to generate a multi-module project, then you can use such snippet
```
mvn archetype:generate -B -DarchetypeGroupId=com.igormaznitsa -DarchetypeArtifactId=mvn-golang-hello-multi -DarchetypeVersion=2.3.10 -DgroupId=com.go.test -DartifactId=gohello-multi -Dversion=1.0-SNAPSHOT
```# Introduction
The Plug-in just wraps Golang tool-chain and allows to use strong maven based infrastructure to build Golang projects. It also can automatically download needed Golang SDK from the main server and tune needed version of packets for their branch, tag or revisions.
Because a Golang project in the case is formed as just maven project, it is possible to work with it in any Java IDE which supports Maven.
![mvn-golang-wrapper](https://raw.githubusercontent.com/raydac/mvn-golang/master/assets/doc_common.png)# How it works
On start the plug-in makes below steps:
- analyzing the current platform to generate needed distributive name (it can be defined directly through properties)
- check that needed Golang SDK is already cached, if it is not cached then needed SDK will be loaded and unpacked from the main Golang SDK site
- execute needed go lang tool `bin/go` with defined command, the source folder will be set as current folder
- all folders of the project which are visible for maven (source folder, test folder, resource folders and test resource folders) are archived in ZIP file and the file is saved as a maven artifact into local maven repository (or remote maven repository). The generated ZIP artifact also contains information about dependencies which can be recognized by the plugin. In opposite to Java, Golang produces platform-dependent artifacts so that it doesn't make sense to share them through maven central but only resources and sources.# How to build
Because it is maven plugin, to build the plugin just use
```
mvn clean install -Pplugin
```
To save time, examples excluded from the main build process and activated through special profile
```
mvn clean install -Pexamples
```
# Important note about automatic Golang SDK load
If you have some problems with certificates during Golang SDK load, then just add `true` into plugin configuration to ignore check of certificates (also you can use property 'mvn.golang.disable.ssl.check'). Also it allows property `mvn.golang.disable.ssl.check` to disable SSL certificate check during network actions.# How to add the plugin into maven project?
Below described build section for simple golang project which keeps source in `src` forlder and result should be placed into `bin` folder. Because it is golang project and mvn-golang plugin provides its own lifecycle, packaging for the project should be `mvn-golang````xml
${basedir}${file.separator}src
${basedir}${file.separator}bin
com.igormaznitsa
mvn-golang-wrapper
2.3.10
true
run
main.go
```
# Work with dependencies## Dependencies from Maven repository (since 2.3.0)
Plugin supports work with maven repository and can install and load dependencies from there. Artifacts generated by the plugin saved in maven respository as zip archives and `mvn-golang` must be used as `type`.
```xmlcom.igormaznitsa
mvn-go-test-lib
1.0.0-SNAPSHOT
mvn-golang```
Plugin makes some trick in work with Maven Golang dependencies, it downloads Golang artifacts from repository and unpack them into temporary folder, then all unpacked dependencies are added to `$GOPATH`. You can take a look at [example project which has two level dependency hierarchy](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-maven-repository).
Dependency mechanism is enabled by default for all goals which need it, but it can be off with `false`. If there is any conflicts or errors in Golang for Go modules then you can turn off Go modules with
```xmloff
```
__Keep in mind that it is impossible use links to Github and Bitbucket libraries through `` maven mechanism, links to such dependencies should be processed by standard `GET` command and information about it you can find below.__## Support of Module mode
Since 2.3.3 version, plug-in supports Golang module mode and allows to mix modules and work with golang maven dependencies, [I have made some sample to show the possibility](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-maven-module-mix). By default support of module mode is turned off, but it can be turned on through `true` or property `mvn.golang.module.mode`.
## Wrapped GET command
Plugin provides wrapper for Golang GET command and you can just define some external file contains package info through
system property `mvn.golang.get.packages.file`, the file will be loaded and parsed and its definitions will be added
into package dependencies. Format of the file is very easy. Each package described on a line in
format `package: [,branch: ][,tag: ][,revision: ]` also it supports single line
comments through `//` and directive `#include ` to load packages from some external file. Also it supports
interpolation of properties defined in format `${property.name}` and provide access to maven, system and environment
variables.
Example:```
// example package file
#include "${basedir}/external/file.txt"
package:github.com/maruel/panicparse,tag:v1.0.2 // added because latest changes in panicparse is incompatible with termui
package:github.com/gizak/termui,branch:v2
```This mechanism just makes work with dependencies easier and if you want to provide some specific flags and scripts to
process CVS folders you have to define configuration parameters in pom.xml, packages defined in the external file and in
the pom.xml will be mixed.The Plug-in doesn't work with standard maven dependencies and they must be defined through task of the plugin, the
example of easiest case of dependencies is
```xmldefault-get
github.com/gizak/termui
github.com/kataras/iris
```
it will be executed as `bin/go get github.com/gizak/termui github.com/kataras/iris`If you want work with specific branch then use below snipet
```xmldefault-get
-u
github.com/gizak/termui
v2
```
if you want to have several dependencies with different tag and branch then take a look at the snipet below
```xmldependency1
get
github.com/some/framework
1.0.1
dependency2
get
github.com/some/another
v2
```
sometime GIT can produce cache errors and in the case you can try to turn on auto-fix of such errors with `true` flag.# How to save generated artifact in repository?
By default, artifact will be installed into maven repository automatically during `install` phase if you want to turn off artifact installation then you can use standard maven properties
```xmltrue
true```
or disable plugin mojo execution
```xmldefault-mvninstall
none```
# Configuration
About configuration parameters, you can read at [the wiki page](https://github.com/raydac/mvn-golang/wiki/PluginConfigParameters).
# Testing
The Wrapper just wraps calls to Go tool and recognize the exit code, if call of `go test` is non-zero then build will be failed, it doesn't make any analysing of test reports!
Sometime it is useful to use [GoConvey](https://github.com/smartystreets/goconvey) tool for testing, in the case use snippet below to add dependency and make testing verbose
```xmldefault-get
-u
github.com/smartystreets/goconvey
default-test
-v
```# Some Examples
- __[Protobuf use example](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-protobuf)__
- __[Maven repository dependencies example](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-maven-repository)__
- __[Maven repository dependencies together with modules example](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-maven-module-mix)__
- __[Versioning of dependencies](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/test-git-cvs)__
- __["Hello world!" console application.](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-helloworld)__
- __[Console application with embedded text resource prepared with the `go-bindata` utility.](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-genbindata)__
- __[Console application with `termui` library (it needs installation of some native libraries!).](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-termui)__
- __[NES emulator.](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-nes)__
- __[ANTLR usage.](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-antlr)__
- __[Multimodule project.](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-multimodule)__
- __[Preprocessing.](https://github.com/raydac/mvn-golang/tree/master/mvn-golang-examples/mvn-golang-example-preprocessing)__