Skip to content

raydac/gosdk-wrapper-maven-plugin

Repository files navigation

mvn-golang

License Apache 2.0 Java 11.0+ Maven Central Maven 3.8.1+
Arthur's acres sanctuary donation

Changelog

1.1.2 (09-dec-2025)

  • fixed search of appropriate GoSDK site in default AUTO mode #11
  • added forceGoSdkFromPath boolean flag to force search of installed GoSDK folder among folders listed in OS PATH environment variable #10

1.1.1 (30-nov-2025)

  • added cache-sdk mojo to ensure load GoSDK and to provide way to export paths to work folders through inject of maven project properties

1.1.0 (01-nov-2025)

  • improved parsing of SDK list to support many formats and be prepared for load SDK through site instead of store #7

full changelog

What is it?

A simple Maven plugin that automates working with GoSDK in Maven projects. It handles downloading GoSDK, caching it in a specified directory, and invoking its tools.

Originally, there was a project called mvn-golang that provided similar functionality. However, since then, the Go ecosystem has changed significantly. I decided to create a simpler plugin focused solely on downloading and executing GoSDK, removing features related to package installation, repository management, and processing. Now, this is just a Maven plugin dedicated to fetching and running Go tools.

How to build?

Just clone the project and use Maven. Go into the project folder and execute maven command

mvn clean install

if you want to build examples, use

mvn clean install -Pexamples

Mojo description

The generated Maven mojo site.

Examples

Add to a Maven project

The plugin doesn't provide any packaging so you should use one of regular packaging like pom (if you use jar then maven injects a lot of default calls for Java specific plugins). Just add into the maven pom.xml build section

<plugin>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>gosdk-wrapper-maven-plugin</artifactId>
  <version>1.1.2</version>
    <configuration>
      <goVersion>1.25.5</goVersion>
    </configuration>
    <executions>
        <execution>
            <id>go-help</id>
            <goals>
                <goal>execute</goal>
            </goals>
            <configuration>
                <args>
                    <arg>help</arg>
                </args>
            </configuration>
        </execution>
    </executions>
</plugin>

It will automatically download GoSDK and cache it but keep in mind that the plugin makes minimalistic business and it doesn't provide any extra options and environment variables just out of the box, also it doesn't make any installation and deploy of projects.

If you use something else than pom packaging then during build you can see a lot of notifications from standard plugins provided by packaging, they know nothing about Go, so you can just move their execution into none phase by execution id. For instance

<plugins>
    <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <executions>
            <execution>
                <id>default-clean</id>
                <phase>none</phase>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <executions>
            <execution>
                <id>default-jar</id>
                <phase>none</phase>
            </execution>
        </executions>
    </plugin>
</plugins>

If needed to cache a GoSDK and get access to its path

Since 1.1.1 added cache-sdk mojo to ensure load GoSDK and inject paths into Maven project properties. It doesn't make any actions and only loads and unpack a target GoSDK if it is not found among cached ones.

Allowed paths to export

Go SDK path

GoSDK folder path can be written into a named project property if defined parameter propertyGoSdkPath which contains property name. The property will contain absolute path to the target cached GoSDK folder.

Default GOPATH folder

The plugin provides the default GOPATH folder in the cached GoSDK folders and usually it is named as .go_path. It is possible to export the default path into a project property if to define the named property through propertyDefaultGoPath. Keep in mind that it is just default path and another execution can override the default value.

Path to the go tool in cached GoSDK

Every GoSDK contains the GO command file, and it is possible export the path to the executable command file if to define propertyGoCommandPath.

Example of load GoSDK and export paths as properties

<plugin>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>gosdk-wrapper-maven-plugin</artifactId>
  <version>1.1.2</version>
    <configuration>
      <goVersion>1.25.5</goVersion>
    </configuration>
    <executions>
        <execution>
            <id>cache-gosdk-export-paths</id>
            <goals>
                <goal>cache-sdk</goal>
            </goals>
            <configuration>
                <propertyGoSdkPath>go.cached.sdk.path</propertyGoSdkPath>
                <propertyDefaultGoPath>go.default.gopath</propertyDefaultGoPath>
                <propertyGoCommandPath>go.command.path</propertyGoCommandPath>
            </configuration>
        </execution>
    </executions>
</plugin>

Generate Maven project from archetype

There is provided archetype for plugin based maven projects in the maven repository. You can very easily to generate a project through call:

        mvn archetype:generate "-DarchetypeGroupId=com.igormaznitsa" "-DarchetypeArtifactId=gosdk-wrapper-maven-plugin-hello" "-DarchetypeVersion=1.1.2"

GoSDK list site

By default, the plugin uses https://storage.googleapis.com/golang/ to retrieve the list of available Go SDKs.
However, there is a potential risk that Google may restrict anonymous access to this site or move it elsewhere.

To address this, the plugin provides the sdkSite parameter, which allows you to specify a custom URL for the SDK list source.
It also includes several predefined values:

  • AUTO — Load the Go SDK list from the default location.
  • GOOGLE_APIS — Load the Go SDK list from https://storage.googleapis.com/golang/.
  • GOSDK_SITE — Load the Go SDK list from https://go.dev/dl/.

For example, to switch directly to the Go SDK web page, you can configure the plugin as follows:

<plugin>
    <groupId>com.igormaznitsa</groupId>
    <artifactId>gosdk-wrapper-maven-plugin</artifactId>
  <version>1.1.2</version>
    <configuration>
        <sdkSite>GOSDK_SITE</sdkSite>
      <goVersion>1.25.5</goVersion>
    </configuration>
</plugin>

You can also provide a direct URI or even a local file path as the value of sdkSite. The plugin supports multiple formats, including HTML, XML, JSON, and plain text. You can find examples of these formats in the test resources directory.

About

Maven plugin to provide a way to execute GoSDK tools

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors