• Stars
    star
    345
  • Rank 122,750 (Top 3 %)
  • Language
    Groovy
  • License
    Apache License 2.0
  • Created almost 8 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Gradle plugin that provides a task to generate a HTML license report of your project.

Gradle License Plugin

License Maven Gradle Plugin Portal Build Twitter Follow

This plugin provides a task to generate a HTML license report based on the configuration. (eg. licenseDebugReport for all debug dependencies in an Android project).

Applying this to an Android or Java project will generate the license file(open_source_licenses.html) in the <project>/build/reports/licenses/.

Also, for Android projects the license HTML file will be copied to <project>/src/main/assets/.

Download

Release:

with plugins { }
plugins {
  id("com.jaredsburrows.license") version "0.9.3"
}
with buildscript { }
buildscript {
  repositories {
    mavenCentral()
    google() // For Android projects
  }

  dependencies {
    classpath 'com.jaredsburrows:gradle-license-plugin:0.9.3'
  }
}

apply plugin: 'com.android.application' // or 'java-library'
apply plugin: 'com.jaredsburrows.license'

Release versions are available in the Sonatype's release repository.

Snapshot:

with plugins { }
plugins {
  id("com.jaredsburrows.license") version "0.9.4-SNAPSHOT"
}
with buildscript { }
buildscript {
  repositories {
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    google() // For Android projects
  }

  dependencies {
    classpath 'com.jaredsburrows:gradle-license-plugin:0.9.4-SNAPSHOT'
  }
}

apply plugin: 'com.android.application' // or 'java-library'
apply plugin: 'com.jaredsburrows.license'

Snapshot versions are available in the Sonatype's snapshots repository.

Tasks

  • license${variant}Report for Android
  • licenseReport for Java

Generates a HTML report of the all open source licenses. (eg. licenseDebugReport for all debug dependencies in an Android project).

Example build.gradle:

dependencies {
  implementation 'com.android.support:design:26.1.0'
  implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.3'
  implementation 'wsdl4j:wsdl4j:1.5.1' // Very old library with no license info available
}

Example Outputs:

CSV Example (full):
project,description,version,developers,url,year,licenses,license urls,dependency
Android GIF Drawable Library,Views and Drawable for displaying animated GIFs for Android,1.2.3,Karol Wrótniak,https://github.com/koral--/android-gif-drawable,null,The MIT License,http://opensource.org/licenses/MIT,pl.droidsonroids.gif:android-gif-drawable:1.2.3
design,null,26.1.0,null,null,null,The Apache Software License,http://www.apache.org/licenses/LICENSE-2.0.txt,com.android.support:design:26.1.0
HTML Example (license descriptions are minimized):
<html>
  <head>
    <style>body { font-family: sans-serif } pre { background-color: #eeeeee; padding: 1em; white-space: pre-wrap; word-break: break-word; display: inline-block }</style>
    <title>Open source licenses</title>
  </head>
  <body>
    <h3>Notice for packages:</h3>
    <ul>
      <li>
        <a href="#0">WSDL4J (1.5.1)</a>
        <dl>
          <dt>Copyright &copy; 20xx The original author or authors</dt>
        </dl>
      </li>
      <a name="0"></a>
        <pre>No license found</pre>
      <br>
      <hr>
      <li><a href="#1783810846">Android GIF Drawable Library (1.2.3)</a>
        <dl>
          <dt>Copyright &copy; 20xx Karol Wrótniak</dt>
        </dl>
      </li>
      <a name="1783810846"></a>
        <pre>mit.txt here</pre>
      <br>
      <hr>
      <li><a href="#1934118923">Design (26.1.0)</a>
        <dl>
          <dt>Copyright &copy; 20xx The original author or authors</dt>
        </dl>
      </li>
      <a name="1934118923"></a>
        <pre>apache-2.0.txt here</pre>
      <br>
      <hr>
    </ul>
  </body>
</html>

Note, if no license information is found in the POM for a project, "No License Found" will be used. Those will be listed first. Other missing information is provided as default values that can be corrected from other sources. Projects are grouped by license name and the license text is only provided once. Projects with multiple licenses are grouped as if those licenses were a single combined license.

JSON Example (full):
[
  {
    "project": "Android GIF Drawable Library",
    "description": "Views and Drawable for displaying animated GIFs for Android",
    "version": "1.2.3",
    "developers": [
      "Karol Wrótniak"
    ],
    "url": "https://github.com/koral--/android-gif-drawable",
    "year": null,
    "licenses": [
      {
        "license": "The MIT License",
        "license_url": "http://opensource.org/licenses/MIT"
      }
    ],
    "dependency": "pl.droidsonroids.gif:android-gif-drawable:1.2.3"
  },
  {
    "project": "Design",
    "description": null,
    "version": "26.1.0",
    "developers": [],
    "url": null,
    "year": null,
    "licenses": [
      {
        "license": "The Apache Software License",
        "license_url": "http://www.apache.org/licenses/LICENSE-2.0.txt"
      }
    ],
    "dependency": "com.android.support:design:26.1.0"
  },
  {
    "project": "WSDL4J",
    "description": "Java stub generator for WSDL",
    "version": "1.5.1",
    "developers": [],
    "url": "http://sf.net/projects/wsdl4j",
    "year": null,
    "licenses": [],
    "dependency": "wsdl4j:wsdl4j:1.5.1"
  }
]

Note, if no license information is found for a component, the licenses element in the JSON output will be an empty array.

Text Example (full):
Notice for packages

Android GIF Drawable Library (1.2.3) - The MIT License
Views and Drawable for displaying animated GIFs for Android
https://github.com/koral--/android-gif-drawable

design (26.1.0) - The Apache Software License

Configuration

The plugin can be configured to generate specific reports and automatically copy the reports to the assets directory (Android projects only). The default behaviours are:

  • Java projects: Generate HTML, JSON and CSV reports.
  • Android projects: Generate HTML, JSON and CSV reports, and copy the HTML report to the assets directory.

The plugin can be configured to ignore licenses for certain artifact patterns. The default is that nothing is ignored.

To override the defaults, add the licenseReport configuration closure to the build script.

apply plugin: "com.jaredsburrows.license"

licenseReport {
  generateCsvReport = false
  generateHtmlReport = true
  generateJsonReport = false
  generateTextReport = false
  ignoredPatterns = []

  // These options are ignored for Java projects
  copyCsvReportToAssets = false
  copyHtmlReportToAssets = true
  copyJsonReportToAssets = false
  copyTextReportToAssets = false
  useVariantSpecificAssetDirs = false
}

The copyHtmlReportToAssets option in the above example would have no effect since the HTML report is disabled.

The useVariantSpecificAssetDirs allows the reports to be copied into the source set asset directory of the variant. For example, licensePaidProductionReleaseReport would put the reports in src/paidProductionRelease/assets. They are copied into src/main/assets by default.

The ignoredPatterns allows for ignoring artifact patterns. These can be partial or full patterns.

apply plugin: "com.jaredsburrows.license"

licenseReport {
  ignoredPatterns = ["com.some.group"] // Ignores all artifacts of the given group
  ignoredPatterns = ["com.some.group:some.name"] // Ignores the given artifact regardless of version
  ignoredPatterns = ["com.some.group:some.name:1.2.3"] // Ignores the given artifact with the given version
}

Usage Example

Create an open source dialog

Kotlin
import android.app.Dialog
import android.os.Bundle
import android.webkit.WebView

import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentTransaction

class OpenSourceLicensesDialog : DialogFragment() {

  fun showLicenses(activity: AppCompatActivity) {
    val fragmentManager = activity.getSupportFragmentManager()
    val fragmentTransaction = fragmentManager.beginTransaction()
    val previousFragment = fragmentManager.findFragmentByTag("dialog_licenses")
    if (previousFragment != null) {
      fragmentTransaction.remove(previousFragment)
    }
    fragmentTransaction.addToBackStack(null)

    show(fragmentManager, "dialog_licenses")
  }

  override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
    val webView = WebView(requireActivity())
    webView.loadUrl("file:///android_asset/open_source_licenses.html")

    return Builder(requireActivity())
      .setTitle("Open Source Licenses")
      .setView(webView)
      .setPositiveButton("OK",
        DialogInterface.OnClickListener { dialog: DialogInterface, which: Int -> dialog.dismiss() })
      .create()
  }
}
Java
import android.app.Dialog;
import android.os.Bundle;
import android.webkit.WebView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;

public final class OpenSourceLicensesDialog extends DialogFragment {

  public OpenSourceLicensesDialog() {
  }

  public void showLicenses(AppCompatActivity activity) {
    FragmentManager fragmentManager = activity.getSupportFragmentManager();
    FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
    Fragment previousFragment = fragmentManager.findFragmentByTag("dialog_licenses");
    if (previousFragment != null) {
      fragmentTransaction.remove(previousFragment);
    }
    fragmentTransaction.addToBackStack(null);

    show(fragmentManager, "dialog_licenses");
  }

  @Override
  public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    WebView webView = new WebView(requireActivity());
    webView.loadUrl("file:///android_asset/open_source_licenses.html");

    return new AlertDialog.Builder(requireActivity())
        .setTitle("Open Source Licenses")
        .setView(webView)
        .setPositiveButton("OK", (dialog, which) -> dialog.dismiss())
        .create();
  }
}

How to use it

Kotlin
OpenSourceLicensesDialog().showLicenses(this)
Java
new OpenSourceLicensesDialog().showLicenses(this);

Source: https://github.com/google/iosched/blob/2531cbdbe27e5795eb78bf47d27e8c1be494aad4/android/src/main/java/com/google/samples/apps/iosched/util/AboutUtils.java#L52

Source: https://www.bignerdranch.com/blog/open-source-licenses-and-android/

License

Copyright (C) 2016 Jared Burrows

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

More Repositories

1

android-gradle-java-app-template

Gradle + Android Studio + Robolectric + Espresso + Mockito + EasyMock/PowerMock + JaCoCo
Java
589
star
2

android-gif-search

Gif LazyVerticalGrid MVVM using Dagger 2 + Hilt with Retrofit 2, Moshi, Kotlin Coroutines, JUnit, Espresso and Robolectric tests!
Kotlin
393
star
3

open-quartz

Google Glass Development - GDK + SDK
Java
211
star
4

rarcrack

Rarcrack - port for Mac OSX (works on Linux and Mac OSX)
C
181
star
5

gradle-spoon-plugin

Gradle plugin that provides a task to run Android instrumentation tests via Spoon.
Groovy
123
star
6

android-bloatware

Keeping tracking of Bloatware that is safe to disable.
Shell
89
star
7

android-gradle-kotlin-app-template

Gradle + Android Studio + Robolectric + Espresso + JaCoCo
Kotlin
81
star
8

cs-interview-questions

Personal Solutions to Interview Questions
Java
62
star
9

android-gradle-groovy-app-template

Gradle + Android Studio + Robolectric + Espresso + RoboSpock + JaCoCo
Groovy
40
star
10

assembly-example

Common Functions and Code written in Assembly Language
Assembly
32
star
11

retrofit2-synchronous-adapter

This adapter allows synchronous return types for Retrofit 2.
Java
30
star
12

android-gradle-java-multi-module-template

Static analysis tools: PMD, Findbugs, Checkstyle, Lint and Jacoco on multi module build with an Android app module, Android library module and a Java module
Java
30
star
13

android-gradle-java-library-template

Android Gradle Library Template
Java
23
star
14

android-bazel-java-app-template

Gradle + Android Studio + Robolectric + Espresso + Mockito + EasyMock/PowerMock + JaCoCo
Java
17
star
15

open-virus

Open Source Virus Development
Shell
14
star
16

gradle-checker-framework-plugin

Gradle plugin to use the Checker Framework for Java.
Groovy
9
star
17

ios-gradle-objc-app-template

Gradle + Xcode + XCtest
Objective-C
5
star
18

ios-gradle-swift-app-template

Gradle + Xcode + XCtest
Swift
5
star
19

xml-rpcpp

XmlRpc++ - port for Mac OSX (works on Linux, Mac OSX and Windows) - http://sourceforge.net/projects/xmlrpcpp/
C++
4
star
20

flutter-app-template

Flutter App Template
Dart
3
star
21

jaredsburrows.com

Personal website
HTML
3
star
22

burrowsapps.com

Burrows Applications website
HTML
3
star
23

msp-430

Here are some examples of how to use the MSP430
C
3
star
24

gradle-ios-plugin

Gradle plugin for iOS mobile development
Groovy
3
star
25

gradle-versions-downloader

Download previous of Gradle for cache
Shell
2
star
26

bluetooth-controller

Android Bluetooth with Arduino
Java
2
star
27

hello-world

Hello world in multiple languages.
Assembly
2
star
28

android-gradle-publish-example

TBD
Kotlin
2
star
29

cplusplus-cmake-template

CMake + Boost + Protobuf + GTest + GMock
C++
2
star
30

finance-api

Finance API
Java
1
star
31

dot-files

Development Dot Files
Vim Script
1
star
32

flutter-gif-search

Flutter Gif Search
Dart
1
star
33

flutter-app-firebase

Dart
1
star
34

ci-droid

Java
1
star
35

android-login-example

Basic Android login to PHP + MySQL server, written a while ago for a demo
Java
1
star
36

flutter-app-playground

A playground for Flutter.
Dart
1
star