License Finder Documentation

repository·master·Indexed 23 days ago

https://github.com/pivotal/licensefinder

A tool that scans project dependencies across various package managers to detect licenses and compare them against permitted lists. It supports multiple languages including Ruby, Node.js, Python, Java, Go, Swift/iOS, Rust, PHP, and JavaScript. Features include the ability to approve specific dependencies, permit licenses globally, restrict forbidden licenses, and generate reports in text, CSV, HTML, or Markdown formats. It can be installed as a command line tool, a pre-commit hook, or via Bundler.

Tokens
6.7K
Snippets
11
Records
68
Agent score
83%

What's inside License Finder

  1. How License Finder detects project types

    master

    License Finder automatically detects supported languages by looking for specific package definition files in your project directory.

    Key detection files include:

    • Ruby: Gemfile (bundler)
    • Node.js: package.json (npm)
    • Python: requirements.txt (pip), Pipfile.lock (pipenv)
    • Java: pom.xml (maven), build.gradle or build.gradle.kts (gradle)
    • Go: go.mod (go mod), Gopkg.lock (dep), Godeps/Godeps.json (godep)
    • Swift/iOS: Podfile (cocoapods), Cartfile (carthage), or workspace-state.json (SPM)
    • Rust: Cargo.lock (cargo)
    • PHP: composer.lock (composer)
    • JavaScript: yarn.lock (yarn)

    Note: For CocoaPods, you can target a specific target by setting the ACKNOWLEDGEMENTS_PATH environment variable.

  2. Run License Finder to scan dependencies

    master

    Before running, ensure your dependencies are already installed (e.g., via bundle install or npm install).

    To scan your project, run:

    license_finder

    If you installed via Bundler, use:

    bundle exec license_finder

    On the first run, it will list all packages. Subsequent runs will only report new or unapproved packages.

    Useful Options:

    • --quiet: Suppresses progressive output "dots".
    • --debug: Provides detailed output about package discovery and license detection.
    • --prepare or -p: Automatically runs the package manager's prepare command (e.g., npm install) before scanning.
    • --prepare-no-fail: Runs the prepare step but continues even if it fails.
    license_finder
  3. Approve specific dependencies

    master

    When license_finder reports an unapproved dependency, you can approve it to stop it from appearing in future reports.

    Approve a package by name:

    $ license_finder approvals add <package_name>

    Approve a specific version:

    $ license_finder approvals add <package_name> --version=<version>

    Approve with metadata (who and why):

    $ license_finder approvals add <package_name> --who <name> --why "<reason>"
    license_finder approvals add awesome_gpl_gem --who CTO --why "Go ahead"
  4. Use License Finder with Docker

    master

    To maintain consistent versions of all package managers, you can use the dlf script which runs commands inside a pre-provisioned Docker container. The container mounts your current directory at /scan.

    Note: If your command contains &&, you must wrap the command in quotes.

    Examples:

    # Check a package manager version
    $ dlf npm --version
    
    # Run help
    $ dlf license_finder --help
    
    # Run a combined command
    $ dlf "bundle install && license_finder"
    dlf "bundle install && license_finder"
  5. Permit specific licenses globally

    master

    Instead of approving packages one-by-one, you can define blanket policies for entire licenses. For example, to permit all packages using the MIT license:

    $ license_finder permitted_licenses add MIT

    Any current or future packages with the permitted license will be excluded from the output. You can also use --who and --why when adding permitted licenses.

    license_finder permitted_licenses add MIT
  6. Install License Finder

    master

    You can install License Finder using several methods depending on your workflow:

    Install it directly via RubyGems:

    $ gem install license_finder

    As a pre-commit hook

    Add the following to your .pre-commit-config.yaml to run license checks automatically before commits:

    repos:
      - repo: https://github.com/pivotal/LicenseFinder
        rev: v7.1.0 # Use the latest tag
        hooks:
          - id: license-finder

    In a Ruby project via Bundler

    Add it to your Gemfile in the development group:

    gem 'license_finder', :group => :development

    Requirements: Running License Finder directly requires Ruby 2.6.0 or greater.

    gem install license_finder
  7. Configure Gradle projects

    master

    License Finder requires the license-gradle-plugin to be installed in your project. By default, it reports on runtime dependencies. To report on a different configuration (like compile for Android), add the following to your build.gradle:

    // Must come *after* applying the license-gradle-plugin
    downloadLicenses {
      dependencyConfiguration "compile"
    }
    downloadLicenses {
      dependencyConfiguration "compile"
    }