Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check runtime Maven version is aligned with wrapper Maven version #36357

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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/) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will work for Quarkus but we if the maven wrapper is distributed from a custom URL will this still work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am parsing here a standard URL, this could not work with a custom URL indeed.
I am adding a comment to describe what is expected.

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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it be valuable to add a custom value with the wrapper version? I'm assuming that the runtime version is already part of the scan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think it was necessary at first thought as the version can be obtained in the Git repo, let's add it to simplify investigation if any 👍

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'm not sure it is needed if it is in the repo then. It was just a thought.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add it, Guillaume will decide if they want it or not

buildScan.value("wrapper-maven-version", wrapperMavenVersion)
}
}
}