GithubHelp home page GithubHelp logo

raydac / mvn-golang Goto Github PK

View Code? Open in Web Editor NEW
161.0 11.0 31.0 102.61 MB

maven plugin to automate GoSDK load and build of projects

License: Apache License 2.0

Java 77.94% Go 14.32% HTML 0.73% CSS 0.18% GLSL 0.06% Mermaid 6.77%
golang mojo maven-plugin java

mvn-golang's Introduction

mvn-golang

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

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
  • fix for seldom error "Can't create temp folder" when building modules concurrently #88
  • default GoSDK version is 1.16.5
  • added autodetect for aarch64 #87

full changelog

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

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

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.10</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 dependencies. 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, 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

<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

mvn-golang's People

Contributors

fmazoyer avatar guillaumecleme avatar hoshposh avatar khmarbaise avatar laurentgo avatar lojian avatar pflynn-virtru avatar raydac avatar sankala-dremio avatar theoderich avatar ttaylor249 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvn-golang's Issues

`go get` from artfactory

Thanks a lot for this plugin.

Many of the artifacts that we use are internal packages which reside in artifactory. Is there a way to configure go get to use artifactory so that packages can also be downloaded from there?

Thanks

Weird artifact generated when trying to compile a github package.

I'm trying to compile a github package, which otherwise woks fine, using mvn-golang-wrapper:

           <execution>
                    <id>build-rice</id>
                    <goals>
                        <goal>build</goal>
                    </goals>
                    <configuration>
                        <verbose>true</verbose>
                        <name>rice</name>
                        <resultName>rice</resultName>
                        <goPath>${basedir}/src/main/go</goPath>
                        <sources>${basedir}/src/main/go</sources>
                        <goVersion>1.8.1</goVersion>
                        <packages>
                            <package>github.com/GeertJohan/go.rice</package>
                        </packages>
                    </configuration>
                </execution>

The source is already in my project directory, so there is no dependency management going on here.

The build mojo executes:

      Build mode : default
      Cached SDK detected : /home/dtrombley/.mvnGoLang/go1.8.1.linux-amd64
      Executable file detected : /home/dtrombley/.mvnGoLang/go1.8.1.linux-amd64/bin/go
      Prepared command line : bin/go build -buildmode=default -o                     
      /home/dtrombley/NetBeansProjects/MyProject//target/rice github.com/GeertJohan/go.rice
      GoLang project sources folder : /home/dtrombley/NetBeansProjects/MyProject/src/main/go

      ....Environment vars....
       $GOROOT = /home/dtrombley/.mvnGoLang/go1.8.1.linux-amd64
       $GOPATH = /home/dtrombley/NetBeansProjects/MyProject/src/main/go:/home/dtrombley/MyProject/src/main/java
       $GOBIN = /home/dtrombley/NetBeansProjects/MyProject/target
       $PATH = /usr/local/bin:/usr/bin:/bin:/opt/bin:/usr/x86_64-pc-linux-gnu/gcc-bin/4.9.3:/usr/local/java/bin:~/netbeans-8.1/bin:/home/dtrombley/go/root/bin:/home/dtrombley/.mvnGoLang/go1.8.1.linux-amd64/bin:/home/dtrombley/NetBeansProjects/MyProject/target
       ........................
       The Result file has been successfuly created : /home/dtrombley/NetBeansProjects/MyProject/target/rice

But then, the thing that was generated is broken and weird:

 dtrombley@snow ~/NetBeansProjects/MyProject/target $ ./rice
 ./rice: line 1: syntax error near unexpected token `newline'
 ./rice: line 1: `!<arch>'
 dtrombley@snow ~/NetBeansProjects/MyProject/target $ file rice
 rice: current ar archive     
 dtrombley@snow ~/NetBeansProjects/MyProject/target $ ar -t rice 
 __.PKGDEF
 _go_.o

Trying to build other packages works just fine. Could it be the '.' character in the package name?

place 'pkg' directory under target

my Go build produces a 'pkg' folder (has a bunch of .a files) sitting at basedir. How can i tell mvn-golang to place it under target dir?

Cannot do crosscompiles because the plugin sets the GOBIN environment regardless

If you change the Go OS and Go Architecture values in the configuration, the go binary will try and do cross compiles. But, this will fail all the time due to the fact that GOBIN is set in the plugin as an environmentvariable as seen at:

https://github.com/raydac/mvn-golang/blob/master/mvn-golang-wrapper/src/main/java/com/igormaznitsa/mvngolang/AbstractGolangMojo.java#L1286

Resulting in:

[ERROR] ---------Exec.Err---------
[ERROR] go install: cannot install cross-compiled binaries when GOBIN is set

goBin is not hornor

Go: 1.7.1
mvn: 3.3.9
this plugin: 2.1.2 (ie latest)

I am trying to configure goBin to use ${project.build.directory}/bin

<configuration>
    <goBin>${project.build.directory}${file.separator}bin</goBin>
    [...]
</configuration>

the outputs always go to ${project.build.directory}

Support for build-helper-maven-plugin

Rather than saving generated artifacts by adding maven-install-plugin declarations, could you detect additional artifacts that are added to the project via the org.codehaus.mojo:build-helper-maven-plugin:attach-artifact plugin goal?

The scenario I am interested in is a multi-platform build storing the generated binaries in the maven repo automatically when mvn clean install is invoked:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>build-helper-maven-plugin</artifactId>
  <executions>
    <execution>
      <id>attach-artifacts</id>
      <phase>package</phase>
      <goals>
        <goal>attach-artifact</goal>
      </goals>
      <configuration>
        <artifacts>
          <artifact>
            <file>${project.build.directory}/${project.artifactId}-${project.version}-win-amd64.exe</file>
            <type>exe</type>
            <classifier>win-amd64</classifier>
          </artifact>

          <artifact>
            <file>${project.build.directory}/${project.artifactId}-${project.version}-linux-amd64.exe</file>
            <type>bin</type>
            <classifier>linux-amd64</classifier>
          </artifact>
          <artifact>
            <file>${project.build.directory}/${project.artifactId}-${project.version}-mac-amd64.bin</file>
            <type>bin</type>
            <classifier>mac-amd64</classifier>
          </artifact>
        </artifacts>
      </configuration>
    </execution>
  </executions>
</plugin>

It appears that the maven-install-plugin:install-file goal will add secondary files to the local repo, but I am not sure that it will handle the deploy lifecycle.

Received fatal alert: access_denied

I am using maven behind an enterprise proxy, and encounter error as the title, the following is the maven log, any idea? thanks
env:
jdk: openjdk version "1.8.0_121"
maven: 3.3.9

log:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Build Order:
[INFO]
[INFO] suite-deployer-adaptor
[INFO] deployer-adaptor-binary
[INFO] itsma-deployer-adaptor
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building suite-deployer-adaptor 2017.11-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ suite-deployer-adaptor ---
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ suite-deployer-adaptor ---
[INFO] Installing /home/danny/src/golang/src/suite-deploy-adaptor/pom.xml to /home/danny/.m2/repository/com/hpe/itsma/suite-deployer-adaptor/2017.11-SNAPSHOT/suite-deployer-adaptor-2017.11-SNAPSHOT.pom
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building deployer-adaptor-binary 2017.11-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ deployer-adaptor-binary ---
[INFO]
[INFO] --- mvn-golang-wrapper:2.1.6:run (default) @ deployer-adaptor-binary ---
[WARNING] Loading list of available GoLang SDKs from https://storage.googleapis.com/golang/
[INFO] ------------------------------------------------------------------------
[INFO] Reactor Summary:
[INFO]
[INFO] suite-deployer-adaptor ............................. SUCCESS [ 0.211 s]
[INFO] deployer-adaptor-binary ............................ FAILURE [ 0.954 s]
[INFO] itsma-deployer-adaptor ............................. SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.572 s
[INFO] Finished at: 2017-12-07T17:19:36+08:00
[INFO] Final Memory: 13M/205M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.igormaznitsa:mvn-golang-wrapper:2.1.6:run (default) on project deployer-adaptor-binary: Received fatal alert: access_denied -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
[ERROR]
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR] mvn -rf :deployer-adaptor-binary

Remove maven-aether-provider / maven-compat

It's better to remove maven-aether-provider´ which limits the compatibility to particular maven versions. Better is to use maven-artifact-transershared component which handles all those cases much easier. This also results in getting rid ofmaven-compat(only for compatibility to Maven 2 needed if you really like to support that which I have my doubts about). It needed to be kept in pom as test scope dependency for maven-plugin-testing-harness. This in consequence would also remove dependency tomaven-artifact`

Can't change branch or tag

I'm trying to use <branch> or <revision> to pin down a package, but failed on a specific one "golang.org/x/sys/windows/registry" where itself is not a Git repo, but a legit go package.

Is there an alternate way?

<execution>
  <id>default-get</id>
  <phase>generate-sources</phase>
  <configuration>
    <autofixGitCache>true</autofixGitCache>
    <packages>
      <package>golang.org/x/sys/windows/registry</package>
    </packages>
    <branch>fb4cac33e3196ff7f507ab9b2d2a44b0142f5b5a</branch>
  </configuration>
  <goals>
    <goal>get</goal>
  </goals>
</execution>
[INFO] ....Environment vars....
[INFO]  $GOROOT = /Users/shiaob/mvn-golang-wrapper-get/.external-resources/go1.8.1.darwin-amd64
[INFO]  $GOPATH = /Users/shiaob/mvn-golang-wrapper-get/target/gopath:/Users/shiaob/mvn-golang-wrapper-get/src/main/java
[INFO]  $GOBIN = /Users/shiaob/mvn-golang-wrapper-get/target
[INFO]  $PATH = /Users/shiaob/bin:/Users/shiaob/tools/bin:/Applications/VMware OVF Tool:/Library/Frameworks/Python.framework/Versions/3.5/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/go/bin:/Users/shiaob/mvn-golang-wrapper-get/.external-resources/go1.8.1.darwin-amd64/bin:/Users/shiaob/mvn-golang-wrapper-get/target
[INFO] ........................
[INFO] Switch 'golang.org/x/sys/windows/registry' to branch = 'fb4cac33e3196ff7f507ab9b2d2a44b0142f5b5a', tag = '_', revision = '_'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.479 s
[INFO] Finished at: 2017-06-27T08:55:31-07:00
[INFO] Final Memory: 10M/245M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.igormaznitsa:mvn-golang-wrapper:2.1.4:get (default-get) on project bar: Can't change branch or tag, see the log for errors! -> [Help 1]

override $GOPATH

I need to use all the system variables but not $GOPATH and I want to add my source directory to my custom GOPATH as well.

So I did this

<useEnvVars>true</useEnvVars>
<env>
       <GOPATH>${basedir}/lib</GOPATH>
</env>
<addToGoPath>
	<mySource>${basedir}</mySource>
</addToGoPath>

If I override $GOPATH,then <addToGoPath> is not working

Could not insert ldFlags

I tried to insert build timestamp through linux command.

            <plugin>
                <groupId>com.igormaznitsa</groupId>
                <artifactId>mvn-golang-wrapper</artifactId>
                <version>2.2.0</version>
                <extensions>true</extensions>
                <configuration>
                    <goVersion>1.9.2</goVersion>
                    <disableSdkDownload>true</disableSdkDownload>
                    <useEnvVars>true</useEnvVars>
                    <env>
                        <GOPATH>${basedir}/../../lib/golib${path.separator}${basedir}</GOPATH>
                    </env>
                    <ldFlags>
                        <flag>"-X main.Buildstamp=`date +%Y%m%d.%H%M%S`"</flag>
                    </ldFlags>
                </configuration>
                <executions>
                    <execution>
                        <id>build_win_64</id>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <resultName>Agent_win_x64.exe</resultName>
                            <targetOs>windows</targetOs>
                            <targetArch>amd64</targetArch>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Then I got this error

[INFO] Prepared command line : bin/go build -buildmode=default -ldflags "-X main.Buildstamp=`date +%Y%m%d.%H%M%S`" -o /root/Branch17/src/Agent/target/Agent_win_x64.exe

[ERROR] ---------Exec.Err---------
[ERROR] # Agent
[ERROR] flag provided but not defined: -X main.Buildstamp
[ERROR] usage: link [options] main.o

but when I run the above Prepared command manually,it builds successfully.

Support for GOARM environment variable

When crosscompiling for ARM, I can set and to set GOOS and GOARCH environment variables, but a similar configuration affecting GOARM is missing. I would like to see that in the next release, as I have to compile for a non-FP ARM, which needs GOARM=5 to be set.

How to resolve dependencies from another folder

For example, if I have the following:
src/hello.go
src/config/config.go
src/utils/utils.go

If config.go depends on utils.go what should the import inside config.go look like so that it finds utils.go?
I am getting a "cannot find package" error when using absolute imports.

Assign ldflags to the build

Im trying to set ldFlags to the build, I cant really find a document on this. I think the maven-golang supports it [1]

I tried as following, but it fails the build

                   <execution>
                        <id>build-for-linux64</id>
                        <goals>
                            <goal>build</goal>
                        </goals>
                        <configuration>
                            <strip>true</strip>
                            <targetOs>linux</targetOs>
                            <targetArch>amd64</targetArch>
                            <resultName>prodcut-linux-amd64/${executable.name}</resultName>
                            <ldFlags>main.prodVersion=3.4.5</ldFlags>
                        </configuration>
                    </execution>

[1]. https://github.com/raydac/mvn-golang/blob/master/mvn-golang-wrapper/src/main/java/com/igormaznitsa/mvngolang/GolangBuildMojo.java#L78

mvn-golang package swallows other packagings

my mvn-golang module produces multiple golang binaries. then I use maven-assembly-plugin to tar them up and have maven to install and deploy to maven repo.

However, this plugin seems to swallow my assembly. please add default maven install and deploy to its build lifecycle

existing install/deploy phase currently bind to

          <install>com.igormaznitsa:mvn-golang-wrapper:mvninstall</install>
          <deploy>com.igormaznitsa:mvn-golang-wrapper:install</deploy>

How to set the name of the executable file

I want to set the name of the executable file, which is getting built. I tried to find the way to do this from pom but couldn't find. Is there a way to do it, if so can you please let me know how.

Could not set goPath in Linux from pom.xml

Hi,
this below code sets 'goPath' in windows.but in linux it doesn't.

				<groupId>com.igormaznitsa</groupId>
				<artifactId>mvn-golang-wrapper</artifactId>
				<version>2.1.1</version>
				<extensions>true</extensions>
				<configuration>
					<target>${basedir}/new</target>
					<goVersion>1.8</goVersion>
					<env>
					<goPath>${basedir}/lib</goPath>
					</env>
					<useEnvVars>true</useEnvVars>
				</configuration>

correctly process stderr output of golang tools if no errors

when use go 1.11.x
config GO111MODULE = on
use go.mod file
when mvn compile, the console output like this:

[ERROR] ---------Exec.Err---------
[ERROR] go: finding github.com/modern-go/reflect2 v1.0.1
[ERROR] go: finding github.com/json-iterator/go v1.1.5

I think this just the go common output, not ERROR
want get help, thanks

How to execute a windows batch command in validation phase?

I tried to run a batch command by following way

<execution>
	<id>set Timestamp</id>
	<goals>
		<goal>custom</goal>
	</goals>
	<phase>validate</phase>
	<configuration>
		<exec>set timestamp=currentTime</exec>
	</configuration>
</execution>

but it was converted to

set timestamp=currentTime.exe

How to execute a windows batch command or linux shell command with this plugin?

mvninstall doesn't seem to work

I am using mvninstall as a goal and the resulted binary (named as the artifact, without .exe) doesn't get copied into local mvn repo. Please advise.

setting a custom name for the build artifact

I tried to use finalName to set a custom artifact name like this :
<finalName>${project.artifactId}-${project.version}-${git.branch}-${git.commit.id.abbrev}</finalName>

git.* variables are made available by a plugin called pl.project13.maven, but whatever I tried, the go build cmdline doesn't interpret the variables and the output file ends up being something like this :
my_project-1.0-SNAPSHOT-${git.branch}-${git.commit.id.abbrev}

Any idea how to achieve what I want ?

cannot run tests

[ERROR] Failed to execute goal com.igormaznitsa:mvn-golang-wrapper:2.0.0:test (default-test) on project myproject: Execution default-test of goal com.igormaznitsa:mvn-golang-wrapper:2.0.0:test failed: String index out of range: -1
-> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal com.igormaznitsa:mvn-golang-wrapper:2.0.0:test (default-test) on project myproject: Execution default-test of goal com.igormaznitsa:mvn-golang-wrapper:2
.0.0:test failed: String index out of range: -1
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:224)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:108)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:76)
at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:116)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:361)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:213)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:157)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.PluginExecutionException: Execution default-test of goal com.igormaznitsa:mvn-golang-wrapper:2.0.0:test failed: String index out of range: -1
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:144)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
... 19 more
Caused by: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
at java.lang.String.substring(String.java:1931)
at com.igormaznitsa.mvngolang.GolangTestMojo.getPackages(GolangTestMojo.java:72)
at com.igormaznitsa.mvngolang.AbstractPackageGolangMojo.getTailArguments(AbstractPackageGolangMojo.java:44)
at com.igormaznitsa.mvngolang.AbstractGolangMojo.prepareExecutor(AbstractGolangMojo.java:1047)
at com.igormaznitsa.mvngolang.AbstractGolangMojo.execute(AbstractGolangMojo.java:863)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:133)
... 20 more

"mvn deploy" doesn't attempt to deploy an artifact to the maven repository

Running mvn deploy I fully expect to have the results of my maven build deployed into our Artifactory but don't get that result with the golang extension present. To be honest, when running mvn install I full expect to get the binary in my ~/.m2/repository/ too but that doesn't happen here either. I understand that its' not necessarily straight forward when trying to harmonize the verbs of the two build systems but these seem pretty major departures from the maven tradition!

How can I add parameter to the go build command, eg. -installsuffix

I want to run a command like "CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -a -installsuffix cgo -v -o docker/idm/target/itom-itsma-idm-initializer-1.0.0-SNAPSHOT docker/idm/src/cmd/main.go"
How can I use this plugin?
If I do not add these parameters "standard_init_linux.go:178: exec user process caused "no such file or directory""

add dependencies to git

Hello

We have a few dependencies that is part of our project. With these dependencies, we would like to add it with the project so during our build process, so it doesn't need to grab it from github or whatever repo it is every single time. We had issues in the past where it would fail the build because it was not able to grab the dependencies.

If I "git add vendor/", this is the output:

warning: adding embedded git repository: project/vendor/src/github.com/akavel/rsrc
hint: You've added another git repository inside your current repository.
hint: Clones of the outer repository will not contain the contents of
hint: the embedded repository and will not know how to obtain it.
hint: If you meant to add a submodule, use:
hint:
hint:   git submodule add <url> project/vendor/src/github.com/akavel/rsrc
hint:
hint: If you added this path by mistake, you can remove it from the
hint: index with:
hint:
hint:   git rm --cached project/vendor/src/github.com/akavel/rsrc
hint:
hint: See "git help submodule" for more information.

Can you help?

go get -t -v .

Hi
I am unable to do a "go get -t -v ." in the source directory of my project.
However, the actual go installed on my machine works fine with this.
But when I try to build using mvn and pom.xml, it gets stuck at this get dependecy.
I am attaching the snippet of my pom.xml for your reference.
Please help!

<execution>
            <id>dependency11</id>
            <goals>
            <goal>get</goal>
            </goals>
         <configuration>
           <buildFlags>
                <flag>-t</flag>
                <flag>-v</flag>
           </buildFlags>
           <packages>
                <package>.</package>
            </packages>
      </configuration>
</execution>

Add ability for maven plugin to obtain GOROOT location

my maven project set the required GO version where mvn-golang automatically download and place GO sdk under ~/.mvngolang

Requesting mvn-golang to push the download GOROOT path to a maven property ( like ${go.root} so I can retrieve it for other purposes

For my case, I need to run another external script which needs the location of my GOROOT (https://github.com/kubernetes/code-generator/blob/master/generate-groups.sh)

if user passes in plugin parameter, mvn-golang should push it into the property as well

threadsafe mvn-golang

My maven multithread build shows this warning

[WARNING] The following plugins are not marked @threadSafe in kubernetes-controller:
[WARNING] com.igormaznitsa:mvn-golang-wrapper:2.3.3-SNAPSHOT

not sure if this plugin is threadsafe, so far it working great for me

if so, please mark it threadsafe where possible

output .exe in bin folder for windows environment

Tried your default archetype on windows 10 environment.
The package goal generates a binary that has no extension.
I had to change the binary file name with .exe extension in order to run it properly.

please fix this.

mvn deploy make can't load package: package

execute command mvn clean deploy ,output mistake
[ERROR] can't load package: package .: no buildable Go source files in /work/go-pro/src ,
[ERROR]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 20.574 s
[INFO] Finished at: 2017-02-07T15:22:26+08:00
[INFO] Final Memory: 40M/455M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.igormaznitsa:mvn-golang-wrapper:2.1.2:install (default-install) on project oss-eureka-sidecar: Process exit code : 1 -> [Help 1]

my app exist /work/go-pro/src/github/test/main.go
how do work?

Unable to build k8s.io dependencies

We are using maven to build an extension app to kubernetes. We tried adding the k8s.io dependency in our pom.xml but it throws below error

[ERROR] ---------Exec.Err---------
[ERROR] can't load package: package k8s.io/apimachinery: no Go files in /root/../../../src/k8s.io/apimachinery
[ERROR]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

How to add these dependencies.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.