gnodet opened a new issue, #13929:
URL: https://github.com/apache/maven/issues/13929

   ## Problem
   
   `DependencyScope` is the only scope/type concept in the Maven 4 API that is 
implemented as a hard Java `enum`. All similar concepts use the 
`ExtensibleEnum` pattern:
   
   | Type | Implementation | Extensible via SPI |
   |---|---|---|
   | `PathScope` | `interface extends ExtensibleEnum` | `PathScopeProvider` |
   | `Language` | `interface extends ExtensibleEnum` | `LanguageProvider` |
   | `Packaging` | `interface extends ExtensibleEnum` | `PackagingProvider` |
   | `ProjectScope` | `interface extends ExtensibleEnum` | 
`ProjectScopeProvider` |
   | `Type` | `interface extends ExtensibleEnum` | `TypeProvider` |
   | `Dialect` | `interface extends ExtensibleEnum` | `DialectProvider` |
   | **`DependencyScope`** | **`enum`** | **Not extensible** |
   
   This inconsistency means:
   - Extensions/plugins cannot define custom dependency scopes
   - Adding new scopes (like `api`/`implementation` in #12745) requires 
modifying the core enum
   - The `Maven4ScopeManagerConfiguration` sanity check (`values().length - 1`) 
couples the resolver config to the enum size, which breaks if scopes are added 
externally
   
   ## Proposed change
   
   Convert `DependencyScope` from a Java `enum` to `interface extends 
ExtensibleEnum`, following the established pattern:
   
   ### 1. `DependencyScope.java` (api)
   - Change from `enum` to `interface extends ExtensibleEnum`
   - Built-in scopes become interface constants (e.g., `DependencyScope COMPILE 
= dependencyScope("compile")`)
   - `forId(String)` delegates to a registry lookup instead of a static map 
over `values()`
   - Remove `is(String)` (redundant with `id().equals()`)
   
   ### 2. `DependencyScopeProvider.java` (spi)
   - New SPI interface: `interface DependencyScopeProvider extends 
ExtensibleEnumProvider<DependencyScope>`
   - Follows the exact pattern of `PathScopeProvider`, `LanguageProvider`, etc.
   
   ### 3. `ExtensibleEnums.java` (api)
   - Add `dependencyScope(String id)` factory method, matching 
`pathScope(...)`, `language(...)`, etc.
   
   ### 4. `Maven4ScopeManagerConfiguration.java` (impl + compat)
   - Remove the `values().length` sanity check (no longer meaningful with 
extensible scopes)
   - Register built-in scopes explicitly; additional scopes come from 
`DependencyScopeProvider` implementations
   
   ### 5. `DefaultConsumerPomBuilder.java`
   - Replace `DependencyScope.forId()` with registry lookup via the 
session/container
   
   ### 6. `PathScope.java`
   - `dependencyScopes()` set construction uses registry-resolved instances 
instead of enum constants
   
   ## Migration impact
   
   - **Source-compatible for most consumers**: code referencing 
`DependencyScope.COMPILE`, `DependencyScope.API`, etc. continues to work 
(constants on the interface instead of enum values)
   - **Binary-incompatible**: code using `DependencyScope.values()`, 
`DependencyScope.valueOf()`, or `switch` on the enum will break. Grep shows 
only 3 uses of `values()` (the 2 sanity checks in 
`Maven4ScopeManagerConfiguration` and the internal `IDS` map), and no `switch` 
statements.
   - The API is `@Experimental`, so breaking changes are acceptable
   
   ## Use cases enabled
   
   - **Custom scopes in extensions**: an annotation-processing extension could 
define an `annotation-processor` scope
   - **Domain-specific scopes**: frameworks could define scopes matching their 
deployment model
   - **Decoupling**: new built-in scopes (like `api`/`implementation`) could be 
added via a provider without touching the core interface
   
   _Claude Code on behalf of Guillaume Nodet_


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to