mirror of https://github.com/apache/maven.git
[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
This commit is contained in:
parent
76ff89f507
commit
0d5ab52ac4
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue