GithubHelp home page GithubHelp logo

rockdell / gradle-dotnet-plugin Goto Github PK

View Code? Open in Web Editor NEW

This project forked from itiviti/gradle-dotnet-plugin

0.0 0.0 0.0 203 KB

Gradle plugin for interacting with dotnet cli

License: Apache License 2.0

Groovy 16.10% C# 13.28% Kotlin 70.62%

gradle-dotnet-plugin's Introduction

Gradle Dotnet Plugin Build Status GitHub release (latest by date) License

This plugin allows executing dotnet cli commands for building dotnet projects. It supports only project with sdk format.

Supported tasks are

  • dotnetClean
  • dotnetBuild
  • dotnetTest
  • dotnetNugetPush
  • dotnetInstallSonar
  • sonarqube

It also supports project file parsing, and some basic up-to-date checks to skip the build. You can access the properties via project.dotnet.allProjects and project.dotnet.mainProject. dotnet restore will be done at project evaluation phase to make sure all project properties can be retrieved.

Plugin applies the LifecycleBasePlugin automatically, and hooks tasks to standard lifecycle, such as clean, assemble and build. if publising plugin is applied, dotnetNugetPush task will hook on publish

Prerequisites

  • .Net Core SDK 3.1 / .Net 5.0 / .Net 6.0
  • Gradle 6.1

To Apply

plugins {
    id 'com.itiviti.dotnet'
}

or

buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }

    dependencies {
        classpath 'com.itiviti.gradle:gradle-dotnet-plugin:1.6.1'
    }
}

apply plugin: 'com.itiviti.dotnet'

Configuration

For finding all available options and explanations, please refer to src/main/kotlin/com/itiviti/extensions/

dotnet {
    // where dotnet sdk is installed, default is to use the one specified in PATH
    dotnetExecutable = 'dotnet'

    // the workingDir of the dotnet cli, default is the current directory
    workingDir = '.'

    // the solution / csproj to be built, it will search the workingDir if not specified
    solution = 'my-solution.sln'

    // configuration to be used, default is Release
    configuration = 'Release'

    // Log verbosity of dotnet command
    verbosity = 'Normal'

    // Stop builds if pre-release is detected, can be used when building release build, default is false
    preReleaseCheck = false

    restore {
        // Specifies to not cache packages and HTTP requests.
        noCache = false

        // Forces all dependencies to be resolved even if the last restore was successful. Specifying this flag is the same as deleting the project.assets.json file.
        force = false

        // Delay dotnet restore until dotnetBuild rather than in evaluation phase, could lead to missing project properties due to missing dependencies
        beforeBuild = false
    }

    build {
        // Any build parameter to be passed to msbuild, as /p:key=value, for example
        maxCpuCount = ''

        // Default values applied
        version = project.version
        packageVersion = project.version
    }

    test {
        // filter test to be executed, or use command arguments --dotnet-tests to override (similar to --tests)
        filter = ''

        // test run settings file, no default value
        settings = file(".runsettings")

        // collect code coverage via coverlet, default is true
        collectCoverage = true

        // coverlet output formats, default is opencover
        coverletOutputFormat = 'opencover'

        // [sonar aware] coverlet output path, it must be a directory, default is build/reports/coverlet/
        coverletOutput = file('build/reports/coverlet/')

        nunit {
            // [sonar aware] nunit output path, default is build/reports/nunit/
            testOutputXml = file('build/reports/nunit/')
        }
    }

    nugetPush {
        // The API key for the server.
        apiKey = ''
        // Nuget feed url, default is DefaultPushSource in Nuget config if not set
        source = ''
    }

    sonarqube {
        // version of dotnet-sonarscanner to be installed as global dotnet tool, default is latest
        version = '3.7.1'
    }
}

Sonarqube

Follows the same configuration syntax as the Sonar Scanner for Gradle plugin.

Example usage

plugins {
    id 'com.itiviti.dotnet-sonar'
}

sonarqube {
    properties {
        property 'sonar.projectKey', 'my.project.key'
        property 'sonar.language', 'cs'
        property 'sonar.host.url', 'https://my-sonar'
    }
}

Note:

  • when sonar.projectKey is not set, it will use the project name as project key.
  • sonar.cs.nunit.reportsPaths and sonar.cs.opencover.reportsPaths are set automatically base on dotnet configuration

Troubleshoot

dotnet pack

It is not supported, recommended adding <GeneratePackageOnBuild>true</GeneratePackageOnBuild> to your csproj

dotnet test

To run testing successfully, make sure you have the following packages referenced

  • Microsoft.NET.Test.Sdk
  • NUnit3TestAdapter (or other relevant adapter)

To have coverage report from coverlet, make sure

  • DebugType is set to Portable
  • Add package reference coverlet.msbuild or coverlet.collector (.net core only, for details please refer to coverlet)

gradle-dotnet-plugin's People

Contributors

ngyukman avatar kitsunealex avatar al-dragan 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.