Home

Awesome

MoonLicense - Gradle

MoonLicense integration into the Gradle build process

Introduction

MoonLicense - Gradle is a plugin for Gradle dedicated to automatically and trasparently:

The plugin is based on its dedicated Java library - MoonLicense. Please, refer to its README and to its javadocs for a detailed explanation of the underlying model.

Installation

To add MoonLicense-Gradle to your project, just include the following lines:

buildscript {
    repositories {
        maven {
            url "https://dl.bintray.com/giancosta86/Hephaestus"
        }
    }

    dependencies {
        classpath "info.gianlucacosta.moonlicense:moonlicense-gradle:LATEST_VERSION"
    }
}

apply plugin: "info.gianlucacosta.moonlicense"

Basic usage

The basic configuration is as simple as:

moonLicense {
    license = apache2

    productInfo {
        productName = "My product"
        inceptionYear = 2015
        copyrightHolder = "The copyright holder"
    }
}

where:

Intermediate configuration

It is possible to declare:

For example:

moonLicense {
    license = apache2

    productInfo {
        productName = "My product"
        inceptionYear = 2015
        copyrightHolder = "The copyright holder"
    }

    includes = [
      /.*\.html?$/: htmlFormat
    ]

    excludes = ["^alpha/", "^beta/"]
}

In this case, when one of the license-related tasks is run, it will affect only the files (in the project tree) ending with .htm or .html, except those in the first-level folders alpha and beta, which will be ignored; for every file included after these checks, the HTML notice format will be employed.

This is true, but with one caveat: files and directories beginning with "." (dot items) will also be ignored by default (it is described later how to change this behaviour).

IMPORTANT: before being passed to the regular expressions, every path will be made:

Advanced configuration

The moonLicense block can contain an arbitrary number of fileSet blocks, having the following form:

moonLicense {
  ...

  fileSet {
    license = ...
    productInfo{ ... }
    includes = ...
    excludes = ...
  }

  ...
}

A few important considerations:

IMPORTANT:

Further settings

These settings only apply to the moonLicense block:

Default configuration

For both moonLicense and fileSet blocks:

moonLicense also has a few more defaults:

Provided licenses

The following keywords can be used to reference a license:

Don't forget that you can use, for example, the new operator to instantiate your custom licenses based on MoonLicense.

Provided formats

The following keywords introduce the default notice formats:

In this case as well, you can define your own formats - for both other languages and custom notice outputs - just by using the API provided by MoonLicense.

Special thanks

Special thanks to great tools which I used a lot and which inspired my work: