The core issue is that your GitLab CI pipeline is failing because the license compliance check, specifically the license_finder tool, can’t verify the licenses of your project’s dependencies. This is happening because license_finder is either not seeing your dependency lock files or it’s misinterpreting the license information within them.
Common Causes and Fixes:
-
Missing or Incorrectly Named Lock Files:
- Diagnosis:
license_finderrelies on specific lock files generated by your package managers. For example,Gemfile.lockfor Ruby,package-lock.jsonornpm-shrinkwrap.jsonfor Node.js,Pipfile.lockfor Python (Pipenv),poetry.lockfor Python (Poetry),composer.lockfor PHP, andgo.sumfor Go. Check if these files are present at the root of your repository or in the directory where your package manager commands are run. - Fix: Ensure the correct lock file for your primary language/package manager is committed to your repository and is accessible by the
license_findercommand in your CI job. If you’re using multiple package managers, commit all relevant lock files.- Example (Ruby):
commit Gemfile.lock - Example (Node.js):
commit package-lock.json - Example (Python Pipenv):
commit Pipfile.lock - Example (Python Poetry):
commit poetry.lock - Example (PHP Composer):
commit composer.lock - Example (Go):
commit go.sum
- Example (Ruby):
- Why it works:
license_finderparses these lock files to identify all direct and transitive dependencies and their versions. Without them, it has no definitive list of what’s installed.
- Diagnosis:
-
license_finderNot Run in the Correct Directory:- Diagnosis: The CI job might be executing the
license_findercommand from a directory other than the one containing your lock files. - Fix: In your
.gitlab-ci.yml, ensure youcdinto the correct project directory before runninglicense_finder. If your lock files are at the repository root, nocdis needed. If they are in a subdirectory (e.g.,backend/), usecd backend/before invokinglicense_finder.- Example:
license_check: stage: test script: - cd backend/ - bundle exec license_finder --format=json > license_report.json - echo "License report generated."
- Example:
- Why it works:
license_finderlooks for lock files relative to its current working directory.
- Diagnosis: The CI job might be executing the
-
Dependency Installation Step Missing or Incorrect:
- Diagnosis:
license_findercan sometimes operate by inspecting installed dependencies directly if lock files are unavailable or incomplete. If your CI job doesn’t install dependencies before runninglicense_finder, it might not find anything to check. - Fix: Add or verify the dependency installation step in your CI job before
license_finderruns.- Example (Ruby):
bundle install - Example (Node.js):
npm ci(preferred for CI) ornpm install - Example (Python Pipenv):
pipenv install --deploy --system - Example (Python Poetry):
poetry install - Example (PHP Composer):
composer install --no-dev - Example (Go):
go mod tidy && go mod download
- Example (Ruby):
- Why it works: This ensures that all necessary packages are present in the CI environment, allowing
license_finderto inspect them if needed, or to confirm the lock file’s accuracy.
- Diagnosis:
-
Unrecognized or Missing License Information in Dependencies:
- Diagnosis: Some dependencies might not explicitly declare their license in their metadata (e.g.,
package.json,.gemspec,pyproject.toml).license_findermight flag these as "unknown" or "unapproved." - Fix:
- Option A (Preferred): Update the problematic dependency to a version that correctly declares its license, or find an alternative package.
- Option B (Configuration): Configure
license_finderto explicitly allow or ignore specific dependencies or licenses. You can do this via a.license.ymlfile or command-line arguments.- Example (
.license.ymlto allowsome-unlicensed-lib):ignore_paths: - "some_directory/" allowed_licenses: - MIT - Apache-2.0 packages_root: vendor/ # if applicable dependencies_sources: - gem - npm # Allow specific package with unknown license # Note: This is a last resort and should be reviewed carefully. # It's better to fix the dependency or find an alternative. # For demonstration, let's say 'some-unlicensed-lib' is a specific dependency # you want to allow despite its license status. # license_finder doesn't have a direct 'allow_package' by name for unknown licenses, # but you can manage this via 'ignored_groups' or by setting a default license. # A more robust approach is often to add a custom license definition if possible, # or to use the 'add_to_unapproved' command line flag if you want license_finder # to *recognize* it but not fail. # The most direct way to *ignore* a specific dependency that has an unknown license # is often by using the configuration to define its license or ignore it. # For simplicity and common use cases, focus on 'allowed_licenses'. # If a package has NO license declared, license_finder will often report it as 'unknown'. # You can configure license_finder to *ignore* packages with unknown licenses: # ignore_unknown_licenses: true - Example (Command line to add an unknown license package):
bundle exec license_finder --add-to-unapproved=some-unlicensed-lib
- Example (
- Why it works: Explicitly defining allowed licenses or instructing
license_finderon how to handle packages with missing license metadata prevents the check from failing due to incomplete information.
- Diagnosis: Some dependencies might not explicitly declare their license in their metadata (e.g.,
-
Custom License Definitions or Scans:
- Diagnosis: If your project uses internal or custom-licensed components,
license_findermight not recognize them by default. - Fix: You can define custom licenses or scan directories for licenses using
license_finder’s configuration or command-line options.- Example (
.license.ymlfor custom license):custom_license_expressions: - name: MyInternalLicense expression: "(Internal-Proprietary AND NOT (GPL OR MIT))" - Example (Command line to add a custom license definition):
bundle exec license_finder --custom-license 'MyInternalLicense=(Internal-Proprietary AND NOT (GPL OR MIT))'
- Example (
- Why it works: This allows
license_finderto understand and evaluate licenses that aren’t part of its standard SPDX-based definitions.
- Diagnosis: If your project uses internal or custom-licensed components,
-
license_finderNot Installed or Incorrect Version:- Diagnosis: The
license_finderexecutable might not be installed in your CI environment, or an incompatible version is being used. - Fix: Ensure
license_finderis installed as part of your CI job’s setup. If you’re managing it via a package manager (e.g.,gem install license_finder), make sure that installation step is present and successful. If you’re using it viabundle exec, ensure it’s listed in yourGemfile.- Example (in
Gemfile):gem 'license_finder', '~> 5.0' # Use a specific, known-good version - Example (in
.gitlab-ci.ymlscript):before_script: - gem install license_finder -v 5.0.0 # Or run bundle install if using Gemfile
- Example (in
- Why it works: The
license_findertool must be present and executable for the check to run. Specifying a version helps avoid unexpected behavior from updates.
- Diagnosis: The
The next error you’ll likely encounter after resolving license compliance issues is a failure in a subsequent testing or security scanning stage, as the pipeline progresses through its defined stages.