Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chrimaeon/gradle-licenses-plugin

This Gradle plugin provides tasks to generate a HTML / XML / Json file with the licenses used from the libraries.
https://github.com/chrimaeon/gradle-licenses-plugin

android gradle gradle-plugin gradle-task java kotlin license license-management

Last synced: 3 months ago
JSON representation

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

Awesome Lists containing this project

README

        

# Gradle Licenses Plugin [![Build & Test](https://github.com/chrimaeon/gradle-licenses-plugin/actions/workflows/main.yml/badge.svg)](https://github.com/chrimaeon/gradle-licenses-plugin/actions/workflows/main.yml) [![codecov](https://codecov.io/gh/chrimaeon/gradle-licenses-plugin/branch/master/graph/badge.svg?token=XY0G488B3B)](https://codecov.io/gh/chrimaeon/gradle-licenses-plugin)

[![License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg?style=for-the-badge)](http://www.apache.org/licenses/LICENSE-2.0)
[![Gradle Plugin](https://img.shields.io/badge/Gradle-7.2%2B-%2302303A.svg?style=for-the-badge&logo=Gradle)](https://gradle.org/)
[![MavenCentral](https://img.shields.io/maven-central/v/com.cmgapps/gradle-licenses-plugin?style=for-the-badge&logo=Apache%20Maven)](https://repo1.maven.org/maven2/com/cmgapps/gradle-licenses-plugin/)
[![gradlePluginPortal](https://img.shields.io/maven-metadata/v/https/plugins.gradle.org/m2/com/cmgapps/licenses/com.cmgapps.licenses.gradle.plugin/maven-metadata.xml.svg?label=Gradle%20Plugin%20Portal&style=for-the-badge&logo=Gradle)](https://plugins.gradle.org/plugin/com.cmgapps.licenses)

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

```kotlin
plugins {
id("com.cmgapps.licenses") version "4.8.0"
}
```

Groovy

```groovy
plugins {
id 'com.cmgapps.licenses' version '4.8.0'
}
```

#### Using legacy plugin application

Kotlin

```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

```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"`

* `licenseReport`

For `"org.jetbrains.kotlin.multiplatform"`

* `licenseMultiplatformReport` collects licenses from all targets
* `licenseMultiplatformReport` collects licenses from `common` and the specified ``

### Configuration

#### Output Format

Example:

```kotlin
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`:
```kotlin
licenses {
reports {
html.stylesheet("body {background: #FAFAFA}")
}
}
```
or
```kotlin
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 `` and a custom css theme.

It can be disabled via
```kotlin
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

```kotlin
licenses {
custom {
enabled = true
destination = buildDir.resolve("reports").resolve("licenses.txt")
generate { list -> list.map { it.name }.joinToString() }
}
}
```


Groovy

```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

```kotlin
licenses {
additionalProjects(":module2", ":module3")
}
```

Groovy

```groovy
licenses {
additionalProjects ':module2', ':module3'
}
```

## License

```text
Copyright (c) 2018. Christian Grach

SPDX-License-Identifier: Apache-2.0
```

[TextResource]: https://docs.gradle.org/current/dsl/org.gradle.api.resources.TextResource.html