apache / apache/maven

Switch core API value types to noun-style accessors

Open
#13,035 0 comments 0 reactions 0 assignees View on GitHub
maintenance
Dominant language
Java
Stars
5.3k
Forks
3.1k
Avg merge
20h 42m
Merged PRs (30d)
297

Description

Following the discussion in #11582, the Maven 4 API should consistently use noun-style accessors (record-accessor pattern) for immutable value types, in line with modern JDK conventions (see [detailed analysis](https://github.com/apache/maven/issues/11582#issuecomment-5530720249)).

Several hand-crafted API interfaces already follow this pattern (`XmlNode`, `PathType`, `Lifecycle.Phase`, `Packaging`, `ExtensibleEnum`, `OsService`, `CIInfo`). The remaining core value type interfaces should be migrated as well.

## Scope

For each interface, add the noun-style accessor as the primary abstract method and convert the existing `getX()` to a `default` method delegating to it, annotated with `@Deprecated(since = "4.1.0", forRemoval = true)`. Boolean queries (`is*()`) and conversion methods (`to*()`) are left as-is.

### Interfaces to migrate

| Interface | Accessors to add |
|---|---|
| `Artifact` | `groupId()`, `artifactId()`, `version()`, `baseVersion()`, `classifier()`, `extension()` |
| `ArtifactCoordinates` | `groupId()`, `artifactId()`, `classifier()`, `versionConstraint()`, `extension()` |
| `Dependency` | `type()`, `scope()` |
| `DependencyCoordinates` | `type()`, `scope()`, `optional()` |
| `DownloadedArtifact` | `path()` |
| `Exclusion` | `groupId()`, `artifactId()` |
| `Project` | `groupId()`, `artifactId()`, `version()`, `packaging()`, `model()`, `pomPath()`, `basedir()`, `rootDirectory()` |
| `VersionConstraint` | `versionRange()`, `recommendedVersion()` |
| `VersionRange` / `VersionRange.Boundary` | `upperBoundary()`, `lowerBoundary()`, `version()` |

~42 methods across 9 interfaces.

## Rationale

Every new immutable type introduced in the JDK since Java 8 — unconstrained by pre-existing hierarchies — uses noun-style accessors exclusively. The `getX()` prefix is the JavaBeans convention for mutable components with getters/setters. See #11582 for the full JDK 8–25 survey.

Related: #11582

Contributor guide

Open the contributing guide

Research direction

Locate the nine core API interfaces listed in the issue and compare their accessors with the existing noun-style examples such as XmlNode, PathType, and Packaging. Migrate the specified methods so noun-style accessors are primary and getX() methods delegate as deprecated defaults, while leaving is*() and to*() methods unchanged; verify all listed interfaces and roughly 42 accessors are covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.