HarshMehta112 commented on issue #1470:
URL: https://github.com/apache/maven-release/issues/1470#issuecomment-4818273064
Hi @hboutemy @slawekjaranowski
I think `autoResolveSnapshots` could be improved to preserve property
references when resolving snapshot dependencies. Currently, when a dependency
version is a property expression (e.g. `${dep.version}`), the resolution
inlines the resolved version onto each dependency and leaves the property
stale, which loses the single source of truth and stamps a SNAPSHOT value into
the released POM. I think updating the property value once and keeping the
`${dep.version}` reference would better fit how these projects are structured.
A minimal approach would route the snapshot-resolution path through the
existing property-rewriting logic, with a fallback to inline when the property
can't be rewritten locally (e.g. inherited from a parent), so a snapshot can
never leak into the release:
```java
// autoResolveSnapshots: version given as ${property}
String property =
MavenExpression.extractPropertyFromExpression(rawVersion);
boolean rewritten = false;
if (property != null
&& !property.startsWith("project.")
&& !property.startsWith("pom.")
&& !"version".equals(property)) {
// reuse the same path the release-version flow uses:
// updates the property in place, dedupes deps sharing it, detects
conflicts
rewritten = rewritePropertyUsedInVersionExpression(
projectId, key, rawVersion, resolvedSnapshotVersion,
originalVersion, property, properties, result,
releaseDescriptor);
}
if (!rewritten) {
// property not locally rewritable -> inline to avoid leaking a
snapshot
artifact.setVersion(resolvedSnapshotVersion);
}
```
Result:
```
<properties><dep.version>1.0.0</dep.version></properties> <!-- updated
once -->
<dependency>...<version>${dep.version}</version></dependency> <!--
preserved -->
<dependency>...<version>${dep.version}</version></dependency> <!--
preserved -->
```
If this approach aligns with the project direction, I'm happy to refine or
extend it as needed. As I'm still new to contributing, feedback is welcome!
--
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]