From 325a1a8dc1a1ce6f17415d85bbfb877ff0fe5a64 Mon Sep 17 00:00:00 2001 From: Jerome Prinet Date: Mon, 9 Oct 2023 15:58:28 +0200 Subject: [PATCH] Check current Maven version is aligned with wrapper Maven version --- .../gradle-enterprise-custom-user-data.groovy | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.mvn/gradle-enterprise-custom-user-data.groovy b/.mvn/gradle-enterprise-custom-user-data.groovy index a076e48718294..8e78dcf99e597 100644 --- a/.mvn/gradle-enterprise-custom-user-data.groovy +++ b/.mvn/gradle-enterprise-custom-user-data.groovy @@ -96,3 +96,23 @@ if (System.env.GITHUB_ACTIONS) { } } +// Check runtime Maven version and Maven Wrapper version are aligned +def runtimeInfo = (org.apache.maven.rtinfo.RuntimeInformation) session.lookup("org.apache.maven.rtinfo.RuntimeInformation") +def runtimeMavenVersion = runtimeInfo?.getMavenVersion() +Properties mavenWrapperProperties = new Properties() +File mavenWrapperPropertiesFile = new File(".mvn/wrapper/maven-wrapper.properties") +if(mavenWrapperPropertiesFile.exists()) { + mavenWrapperPropertiesFile.withInputStream { + mavenWrapperProperties.load(it) + } + // assuming the wrapper properties contains: + // distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/VERSION/apache-maven-VERSION-bin.zip + if(regexp = mavenWrapperProperties."distributionUrl" =~ /.*\/apache-maven-(.*)-bin\.zip/) { + def wrapperMavenVersion = regexp.group(1) + if (runtimeMavenVersion && wrapperMavenVersion && wrapperMavenVersion != runtimeMavenVersion) { + log.warn("Maven Wrapper is configured with a different version (" + wrapperMavenVersion + ") than the runtime version (" + runtimeMavenVersion + "). This will negatively impact build consistency and build caching.") + buildScan.tag("misaligned-maven-version") + buildScan.value("wrapper-maven-version", wrapperMavenVersion) + } + } +}