This is an automated email from the ASF dual-hosted git repository. cstamas pushed a commit to branch maven-3.9.x in repository https://gitbox.apache.org/repos/asf/maven.git
The following commit(s) were added to refs/heads/maven-3.9.x by this push: new 0d5ab52ac4 [MNG-8211] Fail the build if CI Friendly revision used without value (#1656) 0d5ab52ac4 is described below commit 0d5ab52ac48b122ff311f02ea9eb17aeab3209dd Author: Tamas Cservenak <ta...@cservenak.net> AuthorDate: Thu Aug 22 12:54:35 2024 +0200 [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 --- .../maven/model/validation/DefaultModelValidator.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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) {