mirror of
https://github.com/actions/setup-java.git
synced 2026-07-08 10:11:34 +08:00
feat: Add set-default option (#1017)
* Add set-default option This option allows to install an additional JDK without making it the default one. I have wanted this for quite a long time as I'm running custom GitHub Actions with Java, which might require a specific JDK and I don't want to pollute the JDK that is used by the overall workflow calling the action. And I'm apparently not alone as there was a preexisting issue. Fixes #560 * Dedupe setJavaDefault and document multi-version/toolchain behavior - Refactor setJavaDefault to delegate shared output/env logic to setJavaEnvironment, avoiding duplication between the two. - Document that set-default applies to all JDKs in a multiline java-version, and that installed JDKs remain registered in Maven toolchains regardless of set-default. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * test: fix Prettier formatting in base-installer test Resolves the failing 'Basic validation / build' format-check on __tests__/distributors/base-installer.test.ts (line exceeded print width). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Bruno Borges <brborges@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -669,3 +669,77 @@ jobs:
|
|||||||
JAVA_PATH: ${{ steps.setup-java.outputs.path }}
|
JAVA_PATH: ${{ steps.setup-java.outputs.path }}
|
||||||
run: bash __tests__/verify-java.sh "17.0.10" "$JAVA_PATH"
|
run: bash __tests__/verify-java.sh "17.0.10" "$JAVA_PATH"
|
||||||
shell: bash
|
shell: bash
|
||||||
|
|
||||||
|
setup-java-set-default:
|
||||||
|
name: set-default option - ${{ matrix.os }}
|
||||||
|
needs: setup-java-major-versions
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
fail-fast: false
|
||||||
|
matrix:
|
||||||
|
os: [macos-latest, windows-latest, ubuntu-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v6
|
||||||
|
- name: Setup Java 17 as default
|
||||||
|
uses: ./
|
||||||
|
id: setup-java-17
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '17'
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Setup Java 21 without setting as default
|
||||||
|
uses: ./
|
||||||
|
id: setup-java-21
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '21'
|
||||||
|
set-default: false
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
- name: Verify JAVA_HOME still points to Java 17
|
||||||
|
run: |
|
||||||
|
echo "JAVA_HOME=$JAVA_HOME"
|
||||||
|
echo "Java 17 path=${{ steps.setup-java-17.outputs.path }}"
|
||||||
|
if [ "$JAVA_HOME" != "${{ steps.setup-java-17.outputs.path }}" ]; then
|
||||||
|
echo "JAVA_HOME should still point to Java 17"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
- name: Verify java -version reports Java 17
|
||||||
|
run: |
|
||||||
|
JAVA_VERSION=$(java -version 2>&1 | head -1)
|
||||||
|
echo "java -version: $JAVA_VERSION"
|
||||||
|
if ! echo "$JAVA_VERSION" | grep -q "17"; then
|
||||||
|
echo "Default java should still be version 17"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
- name: Verify JAVA_HOME_21 env var is set
|
||||||
|
run: |
|
||||||
|
$envName = "JAVA_HOME_21_${env:RUNNER_ARCH}"
|
||||||
|
$JavaVersionPath = [Environment]::GetEnvironmentVariable($envName)
|
||||||
|
if (-not $JavaVersionPath) {
|
||||||
|
Write-Host "$envName is not set"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
if (-not (Test-Path "$JavaVersionPath")) {
|
||||||
|
Write-Host "$envName path does not exist: $JavaVersionPath"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
Write-Host "$envName=$JavaVersionPath"
|
||||||
|
shell: pwsh
|
||||||
|
- name: Verify Java 21 outputs are set
|
||||||
|
run: |
|
||||||
|
echo "Java 21 path=${{ steps.setup-java-21.outputs.path }}"
|
||||||
|
echo "Java 21 version=${{ steps.setup-java-21.outputs.version }}"
|
||||||
|
if [ -z "${{ steps.setup-java-21.outputs.path }}" ]; then
|
||||||
|
echo "Java 21 path output should be set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [ -z "${{ steps.setup-java-21.outputs.version }}" ]; then
|
||||||
|
echo "Java 21 version output should be set"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
shell: bash
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ For more details, see the full release notes on the [releases page](https://git
|
|||||||
|
|
||||||
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
|
- `check-latest`: Setting this option makes the action to check for the latest available version for the version spec.
|
||||||
|
|
||||||
|
- `set-default`: Set to `false` to install a JDK without making it the default. When `false`, `JAVA_HOME` and `PATH` are not updated, but `JAVA_HOME_<major>_<arch>` is still set so the JDK remains discoverable. Default value: `true`. See [Installing JDK without setting as default](docs/advanced-usage.md#Installing-JDK-without-setting-as-default) for more details.
|
||||||
|
|
||||||
- `verify-signature`: Verifies downloaded Java package signatures when supported by the selected distribution. Currently supported for `temurin` and `microsoft`. If set to `true` for unsupported distributions, the action fails.
|
- `verify-signature`: Verifies downloaded Java package signatures when supported by the selected distribution. Currently supported for `temurin` and `microsoft`. If set to `true` for unsupported distributions, the action fails.
|
||||||
|
|
||||||
- `verify-signature-public-key`: ASCII-armored GPG public key used to verify the downloaded package signature. Overrides the default bundled key for the selected distribution.
|
- `verify-signature-public-key`: ASCII-armored GPG public key used to verify the downloaded package signature. Overrides the default bundled key for the selected distribution.
|
||||||
|
|||||||
@@ -563,6 +563,110 @@ describe('setupJava', () => {
|
|||||||
expect(spyCoreExportVariable).not.toHaveBeenCalled();
|
expect(spyCoreExportVariable).not.toHaveBeenCalled();
|
||||||
expect(spyCoreSetOutput).not.toHaveBeenCalled();
|
expect(spyCoreSetOutput).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not set JAVA_HOME and PATH when setDefault is false', async () => {
|
||||||
|
mockJavaBase = new EmptyJavaBase({
|
||||||
|
version: '11',
|
||||||
|
architecture: 'x86',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false,
|
||||||
|
setDefault: false
|
||||||
|
});
|
||||||
|
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||||
|
version: installedJavaVersion,
|
||||||
|
path: javaPath
|
||||||
|
});
|
||||||
|
expect(spyCoreExportVariable).not.toHaveBeenCalledWith(
|
||||||
|
'JAVA_HOME',
|
||||||
|
expect.anything()
|
||||||
|
);
|
||||||
|
expect(spyCoreAddPath).not.toHaveBeenCalled();
|
||||||
|
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||||
|
'JAVA_HOME_11_X86',
|
||||||
|
javaPath
|
||||||
|
);
|
||||||
|
expect(spyCoreSetOutput).toHaveBeenCalledWith(
|
||||||
|
'version',
|
||||||
|
installedJavaVersion
|
||||||
|
);
|
||||||
|
expect(spyCoreSetOutput).toHaveBeenCalledWith('path', javaPath);
|
||||||
|
expect(spyCoreSetOutput).toHaveBeenCalledWith('distribution', 'Empty');
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||||
|
`Installing Java ${installedJavaVersion} (not setting as default)`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set JAVA_HOME and PATH when setDefault is true', async () => {
|
||||||
|
mockJavaBase = new EmptyJavaBase({
|
||||||
|
version: '11',
|
||||||
|
architecture: 'x86',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false,
|
||||||
|
setDefault: true
|
||||||
|
});
|
||||||
|
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||||
|
version: installedJavaVersion,
|
||||||
|
path: javaPath
|
||||||
|
});
|
||||||
|
expect(spyCoreExportVariable).toHaveBeenCalledWith('JAVA_HOME', javaPath);
|
||||||
|
expect(spyCoreAddPath).toHaveBeenCalledWith(path.join(javaPath, 'bin'));
|
||||||
|
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||||
|
'JAVA_HOME_11_X86',
|
||||||
|
javaPath
|
||||||
|
);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||||
|
`Setting Java ${installedJavaVersion} as the default`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should default to setting as default when setDefault is not specified', async () => {
|
||||||
|
mockJavaBase = new EmptyJavaBase({
|
||||||
|
version: '11',
|
||||||
|
architecture: 'x86',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false
|
||||||
|
});
|
||||||
|
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||||
|
version: installedJavaVersion,
|
||||||
|
path: javaPath
|
||||||
|
});
|
||||||
|
expect(spyCoreExportVariable).toHaveBeenCalledWith('JAVA_HOME', javaPath);
|
||||||
|
expect(spyCoreAddPath).toHaveBeenCalledWith(path.join(javaPath, 'bin'));
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||||
|
`Setting Java ${installedJavaVersion} as the default`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should download and not set default when setDefault is false', async () => {
|
||||||
|
mockJavaBase = new EmptyJavaBase({
|
||||||
|
version: '11',
|
||||||
|
architecture: 'x64',
|
||||||
|
packageType: 'jdk',
|
||||||
|
checkLatest: false,
|
||||||
|
setDefault: false
|
||||||
|
});
|
||||||
|
await expect(mockJavaBase.setupJava()).resolves.toEqual({
|
||||||
|
version: '11.0.9',
|
||||||
|
path: path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64')
|
||||||
|
});
|
||||||
|
expect(spyCoreExportVariable).not.toHaveBeenCalledWith(
|
||||||
|
'JAVA_HOME',
|
||||||
|
expect.anything()
|
||||||
|
);
|
||||||
|
expect(spyCoreAddPath).not.toHaveBeenCalled();
|
||||||
|
expect(spyCoreExportVariable).toHaveBeenCalledWith(
|
||||||
|
'JAVA_HOME_11_X64',
|
||||||
|
path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64')
|
||||||
|
);
|
||||||
|
expect(spyCoreSetOutput).toHaveBeenCalledWith('version', '11.0.9');
|
||||||
|
expect(spyCoreSetOutput).toHaveBeenCalledWith(
|
||||||
|
'path',
|
||||||
|
path.join('toolcache', 'Java_Empty_jdk', '11.0.9', 'x64')
|
||||||
|
);
|
||||||
|
expect(spyCoreInfo).toHaveBeenCalledWith(
|
||||||
|
'Installing Java 11.0.9 (not setting as default)'
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('normalizeVersion', () => {
|
describe('normalizeVersion', () => {
|
||||||
|
|||||||
@@ -26,6 +26,10 @@ inputs:
|
|||||||
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
|
||||||
required: false
|
required: false
|
||||||
default: false
|
default: false
|
||||||
|
set-default:
|
||||||
|
description: 'Set this option to false if you want to install a JDK but not make it the default. When false, JAVA_HOME and PATH are not updated, but JAVA_HOME_<major>_<arch> is still set.'
|
||||||
|
required: false
|
||||||
|
default: true
|
||||||
verify-signature:
|
verify-signature:
|
||||||
description: 'Verify downloaded Java package signatures when supported by the selected distribution'
|
description: 'Verify downloaded Java package signatures when supported by the selected distribution'
|
||||||
required: false
|
required: false
|
||||||
|
|||||||
Vendored
+2
-1
@@ -52241,7 +52241,7 @@ else {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_SET_DEFAULT = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||||
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||||
exports.INPUT_JAVA_VERSION = 'java-version';
|
exports.INPUT_JAVA_VERSION = 'java-version';
|
||||||
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||||
@@ -52250,6 +52250,7 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
|
|||||||
exports.INPUT_DISTRIBUTION = 'distribution';
|
exports.INPUT_DISTRIBUTION = 'distribution';
|
||||||
exports.INPUT_JDK_FILE = 'jdkFile';
|
exports.INPUT_JDK_FILE = 'jdkFile';
|
||||||
exports.INPUT_CHECK_LATEST = 'check-latest';
|
exports.INPUT_CHECK_LATEST = 'check-latest';
|
||||||
|
exports.INPUT_SET_DEFAULT = 'set-default';
|
||||||
exports.INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
exports.INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||||
exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
||||||
exports.INPUT_SERVER_ID = 'server-id';
|
exports.INPUT_SERVER_ID = 'server-id';
|
||||||
|
|||||||
Vendored
+27
-4
@@ -78001,7 +78001,7 @@ function isProbablyGradleDaemonProblem(packageManager, error) {
|
|||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = exports.MAVEN_ARGS_ENV = exports.INPUT_SHOW_DOWNLOAD_PROGRESS = exports.INPUT_MVN_TOOLCHAIN_VENDOR = exports.INPUT_MVN_TOOLCHAIN_ID = exports.MVN_TOOLCHAINS_FILE = exports.MVN_SETTINGS_FILE = exports.M2_DIR = exports.STATE_GPG_PRIVATE_KEY_FINGERPRINT = exports.INPUT_JOB_STATUS = exports.INPUT_CACHE_DEPENDENCY_PATH = exports.INPUT_CACHE = exports.INPUT_DEFAULT_GPG_PASSPHRASE = exports.INPUT_DEFAULT_GPG_PRIVATE_KEY = exports.INPUT_GPG_PASSPHRASE = exports.INPUT_GPG_PRIVATE_KEY = exports.INPUT_OVERWRITE_SETTINGS = exports.INPUT_SETTINGS_PATH = exports.INPUT_SERVER_PASSWORD = exports.INPUT_SERVER_USERNAME = exports.INPUT_SERVER_ID = exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = exports.INPUT_VERIFY_SIGNATURE = exports.INPUT_SET_DEFAULT = exports.INPUT_CHECK_LATEST = exports.INPUT_JDK_FILE = exports.INPUT_DISTRIBUTION = exports.INPUT_JAVA_PACKAGE = exports.INPUT_ARCHITECTURE = exports.INPUT_JAVA_VERSION_FILE = exports.INPUT_JAVA_VERSION = exports.MACOS_JAVA_CONTENT_POSTFIX = void 0;
|
||||||
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
exports.MACOS_JAVA_CONTENT_POSTFIX = 'Contents/Home';
|
||||||
exports.INPUT_JAVA_VERSION = 'java-version';
|
exports.INPUT_JAVA_VERSION = 'java-version';
|
||||||
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
|
||||||
@@ -78010,6 +78010,7 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
|
|||||||
exports.INPUT_DISTRIBUTION = 'distribution';
|
exports.INPUT_DISTRIBUTION = 'distribution';
|
||||||
exports.INPUT_JDK_FILE = 'jdkFile';
|
exports.INPUT_JDK_FILE = 'jdkFile';
|
||||||
exports.INPUT_CHECK_LATEST = 'check-latest';
|
exports.INPUT_CHECK_LATEST = 'check-latest';
|
||||||
|
exports.INPUT_SET_DEFAULT = 'set-default';
|
||||||
exports.INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
exports.INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||||
exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
exports.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
||||||
exports.INPUT_SERVER_ID = 'server-id';
|
exports.INPUT_SERVER_ID = 'server-id';
|
||||||
@@ -78325,6 +78326,10 @@ class JavaBase {
|
|||||||
this.architecture = installerOptions.architecture || os_1.default.arch();
|
this.architecture = installerOptions.architecture || os_1.default.arch();
|
||||||
this.packageType = installerOptions.packageType;
|
this.packageType = installerOptions.packageType;
|
||||||
this.checkLatest = installerOptions.checkLatest;
|
this.checkLatest = installerOptions.checkLatest;
|
||||||
|
this.setDefault =
|
||||||
|
installerOptions.setDefault !== undefined
|
||||||
|
? installerOptions.setDefault
|
||||||
|
: true;
|
||||||
this.verifySignature = (_a = installerOptions.verifySignature) !== null && _a !== void 0 ? _a : false;
|
this.verifySignature = (_a = installerOptions.verifySignature) !== null && _a !== void 0 ? _a : false;
|
||||||
this.verifySignaturePublicKey = installerOptions.verifySignaturePublicKey;
|
this.verifySignaturePublicKey = installerOptions.verifySignaturePublicKey;
|
||||||
}
|
}
|
||||||
@@ -78445,8 +78450,14 @@ class JavaBase {
|
|||||||
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
|
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
|
||||||
foundJava.path = macOSPostfixPath;
|
foundJava.path = macOSPostfixPath;
|
||||||
}
|
}
|
||||||
|
if (this.setDefault) {
|
||||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Installing Java ${foundJava.version} (not setting as default)`);
|
||||||
|
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||||
|
}
|
||||||
return foundJava;
|
return foundJava;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -78547,9 +78558,12 @@ class JavaBase {
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
setJavaDefault(version, toolPath) {
|
setJavaDefault(version, toolPath) {
|
||||||
const majorVersion = version.split('.')[0];
|
|
||||||
core.exportVariable('JAVA_HOME', toolPath);
|
core.exportVariable('JAVA_HOME', toolPath);
|
||||||
core.addPath(path_1.default.join(toolPath, 'bin'));
|
core.addPath(path_1.default.join(toolPath, 'bin'));
|
||||||
|
this.setJavaEnvironment(version, toolPath);
|
||||||
|
}
|
||||||
|
setJavaEnvironment(version, toolPath) {
|
||||||
|
const majorVersion = version.split('.')[0];
|
||||||
core.setOutput('distribution', this.distribution);
|
core.setOutput('distribution', this.distribution);
|
||||||
core.setOutput('path', toolPath);
|
core.setOutput('path', toolPath);
|
||||||
core.setOutput('version', version);
|
core.setOutput('version', version);
|
||||||
@@ -80048,8 +80062,14 @@ class LocalDistribution extends base_installer_1.JavaBase {
|
|||||||
if (process.platform === 'darwin' && fs_1.default.existsSync(macOSPostfixPath)) {
|
if (process.platform === 'darwin' && fs_1.default.existsSync(macOSPostfixPath)) {
|
||||||
foundJava.path = macOSPostfixPath;
|
foundJava.path = macOSPostfixPath;
|
||||||
}
|
}
|
||||||
core.info(`Setting Java ${foundJava.version} as default`);
|
if (this.setDefault) {
|
||||||
|
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Installing Java ${foundJava.version} (not setting as default)`);
|
||||||
|
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||||
|
}
|
||||||
return foundJava;
|
return foundJava;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -81532,6 +81552,7 @@ function run() {
|
|||||||
const cache = core.getInput(constants.INPUT_CACHE);
|
const cache = core.getInput(constants.INPUT_CACHE);
|
||||||
const cacheDependencyPath = core.getInput(constants.INPUT_CACHE_DEPENDENCY_PATH);
|
const cacheDependencyPath = core.getInput(constants.INPUT_CACHE_DEPENDENCY_PATH);
|
||||||
const checkLatest = (0, util_1.getBooleanInput)(constants.INPUT_CHECK_LATEST, false);
|
const checkLatest = (0, util_1.getBooleanInput)(constants.INPUT_CHECK_LATEST, false);
|
||||||
|
const setDefault = (0, util_1.getBooleanInput)(constants.INPUT_SET_DEFAULT, true);
|
||||||
const verifySignature = (0, util_1.getBooleanInput)(constants.INPUT_VERIFY_SIGNATURE, false);
|
const verifySignature = (0, util_1.getBooleanInput)(constants.INPUT_VERIFY_SIGNATURE, false);
|
||||||
const verifySignaturePublicKey = core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
const verifySignaturePublicKey = core.getInput(constants.INPUT_VERIFY_SIGNATURE_PUBLIC_KEY) || undefined;
|
||||||
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
|
||||||
@@ -81546,6 +81567,7 @@ function run() {
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
distributionName,
|
distributionName,
|
||||||
@@ -81582,11 +81604,12 @@ function run() {
|
|||||||
run();
|
run();
|
||||||
function installVersion(version, options, toolchainId = 0) {
|
function installVersion(version, options, toolchainId = 0) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const { distributionName, jdkFile, architecture, packageType, checkLatest, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
|
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, verifySignature, verifySignaturePublicKey, toolchainIds } = options;
|
||||||
const installerOptions = {
|
const installerOptions = {
|
||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
version
|
version
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
- [Installing custom Java package type](#Installing-custom-Java-package-type)
|
- [Installing custom Java package type](#Installing-custom-Java-package-type)
|
||||||
- [JavaFX Maven project](#JavaFX-Maven-project)
|
- [JavaFX Maven project](#JavaFX-Maven-project)
|
||||||
- [Installing custom Java architecture](#Installing-custom-Java-architecture)
|
- [Installing custom Java architecture](#Installing-custom-Java-architecture)
|
||||||
|
- [Installing JDK without setting as default](#Installing-JDK-without-setting-as-default)
|
||||||
- [Installing custom Java distribution from local file](#Installing-Java-from-local-file)
|
- [Installing custom Java distribution from local file](#Installing-Java-from-local-file)
|
||||||
- [Testing against different Java distributions](#Testing-against-different-Java-distributions)
|
- [Testing against different Java distributions](#Testing-against-different-Java-distributions)
|
||||||
- [Testing against different platforms](#Testing-against-different-platforms)
|
- [Testing against different platforms](#Testing-against-different-platforms)
|
||||||
@@ -297,6 +298,34 @@ steps:
|
|||||||
- run: java --version
|
- run: java --version
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Installing JDK without setting as default
|
||||||
|
|
||||||
|
When installing multiple JDKs, the last one installed becomes the default (`JAVA_HOME`, `PATH`). Use the `set-default` option to install a JDK without overriding the default. The installed JDK is still discoverable via the `JAVA_HOME_<major>_<arch>` environment variable (e.g. `JAVA_HOME_21_X64`).
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v6
|
||||||
|
- uses: actions/setup-java@v5
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '17'
|
||||||
|
- uses: actions/setup-java@v5
|
||||||
|
id: setup-java-21
|
||||||
|
with:
|
||||||
|
distribution: 'temurin'
|
||||||
|
java-version: '21'
|
||||||
|
set-default: false
|
||||||
|
- run: |
|
||||||
|
echo "Default java:"
|
||||||
|
java -version
|
||||||
|
echo "Java 21 home: $JAVA_HOME_21_X64"
|
||||||
|
echo "Java 21 path from output: ${{ steps.setup-java-21.outputs.path }}"
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, `JAVA_HOME` and `java` on `PATH` point to Java 17, while Java 21 is available via `JAVA_HOME_21_X64` or the step output `path`.
|
||||||
|
|
||||||
|
> **Note:** When a single step installs multiple JDKs via a multiline `java-version`, the `set-default` value applies to all of them. With `set-default: false`, none of those JDKs become the default; each remains discoverable through its `JAVA_HOME_<major>_<arch>` variable. Regardless of `set-default`, installed JDKs are still registered in the Maven toolchains file, so they can be selected via Maven toolchains.
|
||||||
|
|
||||||
## Installing Java from local file
|
## Installing Java from local file
|
||||||
If your use-case requires a custom distribution or a version that is not provided by setup-java, you can download it manually and setup-java will take care of the installation and caching on the VM:
|
If your use-case requires a custom distribution or a version that is not provided by setup-java, you can download it manually and setup-java will take care of the installation and caching on the VM:
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ export const INPUT_JAVA_PACKAGE = 'java-package';
|
|||||||
export const INPUT_DISTRIBUTION = 'distribution';
|
export const INPUT_DISTRIBUTION = 'distribution';
|
||||||
export const INPUT_JDK_FILE = 'jdkFile';
|
export const INPUT_JDK_FILE = 'jdkFile';
|
||||||
export const INPUT_CHECK_LATEST = 'check-latest';
|
export const INPUT_CHECK_LATEST = 'check-latest';
|
||||||
|
export const INPUT_SET_DEFAULT = 'set-default';
|
||||||
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';
|
||||||
export const INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
export const INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
|
||||||
export const INPUT_SERVER_ID = 'server-id';
|
export const INPUT_SERVER_ID = 'server-id';
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ export abstract class JavaBase {
|
|||||||
protected packageType: string;
|
protected packageType: string;
|
||||||
protected stable: boolean;
|
protected stable: boolean;
|
||||||
protected checkLatest: boolean;
|
protected checkLatest: boolean;
|
||||||
|
protected setDefault: boolean;
|
||||||
protected verifySignature: boolean;
|
protected verifySignature: boolean;
|
||||||
protected verifySignaturePublicKey: string | undefined;
|
protected verifySignaturePublicKey: string | undefined;
|
||||||
|
|
||||||
@@ -38,6 +39,10 @@ export abstract class JavaBase {
|
|||||||
this.architecture = installerOptions.architecture || os.arch();
|
this.architecture = installerOptions.architecture || os.arch();
|
||||||
this.packageType = installerOptions.packageType;
|
this.packageType = installerOptions.packageType;
|
||||||
this.checkLatest = installerOptions.checkLatest;
|
this.checkLatest = installerOptions.checkLatest;
|
||||||
|
this.setDefault =
|
||||||
|
installerOptions.setDefault !== undefined
|
||||||
|
? installerOptions.setDefault
|
||||||
|
: true;
|
||||||
this.verifySignature = installerOptions.verifySignature ?? false;
|
this.verifySignature = installerOptions.verifySignature ?? false;
|
||||||
this.verifySignaturePublicKey = installerOptions.verifySignaturePublicKey;
|
this.verifySignaturePublicKey = installerOptions.verifySignaturePublicKey;
|
||||||
}
|
}
|
||||||
@@ -179,8 +184,15 @@ export abstract class JavaBase {
|
|||||||
foundJava.path = macOSPostfixPath;
|
foundJava.path = macOSPostfixPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.setDefault) {
|
||||||
core.info(`Setting Java ${foundJava.version} as the default`);
|
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||||
|
} else {
|
||||||
|
core.info(
|
||||||
|
`Installing Java ${foundJava.version} (not setting as default)`
|
||||||
|
);
|
||||||
|
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||||
|
}
|
||||||
|
|
||||||
return foundJava;
|
return foundJava;
|
||||||
}
|
}
|
||||||
@@ -312,9 +324,13 @@ export abstract class JavaBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected setJavaDefault(version: string, toolPath: string) {
|
protected setJavaDefault(version: string, toolPath: string) {
|
||||||
const majorVersion = version.split('.')[0];
|
|
||||||
core.exportVariable('JAVA_HOME', toolPath);
|
core.exportVariable('JAVA_HOME', toolPath);
|
||||||
core.addPath(path.join(toolPath, 'bin'));
|
core.addPath(path.join(toolPath, 'bin'));
|
||||||
|
this.setJavaEnvironment(version, toolPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected setJavaEnvironment(version: string, toolPath: string) {
|
||||||
|
const majorVersion = version.split('.')[0];
|
||||||
core.setOutput('distribution', this.distribution);
|
core.setOutput('distribution', this.distribution);
|
||||||
core.setOutput('path', toolPath);
|
core.setOutput('path', toolPath);
|
||||||
core.setOutput('version', version);
|
core.setOutput('version', version);
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ export interface JavaInstallerOptions {
|
|||||||
architecture: string;
|
architecture: string;
|
||||||
packageType: string;
|
packageType: string;
|
||||||
checkLatest: boolean;
|
checkLatest: boolean;
|
||||||
|
setDefault?: boolean;
|
||||||
verifySignature?: boolean;
|
verifySignature?: boolean;
|
||||||
verifySignaturePublicKey?: string;
|
verifySignaturePublicKey?: string;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -69,9 +69,15 @@ export class LocalDistribution extends JavaBase {
|
|||||||
foundJava.path = macOSPostfixPath;
|
foundJava.path = macOSPostfixPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
core.info(`Setting Java ${foundJava.version} as default`);
|
if (this.setDefault) {
|
||||||
|
core.info(`Setting Java ${foundJava.version} as the default`);
|
||||||
this.setJavaDefault(foundJava.version, foundJava.path);
|
this.setJavaDefault(foundJava.version, foundJava.path);
|
||||||
|
} else {
|
||||||
|
core.info(
|
||||||
|
`Installing Java ${foundJava.version} (not setting as default)`
|
||||||
|
);
|
||||||
|
this.setJavaEnvironment(foundJava.version, foundJava.path);
|
||||||
|
}
|
||||||
return foundJava;
|
return foundJava;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ async function run() {
|
|||||||
constants.INPUT_CACHE_DEPENDENCY_PATH
|
constants.INPUT_CACHE_DEPENDENCY_PATH
|
||||||
);
|
);
|
||||||
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
|
||||||
|
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
|
||||||
const verifySignature = getBooleanInput(
|
const verifySignature = getBooleanInput(
|
||||||
constants.INPUT_VERIFY_SIGNATURE,
|
constants.INPUT_VERIFY_SIGNATURE,
|
||||||
false
|
false
|
||||||
@@ -51,6 +52,7 @@ async function run() {
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
distributionName,
|
distributionName,
|
||||||
@@ -110,6 +112,7 @@ async function installVersion(
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
toolchainIds
|
toolchainIds
|
||||||
@@ -119,6 +122,7 @@ async function installVersion(
|
|||||||
architecture,
|
architecture,
|
||||||
packageType,
|
packageType,
|
||||||
checkLatest,
|
checkLatest,
|
||||||
|
setDefault,
|
||||||
verifySignature,
|
verifySignature,
|
||||||
verifySignaturePublicKey,
|
verifySignaturePublicKey,
|
||||||
version
|
version
|
||||||
@@ -155,6 +159,7 @@ interface installerInputsOptions {
|
|||||||
architecture: string;
|
architecture: string;
|
||||||
packageType: string;
|
packageType: string;
|
||||||
checkLatest: boolean;
|
checkLatest: boolean;
|
||||||
|
setDefault: boolean;
|
||||||
verifySignature: boolean;
|
verifySignature: boolean;
|
||||||
verifySignaturePublicKey: string | undefined;
|
verifySignaturePublicKey: string | undefined;
|
||||||
distributionName: string;
|
distributionName: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user