Skip to content

Commit

Permalink
[MNG-8211] Fail the build if project effective version has expression (
Browse files Browse the repository at this point in the history
…#1673)

As this is almost always source of confusion. If feature is used and there is no proper value set, fail the build, as users for sure does not plan to deploy artifacts with version `${revision}` (or any expression in project.version).

Still, to not be disruptive, the old behaviour can be achieved by setting `maven.build.allowExpressionInEffectiveProjectVersion`=true project property.

---

https://issues.apache.org/jira/browse/MNG-8211
  • Loading branch information
cstamas committed Aug 22, 2024
1 parent 20e6f6a commit 6668da3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
@Named
@Singleton
public class DefaultModelValidator implements ModelValidator {
public static final String BUILD_ALLOW_EXPRESSION_IN_EFFECTIVE_PROJECT_VERSION =
"maven.build.allowExpressionInEffectiveProjectVersion";

public static final List<String> VALID_MODEL_VERSIONS =
Collections.unmodifiableList(Arrays.asList("4.0.0", "4.1.0"));
Expand Down Expand Up @@ -699,6 +701,22 @@ public void validateEffectiveModel(Model m, ModelBuilderRequest request, ModelPr
validateBannedCharacters(
EMPTY, "version", problems, errOn31, Version.V20, m.getVersion(), null, m, ILLEGAL_VERSION_CHARS);
validate20ProperSnapshotVersion("version", problems, errOn31, Version.V20, m.getVersion(), null, m);
if (hasExpression(m.getVersion())) {
Severity versionExpressionSeverity = Severity.ERROR;
if (m.getProperties() != null
&& Boolean.parseBoolean(
m.getProperties().get(BUILD_ALLOW_EXPRESSION_IN_EFFECTIVE_PROJECT_VERSION))) {
versionExpressionSeverity = Severity.WARNING;
}
addViolation(
problems,
versionExpressionSeverity,
Version.V20,
"version",
null,
"must be a constant version but is '" + m.getVersion() + "'.",
m);
}

Build build = m.getBuild();
if (build != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@
@Named
@Singleton
public class DefaultModelValidator implements ModelValidator {
public static final String BUILD_ALLOW_EXPRESSION_IN_EFFECTIVE_PROJECT_VERSION =
"maven.build.allowExpressionInEffectiveProjectVersion";

public static final List<String> VALID_MODEL_VERSIONS =
Collections.unmodifiableList(Arrays.asList("4.0.0", "4.1.0"));
Expand Down Expand Up @@ -691,6 +693,22 @@ public void validateEffectiveModel(Model ma, ModelBuildingRequest request, Model
validateBannedCharacters(
EMPTY, "version", problems, errOn31, Version.V20, m.getVersion(), null, m, ILLEGAL_VERSION_CHARS);
validate20ProperSnapshotVersion("version", problems, errOn31, Version.V20, m.getVersion(), null, m);
if (hasExpression(m.getVersion())) {
Severity versionExpressionSeverity = Severity.ERROR;
if (m.getProperties() != null
&& Boolean.parseBoolean(
m.getProperties().get(BUILD_ALLOW_EXPRESSION_IN_EFFECTIVE_PROJECT_VERSION))) {
versionExpressionSeverity = Severity.WARNING;
}
addViolation(
problems,
versionExpressionSeverity,
Version.V20,
"version",
null,
"must be a constant version but is '" + m.getVersion() + "'.",
m);
}

Build build = m.getBuild();
if (build != null) {
Expand Down

0 comments on commit 6668da3

Please sign in to comment.