diff --git a/README.md b/README.md index dcf6f124..eccbc22c 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ This action allows you to work with Java and Scala projects. ## Usage - - `java-version`: _(required)_ The Java version to set up. Takes a whole or [semver](#supported-version-syntax) Java version. + - `java-version`: The Java version to set up. Takes a whole or [semver](#supported-version-syntax) Java version. If not specified, the action will expect `.java-version` file to be in the repository root. See [more details](docs/advanced-usage.md#Java-version-file) in about `.java-version` file. - `distribution`: _(required)_ Java [distribution](#supported-distributions). diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 6423d06c..88ecc0c4 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -16,6 +16,7 @@ - [Publishing using Gradle](#Publishing-using-Gradle) - [Hosted Tool Cache](#Hosted-Tool-Cache) - [Modifying Maven Toolchains](#Modifying-Maven-Toolchains) +- [Java-version file](#Java-version-file) See [action.yml](../action.yml) for more details on task inputs. @@ -478,3 +479,20 @@ steps: something_else something_other ``` + +## Java-version file +If the `java-version` input is not specified, the action will look for a `.java-version` file at the root of the repository. If the file is found, action will try to install the most suitable version. +Action is able to recognize all variants of the version description according to [jenv](https://github.com/jenv/jenv). +Valid entry options: +``` +major versions: 8, 11, 16, 17 +more specific versions: 17.0, 11.0, 11.0.4, 8.0.232, 8.0.282+8 +early access (EA) versions: 15-ea, 15.0.0-ea, 15.0.0-ea.2, 15.0.0+2-ea +versions with specified distribution: openjdk64-11.0.2 +``` +If the file contains multiple versions, only the first one will be recognized. +If action was able to recognize a version in the file that matches the pattern, then attempts will begin to install the most appropriate version. The logic for installing the appropriate version: +action will try to install the specified version. If this version is not available for a given distribution, action will try to install a less specific version according to the algorithm. Attempts will continue until a suitable version is installed or the attempt to install a version specifying only with major tag fails. +Algorithm for selecting the appropriate version: +If a particular patch specification was present in the version (for example, the early access postfix `-ea*` in `major.minor.patch-ea*` notation), action will try to install the version without it in the format `major.minor.patch`. Next, if the install fails again, action will try to install the `major.minor` version. On failure, action will try to install the `major` version and fail on failure. +If the version was originally specified not in full format, then the process will be similar, but it will not start from the first step. \ No newline at end of file