diff --git a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java index 1f1a7ab572..f4d7369c88 100644 --- a/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java +++ b/maven-model-builder/src/main/java/org/apache/maven/model/validation/DefaultModelValidator.java @@ -74,6 +74,8 @@ import org.codehaus.plexus.util.StringUtils; @Named @Singleton public class DefaultModelValidator implements ModelValidator { + public static final String BUILD_ALLOW_EXPRESSION_IN_EFFECTIVE_PROJECT_VERSION = + "maven.build.allowExpressionInEffectiveProjectVersion"; private static final Pattern CI_FRIENDLY_EXPRESSION = Pattern.compile("\\$\\{(.+?)}"); private static final Pattern EXPRESSION_PROJECT_NAME_PATTERN = Pattern.compile("\\$\\{(project.+?)}"); @@ -506,6 +508,21 @@ public class DefaultModelValidator implements ModelValidator { 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 (Boolean.parseBoolean( + m.getProperties().getProperty(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) {