mirror of
https://github.com/actions/setup-java.git
synced 2026-06-23 16:20:28 +03:00
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>
This commit is contained in:
@@ -28,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'];
|
||||
|
||||
@@ -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(
|
||||
`Set ${MAVEN_ARGS_ENV} to '${updatedArgs}' to suppress Maven transfer progress logs. ` +
|
||||
`Set 'show-download-progress: true' to keep the download progress output.`
|
||||
);
|
||||
}
|
||||
@@ -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 {
|
||||
@@ -79,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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user