Go Gradle Plugin

The Go Gradle plugin lets you run Go as part of your build.

The plugin has been successfully tested with Gradle 3.5.1 up to 4.10.2.

Usage

To use the plugin, include it in your build script:

buildscript {
    dependencies {
        classpath group: "com.liferay", name: "com.liferay.gradle.plugins.go", version: "1.0.0"
    }

    repositories {
        maven {
            url "https://repository-cdn.liferay.com/nexus/content/groups/public"
        }
    }
}

apply plugin: "com.liferay.go"

Project Extension

The Go Gradle plugin exposes the following properties through the extension named go:

Property NameTypeDefault ValueDescription
goDirFile"${project.buildDir}/go"The directory where the Go distribution is unpacked.
goUrlString"https://dl.google.com/go/go${go.goVersion}.${platform}-${bitMode}.${extension}The URL of the Go distribution to download.
goVersionString"1.11.4"The Go distribution’s version to use.
workingDirFile"${project.projectDir}"The directory that contains the project’s Go source code.

Tasks

The plugin adds a series of tasks to your project:

NameDepends OnTypeDescription
downloadGo-DownloadGoTaskDownloads and unpacks the local Go distribution for the project.
goBuild${programName}downloadGoExecuteGoTaskCompiles packages and dependencies for the Go program.
goClean${programName}downloadGoExecuteGoTaskRemoves object files for the Go program.
goRun${programName}downloadGoExecuteGoTaskCompiles and runs the Go program.
goTest${programName}downloadGoExecuteGoTaskTests packages for the Go program.

DownloadGoTask

The purpose of this task is to download and unpack a Go distribution.

Task Properties

Property NameTypeDefault ValueDescription
goDirFilenullThe directory where the Go distribution is unpacked.
goUrlStringnullThe URL of the Go distribution to download.

The File type properties support any type that can be resolved by project.file. Moreover, it is possible to use Closures and Callables as values for the String properties, to defer evaluation until task execution.

ExecuteGoTask

This is the base task to run Go in a Gradle build. All tasks of type ExecuteGoTask automatically depend on downloadGo.

Task Properties

Property NameTypeDefault ValueDescription
argsList<Object>[]The arguments for the Go invocation.
commandString"go"The file name of the executable to invoke.
environmentMap<Object, Object>[]The environment variables for the Go invocation.
inheritProxybooleantrueWhether to set the http_proxy, https_proxy, and no_proxy environment variables in the Go invocation based on the values of the system properties https.proxyHost, https.proxyPort, https.proxyUser, https.proxyPassword, https.nonProxyHosts, https.proxyHost, https.proxyPort, https.proxyUser, https.proxyPassword, and https.nonProxyHosts. If these environment variables are already set, their values will not be overwritten.
goDirFilego.goDir](#godir)The directory that contains the executable to invoke.
useGradleExecboolean

If running in a Gradle Daemon: true

Otherwise: false

Whether to invoke Go using project.exec, which can solve hanging problems with the Gradle Daemon.
workingDirFilego.workingDir](#workingdir)The working directory to use in the Go invocation.

The File type properties support any type that can be resolved by project.file. Moreover, it is possible to use Closures and Callables as values for the String properties to defer evaluation until task execution.

Task Methods

MethodDescription
ExecuteGoTask args(Iterable<?> args)Adds arguments for the Go invocation.
ExecuteGoTask args(Object... args)Adds arguments for the Go invocation.
ExecuteGoTask environment(Map<?, ?> environment)Adds environment variables for the Go invocation.
ExecuteGoTask environment(Object key, Object value)Adds an environment variable for the Go invocation.

go$$ Task

For each Go program in workingDir, four tasks of type ExecuteGoTask are added. Each of these tasks are automatically configured with sensible defaults:

Property NameDefault Value
args["${command}", "${programFile.absolutePath}"]
¿Fue útil este artículo?
Usuarios a los que les pareció útil: 0 de 0