Skip to content

This Gradle plugin provides tasks to generate a HTML / XML / Json file with the licenses used from the libraries.

License

Notifications You must be signed in to change notification settings

chrimaeon/gradle-licenses-plugin

Repository files navigation

Gradle Licenses Plugin Build & Test codecov

License Gradle Plugin MavenCentral gradlePluginPortal

This Gradle plugin provides tasks to generate a file with the licenses used from the project's dependencies.

Usage

Integration

Using the plugins DSL

Kotlin
plugins {
    id("com.cmgapps.licenses") version "4.8.0"
}
Groovy
plugins {
    id 'com.cmgapps.licenses' version '4.8.0'
}

Using legacy plugin application

Kotlin
buildscript {
    repositories {
        maven {
            url = uri("https://plugins.gradle.org/m2/")
        }
    }
    dependencies {
        classpath("com.cmgapps:gradle-licenses-plugin:4.8.0")
    }
}

apply(plugin = "com.cmgapps.licenses")
Groovy
buildscript {
    repositories {
        maven {
            url 'https://plugins.gradle.org/m2/'
        }
    }
    dependencies {
        classpath 'com.cmgapps:gradle-licenses-plugin:4.8.0'
    }
}

apply plugin: 'com.cmgapps.licenses'

Tasks

Applying the plugin will create tasks to generate the license report

For "java" and "java-library"

  • licenseReport

For "com.android.application", "com.android.library", "com.android.feature" and "com.android.dynamic-feature"

  • license<variant>Report

For "org.jetbrains.kotlin.multiplatform"

  • licenseMultiplatformReport collects licenses from all targets
  • licenseMultiplatform<target>Report collects licenses from common and the specified <target>

Configuration

Output Format

Example:

licenses {
    reports {
        html.enabled = false // html is enabled by default
        xml {
            enabled = true
            destination = file("$buildDir/reports/licenses.xml")
        }
    }
}

The plugin can output different formats.

  • HTML generates a formatted HTML website

    • Styling

      For an HTML report you can define custom stylesheet using a File or String:

       licenses {
           reports {
               html.stylesheet("body {background: #FAFAFA}")
           }     
       }

      or

      licenses {
          reports {
              html.stylesheet(file("$projectDir/styles/licenses.css"))
          } 
      }
    • On the default CSS style Dark Mode for supported browsers is also enabled by default. It adds a <meta name="color-scheme" content="dark light"> and a custom css theme.

      It can be disabled via

      licenses {
          reports {
              html.useDarkMode.set(false)
          }
      }
  • JSON generates a JSON file

  • XML generates a valid XML version 1.0 file

  • Text generates a plain text report file

  • Mardown generates a Markdown file

  • Custom add your own reporter as a lambda function

    Kotlin
      licenses {
          custom {
              enabled = true
              destination = buildDir.resolve("reports").resolve("licenses.txt")
              generate { list -> list.map { it.name }.joinToString() }
          }
      }
    Groovy
      licenses {
          custom {
              enabled = true
              destination = file("$buildDir/reports/licenses/licenses.txt")
              generate { list -> list.collect { it.name }.join(', ') }
          }
     }

Multi-project Builds

For multi-project build, you can add projects you want to collect license information from in the main project.

Kotlin
licenses {
    additionalProjects(":module2", ":module3")
}
Groovy
licenses {
    additionalProjects ':module2', ':module3'
}

License

Copyright (c) 2018. Christian Grach <[email protected]>

SPDX-License-Identifier: Apache-2.0