Class Coordinates
type for last element, while in fact it is
sometimes used as "type" and sometimes used as "extension", depending on context where this record is used. In
real life artifacts have extension (and not type), while dependencies have type (or as in Maven resolver, extension
derived from type).
This is a simple immutable record for representing Maven artifact coordinates. It provides convenient factory methods and string representations commonly used in Maven.
Maven 4 Inference Support: With Maven 4's inference mechanism, groupId and version may be inferred from the reactor or parent POM and might not be present in the build POM. This record allows null values for groupId and version to support such scenarios. Only artifactId is strictly required.
Usage Examples:
// Create Coordinates
Coordinates jar = Coordinates.of("org.junit.jupiter", "junit-jupiter", "5.9.2");
Coordinates pom = Coordinates.of("org.example", "my-project", "1.0.0", null, "pom");
Coordinates classified = Coordinates.of("org.example", "my-lib", "1.0.0", "sources", "jar");
// Maven 4 inference - groupId/version may be null
Coordinates inferred = Coordinates.of(null, "my-module", null, null, "jar");
// Get string representations
String ga = jar.toGA(); // "org.junit.jupiter:junit-jupiter"
String gav = jar.toGAV(); // "org.junit.jupiter:junit-jupiter:5.9.2"
String gatc = jar.toGATC(); // "org.junit.jupiter:junit-jupiter:jar"
String full = jar.toFullString(); // "org.junit.jupiter:junit-jupiter:jar:5.9.2"
- Since:
- 0.3.0
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the Maven artifactId.Returns the artifact classifier.static CoordinatesCreates a POM Coordinates from a POM file by reading its GAV coordinates.groupId()Returns the Maven groupId.static CoordinatesCreates a Coordinates with groupId, artifactId, and version (JAR type, no classifier).static CoordinatesCreates a Coordinates with groupId, artifactId, version, classifier, and type.Predicate<eu.maveniverse.domtrip.Element> Creates a predicate that matches elements by GA (groupId:artifactId).Predicate<eu.maveniverse.domtrip.Element> Creates a predicate that matches elements by GATC (groupId:artifactId:type[:classifier]).Predicate<eu.maveniverse.domtrip.Element> Creates a predicate that matches plugin elements by GA (with default groupId handling).Returns the full string representation: groupId:artifactId:type[:classifier]:version.toGA()Returns the groupId:artifactId string representation.toGATC()Returns the groupId:artifactId:type[:classifier] string representation.toGAV()Returns the groupId:artifactId:version string representation.type()Returns the dependency/artifact type (e.g., "jar", "pom").version()Returns the artifact version.Returns a new Coordinates with the same coordinates but different type.withVersion(String newVersion) Returns a new Coordinates with the same coordinates but different version.
-
Constructor Details
-
Coordinates
public Coordinates(String groupId, String artifactId, String version, String classifier, String type) Note: groupId and version can be null to support Maven 4's inference mechanism. Only artifactId is strictly required.
- Throws:
eu.maveniverse.domtrip.DomTripException- if requirements are not fulfilled.
-
-
Method Details
-
of
Creates a Coordinates with groupId, artifactId, and version (JAR type, no classifier).- Parameters:
groupId- the Maven groupIdartifactId- the Maven artifactIdversion- the artifact version- Returns:
- a new Coordinates instance
-
of
public static Coordinates of(String groupId, String artifactId, String version, String classifier, String type) Creates a Coordinates with groupId, artifactId, version, classifier, and type.- Parameters:
groupId- the Maven groupIdartifactId- the Maven artifactIdversion- the artifact versionclassifier- the artifact classifier (can be null)type- the artifact type (can be null, defaults to "jar")- Returns:
- a new Coordinates instance
-
toGA
Returns the groupId:artifactId string representation.- Returns:
- GA string (e.g., "org.junit.jupiter:junit-jupiter")
-
toGAV
Returns the groupId:artifactId:version string representation.- Returns:
- GAV string (e.g., "org.junit.jupiter:junit-jupiter:5.9.2")
-
toGATC
Returns the groupId:artifactId:type[:classifier] string representation.- Returns:
- GATC string (e.g., "org.junit.jupiter:junit-jupiter:jar" or "org.example:lib:jar:sources")
-
toFullString
Returns the full string representation: groupId:artifactId:type[:classifier]:version.- Returns:
- full coordinates string
-
withVersion
Returns a new Coordinates with the same coordinates but different version.- Parameters:
newVersion- the new version- Returns:
- a new Coordinates instance with updated version
-
withType
Returns a new Coordinates with the same coordinates but different type.- Parameters:
newType- the new type- Returns:
- a new Coordinates instance with updated type
-
predicateGA
Creates a predicate that matches elements by GA (groupId:artifactId).This is useful for filtering streams of elements to find matching artifacts:
Coordinates junit = Coordinates.of("junit", "junit", "4.13.2"); dependencies.children("dependency") .filter(junit.predicateGA()) .findFirst();- Returns:
- a predicate for matching elements by GA
- Since:
- 0.3.0
-
predicatePluginGA
Creates a predicate that matches plugin elements by GA (with default groupId handling).Maven plugins default to groupId "org.apache.maven.plugins" if not specified. This predicate handles that convention:
Coordinates compiler = Coordinates.of("org.apache.maven.plugins", "maven-compiler-plugin", "3.11.0"); plugins.children("plugin") .filter(compiler.predicatePluginGA()) .findFirst();- Returns:
- a predicate for matching plugin elements by GA
- Since:
- 0.3.0
-
predicateGATC
Creates a predicate that matches elements by GATC (groupId:artifactId:type[:classifier]).This is useful for filtering dependencies or artifacts with specific types and classifiers:
Coordinates sources = Coordinates.of("org.example", "my-lib", "1.0.0", "sources", "jar"); dependencies.children("dependency") .filter(sources.predicateGATC()) .findFirst();- Returns:
- a predicate for matching elements by GATC
- Since:
- 0.3.0
-
fromPom
Creates a POM Coordinates from a POM file by reading its GAV coordinates.This method reads the groupId, artifactId, and version from the POM file. If groupId or version are not present in the project element, it looks for them in the parent element. With Maven 4's inference mechanism, groupId and version may be inferred from the reactor and not present in the POM - in such cases, the returned Coordinates will have null values for these fields.
Example:
Path pomFile = Paths.get("pom.xml"); Coordinates project = Coordinates.fromPom(pomFile); System.out.println("Project: " + project.toGAV());- Parameters:
pomPath- the path to the POM file- Returns:
- a new Coordinates instance representing the POM (groupId and version may be null)
- Throws:
eu.maveniverse.domtrip.DomTripException- if artifactId is missing- Since:
- 0.3.0
-
groupId
Returns the Maven groupId.- Returns:
- the groupId, or
nullif not specified (Maven 4 inference)
-
artifactId
-
version
Returns the artifact version.- Returns:
- the version, or
nullif not specified
-
classifier
Returns the artifact classifier.- Returns:
- the classifier, or
nullif not specified
-
type
Returns the dependency/artifact type (e.g., "jar", "pom").- Returns:
- the type (defaults to "jar", never
null)
-