All Projects → raydac → Mvn Golang

raydac / Mvn Golang

Licence: apache-2.0
A Maven plugin allows to build Go applications with maven

Programming Languages

java
68154 projects - #9 most used programming language
golang
3204 projects

Projects that are alternatives of or similar to Mvn Golang

Groovy Eclipse
Eclipse Groovy Development Tools
Stars: ✭ 567 (+397.37%)
Mutual labels:  maven-plugin
Buildplan Maven Plugin
A Maven 3.x plugin to inspect project lifecyle.
Stars: ✭ 57 (-50%)
Mutual labels:  maven-plugin
Lambda Monitoring
Logging and metrics libraries for AWS Lambda
Stars: ✭ 85 (-25.44%)
Mutual labels:  maven-plugin
Typescript Generator
Generates TypeScript from Java - JSON declarations, REST service client
Stars: ✭ 729 (+539.47%)
Mutual labels:  maven-plugin
Jcabi Dynamodb Maven Plugin
DynamoDB Local Maven Plugin
Stars: ✭ 26 (-77.19%)
Mutual labels:  maven-plugin
Phantomjs Maven Plugin
A maven plugin for installing the phantomjs binary on your system automatically.
Stars: ✭ 62 (-45.61%)
Mutual labels:  maven-plugin
Jflex
The fast scanner generator for Java™ with full Unicode support
Stars: ✭ 380 (+233.33%)
Mutual labels:  maven-plugin
Cucable Plugin
Maven plugin that simplifies running Cucumber Scenarios in parallel.
Stars: ✭ 110 (-3.51%)
Mutual labels:  maven-plugin
Rpm Maven Plugin
Stars: ✭ 52 (-54.39%)
Mutual labels:  maven-plugin
Flatten Maven Plugin
Flatten Maven Plugin
Stars: ✭ 82 (-28.07%)
Mutual labels:  maven-plugin
Javafx Maven Plugin
Maven plugin for JavaFX
Stars: ✭ 764 (+570.18%)
Mutual labels:  maven-plugin
Graphql Java Codegen Maven Plugin
Maven plugin for graphql-java-codegen
Stars: ✭ 17 (-85.09%)
Mutual labels:  maven-plugin
Appassembler
Stars: ✭ 69 (-39.47%)
Mutual labels:  maven-plugin
Jsonschema2pojo
Generate Java types from JSON or JSON Schema and annotate those types for data-binding with Jackson, Gson, etc
Stars: ✭ 5,633 (+4841.23%)
Mutual labels:  maven-plugin
Lombok.maven
Maven Plugin for Project Lombok
Stars: ✭ 89 (-21.93%)
Mutual labels:  maven-plugin
Bnd
Bnd/Bndtools. Tooling to build OSGi bundles including Eclipse, Maven, and Gradle plugins.
Stars: ✭ 446 (+291.23%)
Mutual labels:  maven-plugin
Animal Sniffer
Stars: ✭ 59 (-48.25%)
Mutual labels:  maven-plugin
Jgitver Maven Plugin
maven core extension to automatically define versions using jgitver & git tags
Stars: ✭ 117 (+2.63%)
Mutual labels:  maven-plugin
Kotlin
The Kotlin Programming Language.
Stars: ✭ 39,664 (+34692.98%)
Mutual labels:  maven-plugin
Git Commit Id Maven Plugin
Maven plugin which includes build-time git repository information into an POJO / *.properties). Make your apps tell you which version exactly they were built from! Priceless in large distributed deployments... :-)
Stars: ✭ 1,187 (+941.23%)
Mutual labels:  maven-plugin

mvn-golang

License Apache 2.0 Java 8.0+ Maven central Maven 3.0.3+ PayPal donation YooMoney donation

Changelog

2.3.6 (19-dec-2020)

  • improved restoration of go.mod and go.sum state after build
  • refactoring and minor bugfixing
  • updated dependencies
  • default version of GoSDK updated to 1.15.6

2.3.5 (12-sep-2020)

  • fixed bug in go.mod backup restore #73
  • default version of GoSDK updated to 1.15.2

2.3.4 (05-nov-2019)

  • improved host arch detection #70
  • default version of GoSDK updated to 1.13.4
  • minor refactoring

full changelog

GO start!

Taste Go in just two commands!

mvn archetype:generate -B -DarchetypeGroupId=com.igormaznitsa -DarchetypeArtifactId=mvn-golang-hello -DarchetypeVersion=2.3.6 -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

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.6 -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

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 <disableSSLcheck>true</disableSSLcheck> 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 <packaging>mvn-golang</packaging>

<build>
    <!--Changing standard Maven project source structure to make it Go compatible-->
    <sourceDirectory>${basedir}${file.separator}src</sourceDirectory>
    <directory>${basedir}${file.separator}bin</directory>

    <plugins>
      <plugin>
        <groupId>com.igormaznitsa</groupId>
          <artifactId>mvn-golang-wrapper</artifactId>
          <version>2.3.6</version>
          <extensions>true</extensions>
        <executions>
          <execution>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <packages>
                <package>main.go</package>
              </packages>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
</build>

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.

<dependency>
  <groupId>com.igormaznitsa</groupId>
  <artifactId>mvn-go-test-lib</artifactId>
  <version>1.0.0-SNAPSHOT</version>
  <type>mvn-golang</type>
</dependency>

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. Dependency mechanism is enabled by default for all goals which need it, but it can be off with <scanDependencies>false</scanDependencies>. If there is any conflicts or errors in Golang for Go modules then you can turn off Go modules with

<env>
  <GO111MODULE>off</GO111MODULE>
</env>

Keep in mind that it is impossible use links to Github and Bitbucket libraries through <dependencies> 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. By default support of module mode is turned off, but it can be turned on through <moduleMode>true</moduleMode> 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 depedencies. Format of the file is very easy. Each package described on a line in format package: <PACKAGE_NAME>[,branch: <BRANCH>][,tag: <TAG>][,revision: <REVISION>] also it supports single line comments through // and directive #include <FILE_NAME> 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, pacages 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

<execution>
   <id>default-get</id>
   <configuration>
     <packages>
       <package>github.com/gizak/termui</package>
       <package>github.com/kataras/iris</package>
     </packages>
   </configuration>
</execution>

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

<execution>
  <id>default-get</id>
  <configuration>
    <buildFlags>
    <flag>-u</flag>
    </buildFlags>
    <packages>
      <package>github.com/gizak/termui</package>
    </packages>
    <branch>v2</branch>
  </configuration>
</execution>

if you want to have several dependencies with different tag and branch then take a look at the snipet below

<execution>
  <id>dependency1</id>
  <goals>
    <goal>get</goal>
  </goals>
  <configuration>
    <packages>
      <package>github.com/some/framework</package>
    </packages>
    <tag>1.0.1</tag>
  </configuration>
</execution>
<execution>
  <id>dependency2</id>
  <goals>
    <goal>get</goal>
  </goals>
  <configuration>
    <packages>
      <package>github.com/some/another</package>
    </packages>
    <branch>v2</branch>
  </configuration>
</execution>

sometime GIT can produce cache errors and in the case you can try to turn on auto-fix of such errors with <autofixGitCache>true</autofixGitCache> 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

<properties>
    <maven.install.skip>true</maven.install.skip>
    <maven.deploy.skip>true</maven.deploy.skip>
</properties>

or disable plugin mojo execution

<execution>
  <id>default-mvninstall</id>
  <phase>none</phase>
</execution>

Configuration

About configuration parameters, you can read at the wiki page.

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 tool for testing, in the case use snippet below to add dependency and make testing verbose

<execution>
  <id>default-get</id>
  <configuration>
    <buildFlags>
      <flag>-u</flag>
    </buildFlags>
    <packages>
      <package>github.com/smartystreets/goconvey</package>
    </packages>
  </configuration>
</execution>
<execution>
  <id>default-test</id>
  <configuration>
    <buildFlags>
      <flag>-v</flag>
    </buildFlags>
  </configuration>
</execution>                    

Some Examples

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].