How can build golang using gradle


(Adinath Ghongadi) #1

Hi,

I am trying to setup the build environment for Go language, I am planning to using gradle for its various advantages.

I need your expertise help to build go language project. I am looking for simple gradle script which can build “Hello World” program written in go language.

i tried to look for link “https://plugins.gradle.org/plugin/org.golang.mobile.bind

I got error: Plugin with id ‘org.golang.mobile.bind’ not found.

Please help me with this.


(Benjamin Muschko) #2

This page shows how to apply the plugin to your build script.


(Adinath Ghongadi) #3

Hi,

Thanks.
I tried plugin mentioned in the page, it gives error.

I got error: Plugin with id ‘org.golang.mobile.bind’ not found.

Below Maven Url mentioned in the page is not exist:

https://plugins.gradle.org/m2/


(Adinath Ghongadi) #4

I tried with below approach.

build.gradle:

plugins {
id “org.golang.mobile.bind” version “0.2.1”
}

gobind {
/* The Go package path; must be under one of the GOPATH elements or
a relative to the current directory (e.g. …/…/hello) */
pkg = “/home/SDL/gocode/src/SDL-SRC”

/* GOPATH where the Go package is; check go env */
GOPATH = “/home/SDL/gocode”

/* Absolute path to the go binary */
GO = “/usr/local/go/bin”

}

I get below error:
What went wrong:
A problem occurred evaluating root project ‘SDL-SRC’.

No signature of method: build_4s3bi4u0rg0mg10bktcmg7ughp$_run_closure1.id() is applicable for argument types: (java.lang.String) values: [org.golang.mobile.bind]

Possible solutions: is(java.lang.Object), is(java.lang.Object), find(), find(), find(groovy.lang.Closure), find(groovy.lang.Closure)


Please help me resolve above issue


(Bo Zhang) #5

Try Gogradle.

It is extremely easy. All you need to do is put

plugins {
    id 'com.github.blindpirate.gogradle' version <the newest version>
}

golang {
    packagePath = 'your/package/path' // path of project to be built 
}

as build.gradle into your project, and run gradle build or ./gradlew build (in this case you need to copy gradlew and related jars into the project dir). No need to set GOPATH, and even no need to pre-install go executables!

Hope that helps.