|
| 1 | +[[single-version-declarations]] |
| 2 | += Single version declarations |
| 3 | + |
| 4 | +The simplest version declaration is a _simple string_ representing the version to use. |
| 5 | +Gradle supports different ways of declaring a version string: |
| 6 | + |
| 7 | +* An exact version: e.g. `1.3`, `1.3.0-beta3`, `1.0-20150201.131010-1` |
| 8 | +* A Maven-style version range: e.g. `[1.0,)`, `[1.1, 2.0)`, `(1.2, 1.5]` |
| 9 | +** The `[` and `]` symbols indicate an inclusive bound; `(` and `)` indicate an exclusive bound. |
| 10 | +** When the upper or lower bound is missing, the range has no upper or lower bound. |
| 11 | +** The symbol `]` can be used instead of `(` for an exclusive lower bound, and `[` instead of `)` for exclusive upper bound. e.g `]1.0, 2.0[` |
| 12 | +* A _prefix_ version range: e.g. `1.+`, `1.3.+` |
| 13 | +** Only versions exactly matching the portion before the `+` are included. |
| 14 | +** The range `+` on it's own will include any version. |
| 15 | +* A `latest-status` version: e.g. `latest.integration`, `latest.release` |
| 16 | +** Will match the highest versioned module with the specified status. See link:{javadocPath}/org/gradle/api/artifacts/ComponentMetadata.html#getStatus--[ComponentMetadata.getStatus()]. |
| 17 | +* A Maven `SNAPSHOT` version identifier: e.g. `1.0-SNAPSHOT`, `1.4.9-beta1-SNAPSHOT` |
| 18 | + |
| 19 | +== Version ordering |
| 20 | + |
| 21 | +Versions have an implicit ordering. Version ordering is used to: |
| 22 | +* Determine if a particular version is included in a range. |
| 23 | +* Determine which version is 'newest' when performing conflict resolution. |
| 24 | + |
| 25 | +Versions are ordered based on the following rules: |
| 26 | + |
| 27 | +* Each version is split into it's constituent "parts": |
| 28 | +** The characters `[. - _ +]` are used to separate the different "parts" of a version. |
| 29 | +** Any part that contains both digits and letters is split into separate parts for each: `1a1 == 1.a.1` |
| 30 | +** Only the parts of a version are compared. The actual separator characters are not significant: `1.a.1 == 1-a+1 == 1.a-1 == 1a1` |
| 31 | +* The equivalent parts of 2 versions are compared using the following rules: |
| 32 | +** If both parts are numeric, the highest numeric value is **higher**: `1.1` < `1.2` |
| 33 | +** If one part is numeric, it is considered **higher** than the non-numeric part: `1.a` < `1.1` |
| 34 | +** If both are not numeric, the parts are compared **alphabetically, case-sensitive**: `1.a` < `1.A` < `1.b` < `1.B` |
| 35 | +** A version with an extra numeric part is considered **higher** than a version without: `1.1` < `1.1.0` |
| 36 | +** A version with an extra non-numeric part is considered **lower** than a version without: `1.1` < `1.1.a` |
| 37 | +* Certain string values have special meaning for the purposes of ordering: |
| 38 | +** The string `dev` is consider **lower** than any other string part: `1.0-dev` < `1.0-alpha` < `1.0-rc`. |
| 39 | +** The strings `rc`, `release` and `final` are considered **higher** than any other string part (sorted in that order): `1.0-zeta` < `1.0-rc` < `1.0-release` < `1.0-final` < `1.0`. |
| 40 | +** The string `SNAPSHOT` has **no special meaning**, and is sorted alphabetically like any other string part: `1.0-alpha` < `1.0-SNAPSHOT` < `1.0-zeta` < `1.0-rc` < `1.0`. |
| 41 | +** Numeric snapshot versions have **no special meaning**, and are sorted like any other numeric part: `1.0` < `1.0-20150201.121010-123` < `1.1`. |
| 42 | + |
| 43 | +== Simple version declaration semantics |
| 44 | + |
| 45 | +When you declare a version using the short-hand notation, for example: |
| 46 | + |
| 47 | +.A simple declaration |
| 48 | +==== |
| 49 | +include::sample[dir="userguide/dependencyManagement/declaringDependencies/concreteVersion/groovy",files="build.gradle[tags=required-version]"] |
| 50 | +include::sample[dir="userguide/dependencyManagement/declaringDependencies/concreteVersion/kotlin",files="build.gradle.kts[tags=required-version]"] |
| 51 | +==== |
| 52 | + |
| 53 | +Then the version is considered a <<rich_versions.adoc#sec:required-version,required version>> which means that it should _minimally_ be `1.7.15` but can be upgraded by the engine (optimistic upgrade). |
| 54 | + |
| 55 | +There is, however, a shorthand notation for <<rich_versions.adoc#sec:strict-version,strict versions>>, using the `!!` notation: |
| 56 | + |
| 57 | +.Shorthand notation for strict dependencies |
| 58 | +==== |
| 59 | +include::sample[dir="userguide/dependencyManagement/declaringDependencies/concreteVersion/groovy",files="build.gradle[tags=strict-shorthand]"] |
| 60 | +include::sample[dir="userguide/dependencyManagement/declaringDependencies/concreteVersion/kotlin",files="build.gradle.kts[tags=strict-shorthand]"] |
| 61 | +==== |
| 62 | + |
| 63 | +A strict version _cannot be upgraded_ and overrides whatever transitive dependencies originating from this dependency provide. |
| 64 | +It is recommended to use ranges for strict versions. |
| 65 | + |
| 66 | +The notation `[1.7, 1.8[!!1.7.25` above is equivalent to: |
| 67 | + |
| 68 | +* strictly `[1.7, 1.8[` |
| 69 | +* prefer `1.7.25` |
| 70 | + |
| 71 | +which means that the engine **must** select a version between 1.7 (included) and 1.8 (excluded), and that if no other component in the graph needs a different version, it should _prefer_ `1.7.25`. |
| 72 | + |
| 73 | +The section below explains the semantics of rich version constraints in details. |
0 commit comments