Compare commits

..

3 Commits

Author SHA1 Message Date
copilot-swe-agent[bot] fa20c15c93 Update generated dist for Maven args log change 2026-06-23 02:46:55 +00:00
Bruno Borges 8e27c114ea Potential fix for pull request finding
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
2026-06-22 22:40:43 -04:00
Bruno Borges cf3151c7a1 feat: suppress Maven transfer progress via MAVEN_ARGS by default
Set MAVEN_ARGS to include -ntp (--no-transfer-progress) so Maven invocations
in the job produce cleaner CI logs without download/transfer progress noise.
Add a new optional 'show-download-progress' input (default false); set it to
true to keep the progress output.

The change preserves any existing MAVEN_ARGS value (the flag is appended,
not overwritten) and is idempotent (it won't add the flag twice if -ntp or
--no-transfer-progress is already present). Applies on all platforms; honored
by Maven 3.9.0+ and the Maven Wrapper, and is a no-op for non-Maven builds.

- action.yml: add show-download-progress input
- src/constants.ts: add input + MAVEN_ARGS constants
- src/maven-args.ts: new configureMavenArgs()
- src/setup-java.ts: invoke configureMavenArgs() during setup
- __tests__/maven-args.test.ts: unit tests
- docs/advanced-usage.md: document the behavior and input
- dist: rebuild bundled action

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-06-22 22:26:13 -04:00
14 changed files with 320 additions and 280 deletions
-74
View File
@@ -545,77 +545,3 @@ jobs:
- name: Verify Java
run: bash __tests__/verify-java.sh "17.0.10" "${{ steps.setup-java.outputs.path }}"
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
-2
View File
@@ -41,8 +41,6 @@ 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.
- `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.
- `cache`: Quick [setup caching](#caching-packages-dependencies) for the dependencies managed through one of the predefined package managers. It can be one of "maven", "gradle" or "sbt".
- `cache-dependency-path`: The path to a dependency file: pom.xml, build.gradle, build.sbt, etc. This option can be used with the `cache` option. If this option is omitted, the action searches for the dependency file in the entire repository. This option supports wildcards and a list of file names for caching multiple dependencies.
@@ -545,110 +545,6 @@ describe('setupJava', () => {
expect(spyCoreExportVariable).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', () => {
+104
View File
@@ -0,0 +1,104 @@
import * as core from '@actions/core';
import {configureMavenArgs} from '../src/maven-args';
import {
INPUT_SHOW_DOWNLOAD_PROGRESS,
MAVEN_ARGS_ENV,
MAVEN_NO_TRANSFER_PROGRESS_FLAG
} from '../src/constants';
describe('configureMavenArgs', () => {
let inputs: Record<string, string>;
let spyGetInput: jest.SpyInstance;
let spyExportVariable: jest.SpyInstance;
let spyInfo: jest.SpyInstance;
let spyDebug: jest.SpyInstance;
const originalMavenArgs = process.env[MAVEN_ARGS_ENV];
beforeEach(() => {
inputs = {};
spyGetInput = jest.spyOn(core, 'getInput');
spyGetInput.mockImplementation((name: string) => inputs[name] ?? '');
spyExportVariable = jest.spyOn(core, 'exportVariable');
spyExportVariable.mockImplementation((name: string, value: string) => {
process.env[name] = value;
});
spyInfo = jest.spyOn(core, 'info');
spyInfo.mockImplementation(() => undefined);
spyDebug = jest.spyOn(core, 'debug');
spyDebug.mockImplementation(() => undefined);
delete process.env[MAVEN_ARGS_ENV];
});
afterEach(() => {
jest.restoreAllMocks();
if (originalMavenArgs === undefined) {
delete process.env[MAVEN_ARGS_ENV];
} else {
process.env[MAVEN_ARGS_ENV] = originalMavenArgs;
}
});
it('sets MAVEN_ARGS with -ntp by default', () => {
configureMavenArgs();
expect(spyExportVariable).toHaveBeenCalledWith(
MAVEN_ARGS_ENV,
MAVEN_NO_TRANSFER_PROGRESS_FLAG
);
expect(process.env[MAVEN_ARGS_ENV]).toBe(MAVEN_NO_TRANSFER_PROGRESS_FLAG);
});
it('does not modify MAVEN_ARGS when show-download-progress is true', () => {
inputs[INPUT_SHOW_DOWNLOAD_PROGRESS] = 'true';
configureMavenArgs();
expect(spyExportVariable).not.toHaveBeenCalled();
expect(process.env[MAVEN_ARGS_ENV]).toBeUndefined();
});
it('preserves an existing MAVEN_ARGS value and appends -ntp', () => {
process.env[MAVEN_ARGS_ENV] = '-B -Dstyle.color=always';
configureMavenArgs();
expect(spyExportVariable).toHaveBeenCalledWith(
MAVEN_ARGS_ENV,
`-B -Dstyle.color=always ${MAVEN_NO_TRANSFER_PROGRESS_FLAG}`
);
});
it('does not duplicate the flag when -ntp is already present', () => {
process.env[MAVEN_ARGS_ENV] = '-B -ntp';
configureMavenArgs();
expect(spyExportVariable).not.toHaveBeenCalled();
expect(process.env[MAVEN_ARGS_ENV]).toBe('-B -ntp');
});
it('does not duplicate the flag when --no-transfer-progress is already present', () => {
process.env[MAVEN_ARGS_ENV] = '--no-transfer-progress -B';
configureMavenArgs();
expect(spyExportVariable).not.toHaveBeenCalled();
expect(process.env[MAVEN_ARGS_ENV]).toBe('--no-transfer-progress -B');
});
it('keeps the existing MAVEN_ARGS when show-download-progress is true', () => {
inputs[INPUT_SHOW_DOWNLOAD_PROGRESS] = 'true';
process.env[MAVEN_ARGS_ENV] = '-B';
configureMavenArgs();
expect(spyExportVariable).not.toHaveBeenCalled();
expect(process.env[MAVEN_ARGS_ENV]).toBe('-B');
});
});
+4 -4
View File
@@ -26,10 +26,6 @@ inputs:
description: 'Set this option if you want the action to check for the latest available version that satisfies the version spec'
required: 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
server-id:
description: 'ID of the distributionManagement repository in the pom.xml
file. Default is `github`'
@@ -79,6 +75,10 @@ inputs:
mvn-toolchain-vendor:
description: 'Name of Maven Toolchain Vendor if the default name of "${distribution}" is not wanted. See examples of supported syntax in Advanced Usage file'
required: false
show-download-progress:
description: 'Whether Maven should print artifact download/transfer progress to the build log. When "false" (default) the action sets "-ntp" (--no-transfer-progress) in MAVEN_ARGS to produce cleaner logs. Set to "true" to keep the progress output. Has no effect on non-Maven builds.'
required: false
default: false
outputs:
distribution:
description: 'Distribution of Java that has been installed'
+5 -2
View File
@@ -52241,7 +52241,7 @@ else {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = 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_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.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_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.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
@@ -52250,7 +52250,6 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_DISTRIBUTION = 'distribution';
exports.INPUT_JDK_FILE = 'jdkFile';
exports.INPUT_CHECK_LATEST = 'check-latest';
exports.INPUT_SET_DEFAULT = 'set-default';
exports.INPUT_SERVER_ID = 'server-id';
exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
@@ -52269,6 +52268,10 @@ exports.MVN_SETTINGS_FILE = 'settings.xml';
exports.MVN_TOOLCHAINS_FILE = 'toolchains.xml';
exports.INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
exports.INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
exports.INPUT_SHOW_DOWNLOAD_PROGRESS = 'show-download-progress';
exports.MAVEN_ARGS_ENV = 'MAVEN_ARGS';
exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = '-ntp';
exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = '--no-transfer-progress';
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
+94 -30
View File
@@ -78000,7 +78000,7 @@ function isProbablyGradleDaemonProblem(packageManager, error) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = 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_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.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_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.INPUT_JAVA_VERSION = 'java-version';
exports.INPUT_JAVA_VERSION_FILE = 'java-version-file';
@@ -78009,7 +78009,6 @@ exports.INPUT_JAVA_PACKAGE = 'java-package';
exports.INPUT_DISTRIBUTION = 'distribution';
exports.INPUT_JDK_FILE = 'jdkFile';
exports.INPUT_CHECK_LATEST = 'check-latest';
exports.INPUT_SET_DEFAULT = 'set-default';
exports.INPUT_SERVER_ID = 'server-id';
exports.INPUT_SERVER_USERNAME = 'server-username';
exports.INPUT_SERVER_PASSWORD = 'server-password';
@@ -78028,6 +78027,10 @@ exports.MVN_SETTINGS_FILE = 'settings.xml';
exports.MVN_TOOLCHAINS_FILE = 'toolchains.xml';
exports.INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
exports.INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
exports.INPUT_SHOW_DOWNLOAD_PROGRESS = 'show-download-progress';
exports.MAVEN_ARGS_ENV = 'MAVEN_ARGS';
exports.MAVEN_NO_TRANSFER_PROGRESS_FLAG = '-ntp';
exports.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = '--no-transfer-progress';
exports.DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
@@ -78318,10 +78321,6 @@ class JavaBase {
this.architecture = installerOptions.architecture || os_1.default.arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.setDefault =
installerOptions.setDefault !== undefined
? installerOptions.setDefault
: true;
}
setupJava() {
var _a, _b;
@@ -78437,14 +78436,8 @@ class JavaBase {
if (process.platform === 'darwin' && fs.existsSync(macOSPostfixPath)) {
foundJava.path = macOSPostfixPath;
}
if (this.setDefault) {
core.info(`Setting Java ${foundJava.version} as the default`);
this.setJavaDefault(foundJava.version, foundJava.path);
}
else {
core.info(`Installing Java ${foundJava.version} (not setting as default)`);
this.setJavaEnvironment(foundJava.version, foundJava.path);
}
core.info(`Setting Java ${foundJava.version} as the default`);
this.setJavaDefault(foundJava.version, foundJava.path);
return foundJava;
});
}
@@ -78542,12 +78535,9 @@ class JavaBase {
return error;
}
setJavaDefault(version, toolPath) {
const majorVersion = version.split('.')[0];
core.exportVariable('JAVA_HOME', toolPath);
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('path', toolPath);
core.setOutput('version', version);
@@ -79744,14 +79734,8 @@ class LocalDistribution extends base_installer_1.JavaBase {
if (process.platform === 'darwin' && fs_1.default.existsSync(macOSPostfixPath)) {
foundJava.path = macOSPostfixPath;
}
if (this.setDefault) {
core.info(`Setting Java ${foundJava.version} as the default`);
this.setJavaDefault(foundJava.version, foundJava.path);
}
else {
core.info(`Installing Java ${foundJava.version} (not setting as default)`);
this.setJavaEnvironment(foundJava.version, foundJava.path);
}
core.info(`Setting Java ${foundJava.version} as default`);
this.setJavaDefault(foundJava.version, foundJava.path);
return foundJava;
});
}
@@ -80909,6 +80893,87 @@ function deleteKey(keyFingerprint) {
exports.deleteKey = deleteKey;
/***/ }),
/***/ 38172:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.configureMavenArgs = void 0;
const core = __importStar(__nccwpck_require__(37484));
const util_1 = __nccwpck_require__(54527);
const constants_1 = __nccwpck_require__(27242);
/**
* Configures the MAVEN_ARGS environment variable so that Maven suppresses
* artifact transfer/download progress output by default, producing cleaner
* CI logs.
*
* Behavior:
* - When `show-download-progress` is `false` (the default), `-ntp`
* (`--no-transfer-progress`) is appended to any existing MAVEN_ARGS value.
* - When `show-download-progress` is `true`, MAVEN_ARGS is left untouched so
* the user's own configuration (and Maven's default progress output) is
* preserved.
*
* The change is idempotent: if MAVEN_ARGS already disables transfer progress
* (via `-ntp` or `--no-transfer-progress`) nothing is added. Any pre-existing
* MAVEN_ARGS value is preserved.
*
* MAVEN_ARGS is honored by Maven 3.9.0+ and the Maven Wrapper; older Maven
* versions ignore it, so this is a no-op there. It has no effect on non-Maven
* builds such as Gradle or sbt.
*/
function configureMavenArgs() {
var _a;
const showDownloadProgress = (0, util_1.getBooleanInput)(constants_1.INPUT_SHOW_DOWNLOAD_PROGRESS, false);
if (showDownloadProgress) {
core.debug(`${constants_1.INPUT_SHOW_DOWNLOAD_PROGRESS} is true; leaving ${constants_1.MAVEN_ARGS_ENV} unchanged`);
return;
}
const existingArgs = ((_a = process.env[constants_1.MAVEN_ARGS_ENV]) !== null && _a !== void 0 ? _a : '').trim();
const alreadyDisabled = existingArgs
.split(/\s+/)
.some(arg => arg === constants_1.MAVEN_NO_TRANSFER_PROGRESS_FLAG ||
arg === constants_1.MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG);
if (alreadyDisabled) {
core.debug(`${constants_1.MAVEN_ARGS_ENV} already disables transfer progress; leaving it unchanged`);
return;
}
const updatedArgs = existingArgs
? `${existingArgs} ${constants_1.MAVEN_NO_TRANSFER_PROGRESS_FLAG}`
: constants_1.MAVEN_NO_TRANSFER_PROGRESS_FLAG;
core.exportVariable(constants_1.MAVEN_ARGS_ENV, updatedArgs);
core.info(`Configured ${constants_1.MAVEN_ARGS_ENV} to include ${constants_1.MAVEN_NO_TRANSFER_PROGRESS_FLAG} to suppress Maven transfer progress logs. ` +
`Set '${constants_1.INPUT_SHOW_DOWNLOAD_PROGRESS}: true' to keep the download progress output.`);
}
exports.configureMavenArgs = configureMavenArgs;
/***/ }),
/***/ 90471:
@@ -80961,6 +81026,7 @@ const constants = __importStar(__nccwpck_require__(27242));
const cache_1 = __nccwpck_require__(97377);
const path = __importStar(__nccwpck_require__(16928));
const distribution_factory_1 = __nccwpck_require__(2970);
const maven_args_1 = __nccwpck_require__(38172);
function run() {
return __awaiter(this, void 0, void 0, function* () {
try {
@@ -80975,7 +81041,6 @@ function run() {
const cache = core.getInput(constants.INPUT_CACHE);
const cacheDependencyPath = core.getInput(constants.INPUT_CACHE_DEPENDENCY_PATH);
const checkLatest = (0, util_1.getBooleanInput)(constants.INPUT_CHECK_LATEST, false);
const setDefault = (0, util_1.getBooleanInput)(constants.INPUT_SET_DEFAULT, true);
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
core.startGroup('Installed distributions');
if (versions.length !== toolchainIds.length) {
@@ -80988,7 +81053,6 @@ function run() {
architecture,
packageType,
checkLatest,
setDefault,
distributionName,
jdkFile,
toolchainIds
@@ -81010,6 +81074,7 @@ function run() {
const matchersPath = path.join(__dirname, '..', '..', '.github');
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
yield auth.configureAuthentication();
(0, maven_args_1.configureMavenArgs)();
if (cache && (0, util_1.isCacheFeatureAvailable)()) {
yield (0, cache_1.restore)(cache, cacheDependencyPath);
}
@@ -81022,12 +81087,11 @@ function run() {
run();
function installVersion(version, options, toolchainId = 0) {
return __awaiter(this, void 0, void 0, function* () {
const { distributionName, jdkFile, architecture, packageType, checkLatest, setDefault, toolchainIds } = options;
const { distributionName, jdkFile, architecture, packageType, checkLatest, toolchainIds } = options;
const installerOptions = {
architecture,
packageType,
checkLatest,
setDefault,
version
};
const distribution = (0, distribution_factory_1.getJavaDistribution)(distributionName, installerOptions, jdkFile);
+31 -29
View File
@@ -14,11 +14,11 @@
- [Installing custom Java package type](#Installing-custom-Java-package-type)
- [JavaFX Maven project](#JavaFX-Maven-project)
- [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)
- [Testing against different Java distributions](#Testing-against-different-Java-distributions)
- [Testing against different platforms](#Testing-against-different-platforms)
- [Publishing using Apache Maven](#Publishing-using-Apache-Maven)
- [Maven transfer progress (download logs)](#Maven-transfer-progress-download-logs)
- [Publishing using Gradle](#Publishing-using-Gradle)
- [Hosted Tool Cache](#Hosted-Tool-Cache)
- [Modifying Maven Toolchains](#Modifying-Maven-Toolchains)
@@ -268,34 +268,6 @@ steps:
- 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
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:
@@ -519,6 +491,36 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}
```
## Maven transfer progress (download logs)
By default, Maven prints a line for every artifact it downloads, which can add hundreds of noisy lines to CI logs. To keep logs clean, `setup-java` sets the [`MAVEN_ARGS`](https://maven.apache.org/configure.html#maven_args-environment-variable) environment variable to include `-ntp` (`--no-transfer-progress`) so that subsequent Maven invocations in the job suppress this transfer progress output.
This is enabled by default. Any existing `MAVEN_ARGS` value is preserved (the flag is appended, not overwritten), and the flag is not added twice if you already set it yourself.
If you want to keep the download/transfer progress in your logs, set `show-download-progress: true`:
```yaml
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: '<distribution>'
java-version: '21'
show-download-progress: true # keep Maven download/transfer progress in the logs
- name: Build with Maven
run: mvn -B package --file pom.xml
```
***NOTES***:
- `MAVEN_ARGS` is honored by Maven 3.9.0+ and the Maven Wrapper (`mvnw`). Older Maven versions ignore it, so on those you can pass `--no-transfer-progress` on the command line instead.
- This setting only affects Maven. It has no effect on Gradle, sbt, or other build tools.
- `-ntp` only controls transfer/progress output; it does not change whether Maven runs in batch mode. Use `-B`/`--batch-mode` (or `<interactiveMode>false</interactiveMode>` in `settings.xml`) if you also want non-interactive runs.
## Publishing using Gradle
```yaml
jobs:
+5 -1
View File
@@ -6,7 +6,6 @@ export const INPUT_JAVA_PACKAGE = 'java-package';
export const INPUT_DISTRIBUTION = 'distribution';
export const INPUT_JDK_FILE = 'jdkFile';
export const INPUT_CHECK_LATEST = 'check-latest';
export const INPUT_SET_DEFAULT = 'set-default';
export const INPUT_SERVER_ID = 'server-id';
export const INPUT_SERVER_USERNAME = 'server-username';
export const INPUT_SERVER_PASSWORD = 'server-password';
@@ -29,5 +28,10 @@ export const MVN_SETTINGS_FILE = 'settings.xml';
export const MVN_TOOLCHAINS_FILE = 'toolchains.xml';
export const INPUT_MVN_TOOLCHAIN_ID = 'mvn-toolchain-id';
export const INPUT_MVN_TOOLCHAIN_VENDOR = 'mvn-toolchain-vendor';
export const INPUT_SHOW_DOWNLOAD_PROGRESS = 'show-download-progress';
export const MAVEN_ARGS_ENV = 'MAVEN_ARGS';
export const MAVEN_NO_TRANSFER_PROGRESS_FLAG = '-ntp';
export const MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG = '--no-transfer-progress';
export const DISTRIBUTIONS_ONLY_MAJOR_VERSION = ['corretto'];
+3 -19
View File
@@ -20,7 +20,6 @@ export abstract class JavaBase {
protected packageType: string;
protected stable: boolean;
protected checkLatest: boolean;
protected setDefault: boolean;
constructor(
protected distribution: string,
@@ -37,10 +36,6 @@ export abstract class JavaBase {
this.architecture = installerOptions.architecture || os.arch();
this.packageType = installerOptions.packageType;
this.checkLatest = installerOptions.checkLatest;
this.setDefault =
installerOptions.setDefault !== undefined
? installerOptions.setDefault
: true;
}
protected abstract downloadTool(
@@ -174,15 +169,8 @@ export abstract class JavaBase {
foundJava.path = macOSPostfixPath;
}
if (this.setDefault) {
core.info(`Setting Java ${foundJava.version} as the default`);
this.setJavaDefault(foundJava.version, foundJava.path);
} else {
core.info(
`Installing Java ${foundJava.version} (not setting as default)`
);
this.setJavaEnvironment(foundJava.version, foundJava.path);
}
core.info(`Setting Java ${foundJava.version} as the default`);
this.setJavaDefault(foundJava.version, foundJava.path);
return foundJava;
}
@@ -310,13 +298,9 @@ export abstract class JavaBase {
}
protected setJavaDefault(version: string, toolPath: string) {
const majorVersion = version.split('.')[0];
core.exportVariable('JAVA_HOME', toolPath);
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('path', toolPath);
core.setOutput('version', version);
-1
View File
@@ -3,7 +3,6 @@ export interface JavaInstallerOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
setDefault?: boolean;
}
export interface JavaInstallerResults {
+3 -9
View File
@@ -69,15 +69,9 @@ export class LocalDistribution extends JavaBase {
foundJava.path = macOSPostfixPath;
}
if (this.setDefault) {
core.info(`Setting Java ${foundJava.version} as the default`);
this.setJavaDefault(foundJava.version, foundJava.path);
} else {
core.info(
`Installing Java ${foundJava.version} (not setting as default)`
);
this.setJavaEnvironment(foundJava.version, foundJava.path);
}
core.info(`Setting Java ${foundJava.version} as default`);
this.setJavaDefault(foundJava.version, foundJava.path);
return foundJava;
}
+69
View File
@@ -0,0 +1,69 @@
import * as core from '@actions/core';
import {getBooleanInput} from './util';
import {
INPUT_SHOW_DOWNLOAD_PROGRESS,
MAVEN_ARGS_ENV,
MAVEN_NO_TRANSFER_PROGRESS_FLAG,
MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG
} from './constants';
/**
* Configures the MAVEN_ARGS environment variable so that Maven suppresses
* artifact transfer/download progress output by default, producing cleaner
* CI logs.
*
* Behavior:
* - When `show-download-progress` is `false` (the default), `-ntp`
* (`--no-transfer-progress`) is appended to any existing MAVEN_ARGS value.
* - When `show-download-progress` is `true`, MAVEN_ARGS is left untouched so
* the user's own configuration (and Maven's default progress output) is
* preserved.
*
* The change is idempotent: if MAVEN_ARGS already disables transfer progress
* (via `-ntp` or `--no-transfer-progress`) nothing is added. Any pre-existing
* MAVEN_ARGS value is preserved.
*
* MAVEN_ARGS is honored by Maven 3.9.0+ and the Maven Wrapper; older Maven
* versions ignore it, so this is a no-op there. It has no effect on non-Maven
* builds such as Gradle or sbt.
*/
export function configureMavenArgs(): void {
const showDownloadProgress = getBooleanInput(
INPUT_SHOW_DOWNLOAD_PROGRESS,
false
);
if (showDownloadProgress) {
core.debug(
`${INPUT_SHOW_DOWNLOAD_PROGRESS} is true; leaving ${MAVEN_ARGS_ENV} unchanged`
);
return;
}
const existingArgs = (process.env[MAVEN_ARGS_ENV] ?? '').trim();
const alreadyDisabled = existingArgs
.split(/\s+/)
.some(
arg =>
arg === MAVEN_NO_TRANSFER_PROGRESS_FLAG ||
arg === MAVEN_NO_TRANSFER_PROGRESS_LONG_FLAG
);
if (alreadyDisabled) {
core.debug(
`${MAVEN_ARGS_ENV} already disables transfer progress; leaving it unchanged`
);
return;
}
const updatedArgs = existingArgs
? `${existingArgs} ${MAVEN_NO_TRANSFER_PROGRESS_FLAG}`
: MAVEN_NO_TRANSFER_PROGRESS_FLAG;
core.exportVariable(MAVEN_ARGS_ENV, updatedArgs);
core.info(
`Configured ${MAVEN_ARGS_ENV} to include ${MAVEN_NO_TRANSFER_PROGRESS_FLAG} to suppress Maven transfer progress logs. ` +
`Set '${INPUT_SHOW_DOWNLOAD_PROGRESS}: true' to keep the download progress output.`
);
}
+2 -5
View File
@@ -12,6 +12,7 @@ import {restore} from './cache';
import * as path from 'path';
import {getJavaDistribution} from './distributions/distribution-factory';
import {JavaInstallerOptions} from './distributions/base-models';
import {configureMavenArgs} from './maven-args';
async function run() {
try {
@@ -28,7 +29,6 @@ async function run() {
constants.INPUT_CACHE_DEPENDENCY_PATH
);
const checkLatest = getBooleanInput(constants.INPUT_CHECK_LATEST, false);
const setDefault = getBooleanInput(constants.INPUT_SET_DEFAULT, true);
let toolchainIds = core.getMultilineInput(constants.INPUT_MVN_TOOLCHAIN_ID);
core.startGroup('Installed distributions');
@@ -45,7 +45,6 @@ async function run() {
architecture,
packageType,
checkLatest,
setDefault,
distributionName,
jdkFile,
toolchainIds
@@ -81,6 +80,7 @@ async function run() {
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
await auth.configureAuthentication();
configureMavenArgs();
if (cache && isCacheFeatureAvailable()) {
await restore(cache, cacheDependencyPath);
}
@@ -102,7 +102,6 @@ async function installVersion(
architecture,
packageType,
checkLatest,
setDefault,
toolchainIds
} = options;
@@ -110,7 +109,6 @@ async function installVersion(
architecture,
packageType,
checkLatest,
setDefault,
version
};
@@ -145,7 +143,6 @@ interface installerInputsOptions {
architecture: string;
packageType: string;
checkLatest: boolean;
setDefault: boolean;
distributionName: string;
jdkFile: string;
toolchainIds: Array<string>;