Maven 2 & 3

<jdk></jdk> clause in the activation section has to provide more complex expressions.

Details

  • Type: Improvement Improvement
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0, 2.0.1
  • Fix Version/s: 2.1.0
  • Component/s: POM
  • Labels:
    None
  • Complexity:
    Novice
  • Patch Submitted:
    Yes
  • Number of attachments :
    1

Description

For now, <jdk></jdk> provides only one operator '!' which means negation, but it would be great if i can use '+' and ~ operator:

<jdk>1.5+</jdk> <!-- this will be activated when the current JDK version is 1.5 or above (e.g. 1.6) -->
<jdk>1.1 ~ 1.4</jdk> <!-- this will be activated when the current JDK version is between 1.1 and 1.4 -->
<jdk>~ 1.3</jdk> <!-- this will be activated when the current JDK version is 1.3 or below -->
<jdk>1.4 ~</jdk. <!-- the same with 1.5+ -->

Issue Links

Activity

Hide
Edwin Punzalan added a comment -

I like this and am voting for it. This is useful for instances like javax.management being already available in JDK 1.5 so you'll want to put the dependency for it and its implementation when the JDK is "~ 1.5".

Show
Edwin Punzalan added a comment - I like this and am voting for it. This is useful for instances like javax.management being already available in JDK 1.5 so you'll want to put the dependency for it and its implementation when the JDK is "~ 1.5".
Hide
Eric Redmond added a comment -

To keep consistent, I think I'd rather prefer the version range syntax that dependency versions use.

Show
Eric Redmond added a comment - To keep consistent, I think I'd rather prefer the version range syntax that dependency versions use.
Hide
Tim Hedger added a comment -

VersionRange syntax doesn't support the ! negation syntax that the current <jdk> tag allows.
Maximum reusability/simplicity here will be to use the existing VersionRange syntax (as you mention Eric used for dependency versions), but for backwards compatibility on <jdk> that would mean allowing ! to be used in dependency versions. Is this OK?

Show
Tim Hedger added a comment - VersionRange syntax doesn't support the ! negation syntax that the current <jdk> tag allows. Maximum reusability/simplicity here will be to use the existing VersionRange syntax (as you mention Eric used for dependency versions), but for backwards compatibility on <jdk> that would mean allowing ! to be used in dependency versions. Is this OK?
Hide
Trustin Lee added a comment -

Sounds good to me.

Show
Trustin Lee added a comment - Sounds good to me.
Hide
Carl Byström added a comment -

I just had brief look at the code and to me, implementing VersionRange-like syntax, comes down to three choices:

  • Use the existing VersionRange classes (which seems rather artifact dependendant, at least when it comes to naming. It's coupled with, for example, ArtifactVersion)
  • Copy the VersionRange class and make it compatible with the problem with try to solve here (code duplication?
  • Make VersionRange more abstract, make it handle different types versions. Such as Java JDK versions? They are a bit special since they use '_' to denote upgrade releases. But if you'd really like to use the VersionRange class, I guess you can trick it to handle JDK versions like ArtifactVersions (upgrade number can become build number).

I'm rather new to the Maven source code, so I'm in need of some guidance on this.

Show
Carl Byström added a comment - I just had brief look at the code and to me, implementing VersionRange-like syntax, comes down to three choices:
  • Use the existing VersionRange classes (which seems rather artifact dependendant, at least when it comes to naming. It's coupled with, for example, ArtifactVersion)
  • Copy the VersionRange class and make it compatible with the problem with try to solve here (code duplication?
  • Make VersionRange more abstract, make it handle different types versions. Such as Java JDK versions? They are a bit special since they use '_' to denote upgrade releases. But if you'd really like to use the VersionRange class, I guess you can trick it to handle JDK versions like ArtifactVersions (upgrade number can become build number).
I'm rather new to the Maven source code, so I'm in need of some guidance on this.
Hide
Torben S. Giesselmann added a comment -

This patch implements the following behavior for JDK version matching:

  • current version matching behavior (JDK_VERSION.startsWith( jdk ), negation through "!")
  • version ranges (by using VersionRange, upgrade number becomes build number)
  • negation operator "!" works for version ranges as well
Show
Torben S. Giesselmann added a comment - This patch implements the following behavior for JDK version matching:
  • current version matching behavior (JDK_VERSION.startsWith( jdk ), negation through "!")
  • version ranges (by using VersionRange, upgrade number becomes build number)
  • negation operator "!" works for version ranges as well
Hide
Joerg Schaible added a comment -

Guys, please take into account that you probably do not get what you try to reach. Especially Edwin's use case will not work. By declaring different dependencies in profiles that are automatically activated based on the used JDK you all implicitly assume that this is also the target JDK. This assumption is false! Have a look at the error reports in MNG-3957 caused by such profiles in spring-core-ws and XStream. Both POMs declare different deps depending on the JDK. If a client now declares a different target JDK than the one he uses to run Maven, he gets the wrong transitive dependencies.

Show
Joerg Schaible added a comment - Guys, please take into account that you probably do not get what you try to reach. Especially Edwin's use case will not work. By declaring different dependencies in profiles that are automatically activated based on the used JDK you all implicitly assume that this is also the target JDK. This assumption is false! Have a look at the error reports in MNG-3957 caused by such profiles in spring-core-ws and XStream. Both POMs declare different deps depending on the JDK. If a client now declares a different target JDK than the one he uses to run Maven, he gets the wrong transitive dependencies.
Hide
Brett Porter added a comment -

Joerg - you are correct, and this needs to be worked into the toolchains implementation. As it stands, however, this change seems like an improvement to the existing logic.

Show
Brett Porter added a comment - Joerg - you are correct, and this needs to be worked into the toolchains implementation. As it stands, however, this change seems like an improvement to the existing logic.
Hide
Brett Porter added a comment -

applied, thanks!

I made one modification - ! is not valid for ranges. I think per the thread on dev@ this is a bit confusing - best to be range or nothing.

I added some tests, but still have an IT and docs to add before closing it out (more patches welcome

Show
Brett Porter added a comment - applied, thanks! I made one modification - ! is not valid for ranges. I think per the thread on dev@ this is a bit confusing - best to be range or nothing. I added some tests, but still have an IT and docs to add before closing it out (more patches welcome
Hide
Brett Porter added a comment -

closing as done - we may need to revisit depending on current dev@ discussion about whether to support ranges, or MNG-1910's syntax of 1.4+

Show
Brett Porter added a comment - closing as done - we may need to revisit depending on current dev@ discussion about whether to support ranges, or MNG-1910's syntax of 1.4+

People

Vote (4)
Watch (6)

Dates

  • Created:
    Updated:
    Resolved: