GithubHelp home page GithubHelp logo

doytsujin / gogradle Goto Github PK

View Code? Open in Web Editor NEW

This project forked from innobead/gogradle

0.0 1.0 0.0 159 KB

A Golang plugin for building, testing, dependency management and popular frameworks (gRPC, Gin, Swagger, ...) supported

License: Apache License 2.0

Kotlin 99.55% Makefile 0.45%

gogradle's Introduction

CircleCI

Note: Before using this plugin, please note that there is no test coverage right now, but it will be done in near future.

What is gogradle

A Gradle plugin supports Go module/package build lifecycle, also integrate go modules started from Go 1.11 for dependency management.

Installation

https://plugins.gradle.org/plugin/com.pivotstir.gogradle

plugins {
  id "com.pivotstir.gogradle" version "1.1.3"
}

Tasks

Gogradle tasks
--------------
goBuild - Build Go project
goClean - Clean Go project
goDep - Resolve Go project library and 3rd party tool dependencies
goEnv - Setup Go environment
goGrpc - Generate gRPC and Protobuf code
goSwag - Generate Swagger files for Gin project, supported by github.com/swaggo/gin-swagger
goTest - Test Go project

Configurations

build.gradle

go {
    // Change module path from default project name
    pluginConfig.modulePath = ""

    build {
        // extra options/flags of `go build`
        cmdArgs = []
        
        // extra envirnment variables of `go build`
        envs = ["CGO_ENABLED": 0]
        
        // crossplatform build. Default: if empty or not specified, just build for local platform
        osArches = [
            "darwin/amd64", 
            "linux/amd64", 
            "windows/amd64"
        ]
        
        // package paths to build. 
        packagePaths = [
            "./cmd/package1"
            "./cmd/package2"
        ]
    }
    
    dep {
        // extra options/flags of `go get` for downloading package dependencies
        cmdArgs = []
            
        // extra envirnment variables of `go get` for downloading package dependencies
        envs = ["CGO_ENABLED": 0]
        
        // ignore third party tools download like Protobuf, Swaggo
        thirdpartyIgnored = false
        
        // Protobuf version for downloading protobuf toolset. Default: "3.6.1"
        protoVersion = "3.8.0"
        
        // version of https://github.com/swaggo/swag
        swaggoVersion = "1.5.1"
    }
    
    env {
        // go version. Default: "1.12.6"
        version = "1.12"
        
        // use project level go installation. Default: true
        useSandbox = true
    }
    
    grpc {
        // Protobuf schemas root folder. Default: file("proto")
        protoDir = file("proto")
        
        // Append the module path as prefix path of below packages when referenced in other protobuf gnerated stub go files
        referencePackages = []
    }

    test {
        // extra options/flags of `go test`
        cmdArgs = []
            
        // extra envirnment variables of `go test`
        envs = ["CGO_ENABLED": 0]
        
        // ignore folders for testing
        ignoredDirs = ["abc"]
    }

    dependencies {
        build "github.com/golang/[email protected]"
        test "github.com/stretchr/[email protected]"
    }
}

build.gradle.kts

extensions.getByType(GoPluginExtension::class).apply {
    env {
        useSandbox = true
    }

    build {
        packagePaths = listOf("./cmd/package1", "./cmd/package2")
    }

    dep {
        thirdpartyIgnored = false
    }

    dependencies {
        build("github.com/golang/[email protected]")
        test("github.com/stretchr/[email protected]")
    }
}

Go Environment

gralde goenv, setup Go environment in .gogradle

gRPC Support

gralde godep, besides resolving package dependencies, setup environments for popular go frameworks (gRPC, gRPC gateway, Gin-Swagger)

gralde gogrpc, generate gRPC stubs from protobuf schemas and swagger files for gRPC gateway support

Swagger Support

gralde goswag, generate swagger files for Gin-Swagger support

Dependencies Management

gralde godep, resolve packages build/test dependencies in gogradle DSL, then create/update go.mod and download all dependent packages.

Test

gralde gotest, run testing, also support ignored folders and different coverage reports (json, xml). XML is Cobertura compatible.

Custom Go Task

import com.pivotstir.gogradle.tasks.Go

task myTask(type: Go) {
    go("help test", [:])
    go("help build", [:])
}

gogradle's People

Contributors

innobead avatar

Watchers

 avatar

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.