{"record":{"id":"7eb86ed40296b333","repo":"composer/composer","slug":"invalid-license-provided-license-only-spdx-li","errorCode":null,"errorMessage":"Invalid license provided: ${license}. Only SPDX license identifiers (https://spdx.org/licenses/) or \"proprietary\" are accepted.","messagePattern":"Invalid license provided: (.+?)\\. Only SPDX license identifiers \\(https://spdx\\.org/licenses/\\) or \"proprietary\" are accepted\\.","errorType":"exception","errorClass":"\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Composer/Command/InitCommand.php","lineNumber":370,"sourceCode":"        );\n        if ($type === '' || $type === false) {\n            $type = null;\n        }\n        $input->setOption('type', $type);\n\n        if (null === $license = $input->getOption('license')) {\n            if (!empty($_SERVER['COMPOSER_DEFAULT_LICENSE'])) {\n                $license = $_SERVER['COMPOSER_DEFAULT_LICENSE'];\n            }\n        }\n\n        $license = $io->ask(\n            'License [<comment>'.$license.'</comment>]: ',\n            $license\n        );\n        $spdx = new SpdxLicenses();\n        if (null !== $license && !$spdx->validate($license) && $license !== 'proprietary') {\n            throw new \\InvalidArgumentException('Invalid license provided: '.$license.'. Only SPDX license identifiers (https://spdx.org/licenses/) or \"proprietary\" are accepted.');\n        }\n        $input->setOption('license', $license);\n\n        $io->writeError(['', 'Define your dependencies.', '']);\n\n        // prepare to resolve dependencies\n        $repos = $this->getRepos();\n        $preferredStability = $minimumStability ?: 'stable';\n        $platformRepo = null;\n        if ($repos instanceof CompositeRepository) {\n            foreach ($repos->getRepositories() as $candidateRepo) {\n                if ($candidateRepo instanceof PlatformRepository) {\n                    $platformRepo = $candidateRepo;\n                    break;\n                }\n            }\n        }\n","sourceCodeStart":352,"sourceCodeEnd":388,"githubUrl":"https://github.com/composer/composer/blob/c435d285c9120efdca35696769c72ea9fdcc0466/src/Composer/Command/InitCommand.php#L352-L388","documentation":"In InitCommand::interact the entered license is validated through Composer\\Spdx\\SpdxLicenses::validate (which checks the SPDX license list) and the literal string 'proprietary'. Anything failing both throws InvalidArgumentException, terminating the init. SPDX identifiers are case- and form-sensitive (e.g. Apache-2.0, MIT, BSD-3-Clause).","triggerScenarios":"User enters a license that is neither a valid SPDX identifier nor the word 'proprietary' — e.g. `Apache`, `GPL3`, `free`, or a custom description.","commonSituations":"Typing a short/informal license name instead of the SPDX identifier; entering a version without the `-` (e.g. `GPL-3` vs `GPL-3.0-only`); copy-pasting a license nickname.","solutions":["Use the exact SPDX identifier from https://spdx.org/licenses/ (e.g. Apache-2.0, MIT, BSD-3-Clause).","Use 'proprietary' for closed-source code.","Leave the field blank if you do not want a license recorded."],"exampleFix":"// before\ncomposer init --license=\"Apache\"\n// after\ncomposer init --license=\"Apache-2.0\"","handlingStrategy":"validation","validationCode":"$spdx = new \\Composer\\Spdx\\SpdxLicenses();\nif ($license !== null && $license !== 'proprietary' && !$spdx->validate($license)) {\n    throw new \\InvalidArgumentException('Bad license');\n}","typeGuard":"function isValidLicense(string $l): bool {\n    return $l === 'proprietary' || (new \\Composer\\Spdx\\SpdxLicenses())->validate($l);\n}","tryCatchPattern":null,"preventionTips":["Keep an allowlist of your org's SPDX identifiers.","Pull identifiers from https://spdx.org/licenses/ rather than typing from memory."],"tags":["init-command","validation","license","spdx"],"backgroundTag":null,"analyzedSha":"c435d285c9120efdca35696769c72ea9fdcc0466","analyzedAt":"2026-08-07T18:58:23.525Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}