关于Maven dependency:properties目标中classifier格式的咨询
Great question! Let's break down what's going on with the classifier in the dependency:properties goal, especially for snapshot dependencies.
1. What's a Classifier in Maven, Anyway?
First, the basics: a classifier is an optional identifier in Maven used to distinguish different artifacts built from the same groupId:artifactId:version coordinate. There's no strict mandatory format for classifiers, but common conventions include things like sources, javadoc, jdk17, or linux-x86_64—they just need to follow Maven's general rules for identifiers (no spaces, special characters like : or /, etc.).
2. Classifier Behavior for Snapshots in dependency:properties
The confusion you're seeing comes from how Maven handles snapshot dependencies. When you declare a snapshot dependency (e.g., com.example:my-lib:jar:1.0-SNAPSHOT), Maven doesn't just use the literal -SNAPSHOT in the artifact filename. Instead, it resolves the latest snapshot build, which includes a timestamp and build number (like 20240520.143022-5).
For the dependency:properties goal, when dealing with a snapshot dependency that has no explicit classifier, it repurposes this timestamp+build number string as the classifier part of the generated property name. For example:
- Your declared dependency:
com.example:my-lib:jar:1.0-SNAPSHOT - Resolved artifact file:
my-lib-1.0-20240520.143022-5.jar - Generated property:
com.example:my-lib:jar:20240520.143022-5(value is the local path to the artifact)
If your dependency does have an explicit classifier (e.g., com.example:my-lib:jar:sources:1.0-SNAPSHOT), the generated property will use that explicit classifier (sources) instead of the timestamp—since the timestamp is part of the snapshot version resolution, not the classifier itself.
3. Why Isn't This Documented?
This behavior is a side effect of Maven's snapshot resolution mechanism, rather than a direct feature of the dependency:properties goal. The official docs focus on the general case (non-snapshot dependencies with optional explicit classifiers), so they don't call out this snapshot-specific behavior explicitly.
The default timestamp format (yyyyMMdd.HHmmss-buildNumber) is controlled by Maven's maven-snapshot-plugin, and you can customize it if needed via plugin configuration, but this is the standard out-of-the-box behavior.
内容的提问来源于stack exchange,提问作者Andremoniy

