Skip to content

Commit

Permalink
Check current Maven version is aligned with wrapper Maven version
Browse files Browse the repository at this point in the history
  • Loading branch information
jprinet authored and gsmet committed Nov 21, 2023
1 parent 5fd4f01 commit 325a1a8
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .mvn/gradle-enterprise-custom-user-data.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

0 comments on commit 325a1a8

Please sign in to comment.