The maven dependency level is not working properly

Maven 2.2.1 claims to support version ranges (see, for example, http://www.sonatype.com/books/mvnref-book/reference/pom-relationships-sect-project-dependencies.html#pom-relationships- sect-version-ranges )

I tried using brand new maven to install the following pom:

<project>

  <modelVersion>4.0.0</modelVersion>
  <artifactId>rangetest</artifactId>
  <groupId>my.group</groupId>
  <version>1.0</version>
  <packaging>jar</packaging>

  <description>test project containing one dependency, only</description>
  <dependencies>
   <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.8</version>
    <scope>test</scope>
   </dependency>
  </dependencies>
 </project>

The dependency should match junit 4.8.2, right? But instead, version 4.8 is allowed:

C:\Users>mvn dependency:tree
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'dependency'.
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - my.group:rangetest:jar:1.0
[INFO]    task-segment: [dependency:tree]
[INFO] ------------------------------------------------------------------------
[INFO] [dependency:tree {execution: default-cli}]
[INFO] my.group:rangetest:jar:1.0
[INFO] \- junit:junit:jar:4.8:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Thu Oct 07 14:30:40 CEST 2010
[INFO] Final Memory: 9M/23M
[INFO] ------------------------------------------------------------------------

You might think that this is a problem with Junit, since 4.8 is an existing version, but it is not. In my projects, I have versions deployed from 1.0.0 to 1.0.15 (without version 1.0!), But mvn dependency:treecomplains about the lack of artifact version 1.0.

+3
3

, POM. 4.8, , Maven . [ ( ( , ).

: [4.8,4.9)

API (.. , ).

, Maven : https://maven.apache.org/enforcer/enforcer-rules/versionRanges.html

, -, (4.8 " 4.8" ), : Maven , - . , POM , 4.8.2, 4.8 " " Maven.

. POM A 4.8, B 4.8.2 B A, Maven . ? 4.8? 4.8.2?

4.8.2 .

A [4.8], , Maven "" 4.8.2 , , 4.8.2 4.8.

+7

, , . .

, , - , , , - , - . , (, ).

+6

version . , , 4.8 :

<version>[4.8,)</version>
+2
source

Source: https://habr.com/ru/post/1768409/


All Articles