Skip to content

Switch core API value types to noun-style accessors #13035

Description

@gnodet

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).

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions