{"record":{"id":"ed08e64e7e91ca43","repo":"apache/maven","slug":"invalid-dependency-scope","errorCode":null,"errorMessage":"Invalid dependency scope: ","messagePattern":"Invalid dependency scope: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"impl/maven-impl/src/main/java/org/apache/maven/impl/AbstractSession.java","lineNumber":1028,"sourceCode":"    public Language requireLanguage(String id) {\n        return getService(LanguageRegistry.class).require(id);\n    }\n\n    @Override\n    public Packaging requirePackaging(String id) {\n        return getService(PackagingRegistry.class).require(id);\n    }\n\n    @Override\n    public ProjectScope requireProjectScope(String id) {\n        return getService(ProjectScopeRegistry.class).require(id);\n    }\n\n    @Override\n    public DependencyScope requireDependencyScope(String id) {\n        DependencyScope scope = DependencyScope.forId(requireNonNull(id, \"id\"));\n        if (scope == null) {\n            throw new IllegalArgumentException(\"Invalid dependency scope: \" + id);\n        }\n        return scope;\n    }\n\n    @Override\n    public PathScope requirePathScope(String id) {\n        return getService(PathScopeRegistry.class).require(id);\n    }\n\n    @Override\n    public void setCurrentTrace(RequestTrace trace) {\n        getTraceHolder().set(trace);\n    }\n\n    @Override\n    public RequestTrace getCurrentTrace() {\n        return getTraceHolder().get();\n    }","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/apache/maven/blob/e4093d4e120eac99d6bdce5ba67cace2f3085c97/impl/maven-impl/src/main/java/org/apache/maven/impl/AbstractSession.java#L1010-L1046","documentation":"Session.requireDependencyScope(id) looks the id up in the DependencyScope enum and throws IllegalArgumentException for unknown ids. Maven 4 scopes are case-sensitive, hyphen-separated ids: none, '' (undefined), compile, compile-only, runtime, provided, test, test-only, test-runtime, system. Note the Maven 4 additions (compile-only, test-only, test-runtime) and that underscores or uppercase variants are NOT accepted.","triggerScenarios":"Calling session.requireDependencyScope('TEST'), requireDependencyScope('compile_only'), or a legacy/typo string like 'compille' or Maven-3-style 'import'/'system' variants that are not in the enum.","commonSituations":"Porting Maven 3 code that manipulated scope strings; parsing scopes from user input or plugin parameters without validation; confusion between Maven 3 and Maven 4 scope vocabularies (e.g. expecting 'test-runtime' vs 'testruntime' vs 'TEST_RUNTIME'); 'import' scope which exists only in dependencyManagement and is not a DependencyScope id.","solutions":["Use one of the exact enum ids: none, compile, compile-only, runtime, provided, test, test-only, test-runtime, system (or DependencyScope enum constants directly)","Validate first with DependencyScope.forId(id) and report the supported list on null","Prefer passing DependencyScope enum values instead of strings throughout your code"],"exampleFix":"// before\nDependencyScope scope = session.requireDependencyScope(userScope); // throws for 'compile_only'\n\n// after\nDependencyScope scope = DependencyScope.forId(userScope);\nif (scope == null) {\n    throw new IllegalArgumentException('Unknown scope \"' + userScope + '\"; valid: ' + Arrays.toString(DependencyScope.values()));\n}","handlingStrategy":"validation","validationCode":"DependencyScope scope = DependencyScope.forId(scopeId);\nif (scope == null) {\n    throw new IllegalArgumentException(\n            'Invalid scope \"' + scopeId + '\"; valid ids: ' + Arrays.toString(DependencyScope.values()));\n}","typeGuard":"static boolean isValidScope(String id) { return DependencyScope.forId(id) != null; }","tryCatchPattern":null,"preventionTips":["Use DependencyScope enum constants instead of strings in code","Validate scope strings from user input against DependencyScope.forId before calling requireDependencyScope","Remember ids are case-sensitive and hyphenated (compile-only, test-runtime)"],"tags":["maven","dependency-scope","validation","maven-api"],"backgroundTag":"invalid-dependency-scope","analyzedSha":"e4093d4e120eac99d6bdce5ba67cace2f3085c97","analyzedAt":"2026-08-21T22:58:24.034Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}