This is an automated email from the ASF dual-hosted git repository.

cstamas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven.git


The following commit(s) were added to refs/heads/master by this push:
     new 6668da3219 [MNG-8211] Fail the build if project effective version has 
expression (#1673)
6668da3219 is described below

commit 6668da321915eeb64b8ac0f6ca3ae4b8f7af9333
Author: Tamas Cservenak <ta...@cservenak.net>
AuthorDate: Thu Aug 22 12:54:24 2024 +0200

    [MNG-8211] Fail the build if project effective version has expression 
(#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
---
 .../internal/impl/model/DefaultModelValidator.java     | 18 ++++++++++++++++++
 .../maven/model/validation/DefaultModelValidator.java  | 18 ++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git 
a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java
 
b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java
index 30dab0bd7c..5c540bd449 100644
--- 
a/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java
+++ 
b/maven-api-impl/src/main/java/org/apache/maven/internal/impl/model/DefaultModelValidator.java
@@ -78,6 +78,8 @@ import org.apache.maven.model.v4.MavenTransformer;
 @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"));
@@ -699,6 +701,22 @@ 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 (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) {
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 f11407e271..4fb50941da 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
@@ -80,6 +80,8 @@ import org.apache.maven.model.v4.MavenTransformer;
 @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"));
@@ -691,6 +693,22 @@ 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 (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) {

Reply via email to