Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0d5ab52

Browse files
authored
[MNG-8211] Fail the build if CI Friendly revision used without value (#1656)
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
1 parent 76ff89f commit 0d5ab52

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
@Named
7575
@Singleton
7676
public class DefaultModelValidator implements ModelValidator {
77+
public static final String BUILD_ALLOW_EXPRESSION_IN_EFFECTIVE_PROJECT_VERSION =
78+
"maven.build.allowExpressionInEffectiveProjectVersion";
7779

7880
private static final Pattern CI_FRIENDLY_EXPRESSION = Pattern.compile("\\$\\{(.+?)}");
7981
private static final Pattern EXPRESSION_PROJECT_NAME_PATTERN = Pattern.compile("\\$\\{(project.+?)}");
@@ -506,6 +508,21 @@ public void validateEffectiveModel(Model m, ModelBuildingRequest request, ModelP
506508
validateBannedCharacters(
507509
EMPTY, "version", problems, errOn31, Version.V20, m.getVersion(), null, m, ILLEGAL_VERSION_CHARS);
508510
validate20ProperSnapshotVersion("version", problems, errOn31, Version.V20, m.getVersion(), null, m);
511+
if (hasExpression(m.getVersion())) {
512+
Severity versionExpressionSeverity = Severity.ERROR;
513+
if (Boolean.parseBoolean(
514+
m.getProperties().getProperty(BUILD_ALLOW_EXPRESSION_IN_EFFECTIVE_PROJECT_VERSION))) {
515+
versionExpressionSeverity = Severity.WARNING;
516+
}
517+
addViolation(
518+
problems,
519+
versionExpressionSeverity,
520+
Version.V20,
521+
"version",
522+
null,
523+
"must be a constant version but is '" + m.getVersion() + "'.",
524+
m);
525+
}
509526

510527
Build build = m.getBuild();
511528
if (build != null) {

0 commit comments

Comments
 (0)