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

[MNG-8586] Expose Maven version segments as properties #2116

Merged
merged 4 commits into from
Feb 21, 2025

Conversation

cstamas
Copy link
Member

@cstamas cstamas commented Feb 17, 2025

Expose version segments. Also add the properties to generated doco.


https://issues.apache.org/jira/browse/MNG-8586

@cstamas cstamas self-assigned this Feb 17, 2025
@slawekjaranowski
Copy link
Member

What do you think about to add to org.apache.maven.rtinfo.RuntimeInformation

@cstamas
Copy link
Member Author

cstamas commented Feb 17, 2025

IMO not needed, that one is used for "programmatic access" and there caller can do with version string whatever he wants. The main idea behind this PR is to be able to create profile in POM that is active in Maven4 only, and have it done in Maven3 compatible way (as Model 4.1.0 already have advanced expressions like inrange(${maven.version}, '[4,)'))

@cstamas
Copy link
Member Author

cstamas commented Feb 17, 2025

Example with this merged:

  • maven3: profile with property activation like <name>!maven.version.major</name> -- not even defined => this is Maven3 or older
  • maven4: profile with property action like <name>maven.verson.major</name> and <value>4</value>.

@cstamas
Copy link
Member Author

cstamas commented Feb 18, 2025

@gnodet @slawekjaranowski given maven.version.major "does the job" (for use case explained above) am tinkering to we want maybe to lower what we expose here? Is minor/patch/snap really needed? For example, snap may be useful (i can imagine some IT with it that changes something or not), but patch and minor?

@Bukama
Copy link

Bukama commented Feb 18, 2025

@gnodet @slawekjaranowski given maven.version.major "does the job" (for use case explained above) am tinkering to we want maybe to lower what we expose here? Is minor/patch/snap really needed? For example, snap may be useful (i can imagine some IT with it that changes something or not), but patch and minor?

I'm neither one of the two, but I would publish all three. Allows more flexibility, use cases we are not aware of yet and even more: Prevents confusion on the users side.

@slawekjaranowski
Copy link
Member

@gnodet @slawekjaranowski given maven.version.major "does the job" (for use case explained above) am tinkering to we want maybe to lower what we expose here? Is minor/patch/snap really needed? For example, snap may be useful (i can imagine some IT with it that changes something or not), but patch and minor?

can be all for consistency

@cstamas cstamas added this to the 4.0.0-rc-3 milestone Feb 19, 2025
if (versionElements.length != 3) {
throw new IllegalStateException("Maven version is expected to have 3 segments: '" + mavenVersion + "'");
}
systemProperties.setProperty("maven.version.major", versionElements[0]);
Copy link
Contributor

Choose a reason for hiding this comment

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

Those need to be in Constants so that they are documented properly.

@cstamas cstamas requested review from Bukama and gnodet February 21, 2025 10:05
@cstamas cstamas marked this pull request as ready for review February 21, 2025 10:05
public static final String MAVEN_HOME = "maven.home";

/**
* Maven version.
Copy link

Choose a reason for hiding this comment

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

I suggest to add small examples to the javadoc - yes with semver most of them should be clear, but I think it helps the reader to clearly read the difference of all properties here together.

systemProperties.setProperty("maven.version", mavenVersion);
systemProperties.setProperty(Constants.MAVEN_VERSION, mavenVersion);

boolean snapshot = mavenVersion.endsWith("SNAPSHOT");
Copy link

Choose a reason for hiding this comment

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

Is the SNAPSHOT-String somewhere globally defined or is it written over and over again?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe use VersionParser#isSnapshot(String) method to abstract a bit ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I disagree here: first, this happens very early, no Maven session (to ask for service), no DI even, not even lookup invoker yet, this is just parsing of inputs. Second, this same code must perform string ops to split (and remove if present) the snapshot trailing string, is not only about detecting its presence. And finally, this is not some "generic" version munging, this is maven version, and IMO we should just do it as low-tech as possible. Of course, if we once decide to change the versioning scheme of Maven itself, this code will need to adapt. But today, this is completely fine.

This is not about _generic artifact version_, this is about
Maven version, and we decide what and how it is formed. Also,
we want to peel of SNAP qualifier if present.

Basically we do it low-tech way, as possible. Naturally,
if we change versioning of Maven, this could will have to
follow it.
@cstamas cstamas merged commit efae0a4 into apache:master Feb 21, 2025
11 of 13 checks passed
@cstamas cstamas deleted the MNG-8586 branch February 21, 2025 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants