Skip to content

Commit e40a8e0

Browse files
brunoborgesCopilot
andauthored
Add an option to disable Java problem matchers (actions#1133)
* Add problem matcher opt-out Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 38eb7886-7ea3-4e4d-8d5f-e3f975135053 * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 6e2e32e commit e40a8e0

9 files changed

Lines changed: 101 additions & 25 deletions

File tree

‎README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ For more details, see the full release notes on the [releases page](https://git
5353

5454
- `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.
5555

56+
- `problem-matcher`: Set to `false` to disable Java problem matcher annotations (compiler diagnostics and uncaught exceptions). Default value: `true`. See [Java problem matcher](docs/advanced-usage.md#java-problem-matcher-compiler-annotations) for details and annotation limits.
57+
5658
- `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.
5759

5860
- `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.
@@ -208,7 +210,7 @@ steps:
208210
cache: 'maven'
209211
cache-dependency-path: 'sub-project/pom.xml' # optional
210212
- name: Build with Maven
211-
run: mvn -B package --file pom.xml
213+
run: mvn package --file pom.xml
212214
```
213215

214216
> [!NOTE]

‎__tests__/problem-matcher.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {afterEach, beforeEach, describe, expect, it, jest} from '@jest/globals';
2+
3+
const mockGetInput = jest.fn<(...args: any[]) => any>();
4+
const mockInfo = jest.fn<(...args: any[]) => any>();
5+
const mockDebug = jest.fn<(...args: any[]) => any>();
6+
7+
jest.unstable_mockModule('@actions/core', () => ({
8+
getInput: mockGetInput,
9+
info: mockInfo,
10+
debug: mockDebug,
11+
warning: jest.fn(),
12+
setSecret: jest.fn()
13+
}));
14+
15+
const {configureProblemMatcher} = await import('../src/problem-matcher.js');
16+
const {INPUT_PROBLEM_MATCHER} = await import('../src/constants.js');
17+
18+
describe('configureProblemMatcher', () => {
19+
let inputs: Record<string, string>;
20+
21+
beforeEach(() => {
22+
inputs = {};
23+
mockGetInput.mockImplementation((name: string) => inputs[name] ?? '');
24+
});
25+
26+
afterEach(() => {
27+
jest.resetAllMocks();
28+
});
29+
30+
it('registers the Java problem matcher by default', () => {
31+
configureProblemMatcher('/matchers/java.json');
32+
33+
expect(mockInfo).toHaveBeenCalledWith('##[add-matcher]/matchers/java.json');
34+
});
35+
36+
it('does not register the Java problem matcher when disabled', () => {
37+
inputs[INPUT_PROBLEM_MATCHER] = 'false';
38+
39+
configureProblemMatcher('/matchers/java.json');
40+
41+
expect(mockInfo).not.toHaveBeenCalled();
42+
expect(mockDebug).toHaveBeenCalledWith('Java problem matcher is disabled');
43+
});
44+
});

‎action.yml‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ inputs:
9494
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.'
9595
required: false
9696
default: false
97+
problem-matcher:
98+
description: 'Whether to register the Java problem matcher (compiler errors/warnings and uncaught exceptions). Set to "false" to disable annotations.'
99+
required: false
100+
default: true
97101
outputs:
98102
distribution:
99103
description: 'Distribution of Java that has been installed'

‎dist/cleanup/index.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95924,6 +95924,7 @@ const INPUT_JDK_FILE = 'jdk-file';
9592495924
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
9592595925
const INPUT_CHECK_LATEST = 'check-latest';
9592695926
const INPUT_SET_DEFAULT = 'set-default';
95927+
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
9592795928
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
9592895929
const INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
9592995930
const INPUT_SERVER_ID = 'server-id';

‎dist/setup/index.js‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73283,6 +73283,7 @@ const INPUT_JDK_FILE = 'jdk-file';
7328373283
const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
7328473284
const INPUT_CHECK_LATEST = 'check-latest';
7328573285
const INPUT_SET_DEFAULT = 'set-default';
73286+
const INPUT_PROBLEM_MATCHER = 'problem-matcher';
7328673287
const INPUT_VERIFY_SIGNATURE = 'verify-signature';
7328773288
const INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
7328873289
const INPUT_SERVER_ID = 'server-id';
@@ -133988,6 +133989,19 @@ function configureMavenArgs() {
133988133989
`Set '${INPUT_SHOW_DOWNLOAD_PROGRESS}: true' to keep the download progress output.`);
133989133990
}
133990133991

133992+
;// CONCATENATED MODULE: ./src/problem-matcher.ts
133993+
133994+
133995+
133996+
function configureProblemMatcher(matcherPath) {
133997+
const problemMatcherEnabled = util_getBooleanInput(INPUT_PROBLEM_MATCHER, true);
133998+
if (!problemMatcherEnabled) {
133999+
core_debug('Java problem matcher is disabled');
134000+
return;
134001+
}
134002+
info(`##[add-matcher]${matcherPath}`);
134003+
}
134004+
133991134005
;// CONCATENATED MODULE: ./src/setup-java.ts
133992134006

133993134007

@@ -134000,6 +134014,7 @@ function configureMavenArgs() {
134000134014

134001134015

134002134016

134017+
134003134018
async function run() {
134004134019
try {
134005134020
const versions = getMultilineInput(INPUT_JAVA_VERSION);
@@ -134073,7 +134088,7 @@ async function run() {
134073134088
}
134074134089
endGroup();
134075134090
const matchersPath = external_path_.join(external_path_.dirname((0,external_url_.fileURLToPath)(import.meta.url)), '..', '..', '.github');
134076-
info(`##[add-matcher]${external_path_.join(matchersPath, 'java.json')}`);
134091+
configureProblemMatcher(external_path_.join(matchersPath, 'java.json'));
134077134092
await configureAuthentication();
134078134093
configureMavenArgs();
134079134094
if (cache && isCacheFeatureAvailable()) {

‎docs/advanced-usage.md‎

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,9 @@ steps:
355355
java-version: '25'
356356
cache: 'maven'
357357
- name: Seed the Maven cache
358-
run: mvn -B dependency:go-offline dependency:resolve-plugins
358+
run: mvn dependency:go-offline dependency:resolve-plugins
359359
- name: Build with Maven
360-
run: mvn -B verify --file pom.xml
360+
run: mvn verify --file pom.xml
361361
```
362362

363363
Separate seed job — useful for a matrix where different legs run different goals
@@ -378,7 +378,7 @@ jobs:
378378
java-version: '25'
379379
cache: 'maven'
380380
- name: Seed the Maven cache
381-
run: mvn -B dependency:go-offline dependency:resolve-plugins
381+
run: mvn dependency:go-offline dependency:resolve-plugins
382382
383383
build:
384384
needs: seed-cache
@@ -394,7 +394,7 @@ jobs:
394394
java-version: '25'
395395
cache: 'maven'
396396
- name: Build
397-
run: mvn -B ${{ matrix.goal }} --file pom.xml
397+
run: mvn ${{ matrix.goal }} --file pom.xml
398398
```
399399

400400
### Caveats
@@ -410,7 +410,7 @@ jobs:
410410
Profile-gated plugins, conditionally-active modules, and artifacts a plugin
411411
fetches at execution time may still be missed. For the most complete cache,
412412
seed with the fullest goal set your CI actually uses (for example
413-
`mvn -B verify` with every profile enabled).
413+
`mvn verify` with every profile enabled).
414414
- **Multi-module projects:** run the seed at the reactor root so every module's
415415
plugins are resolved.
416416

@@ -585,7 +585,7 @@ jobs:
585585
java-version: '11'
586586

587587
- name: Build with Maven
588-
run: mvn -B package --file pom.xml
588+
run: mvn package --file pom.xml
589589

590590
- name: Publish to GitHub Packages Apache Maven
591591
run: mvn deploy
@@ -743,7 +743,7 @@ jobs:
743743
settings-path: ${{ github.workspace }} # location for the settings.xml file
744744
745745
- name: Build with Maven
746-
run: mvn -B package --file pom.xml
746+
run: mvn package --file pom.xml
747747
748748
- name: Publish to GitHub Packages Apache Maven
749749
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
@@ -773,26 +773,27 @@ jobs:
773773
show-download-progress: true # keep Maven download/transfer progress in the logs
774774
775775
- name: Build with Maven
776-
run: mvn -B package --file pom.xml
776+
run: mvn package --file pom.xml
777777
```
778778

779779
***NOTES***:
780780
- `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.
781781
- This setting only affects Maven. It has no effect on Gradle, sbt, or other build tools.
782-
- `-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.
782+
- `-ntp` only controls transfer/progress output. The `settings.xml` generated by `setup-java` separately sets `<interactiveMode>false</interactiveMode>`. If you use `overwrite-settings: false`, ensure your existing settings disable interactive mode or pass `-B`/`--batch-mode`.
783783

784784
## Java problem matcher (compiler annotations)
785785

786-
`setup-java` registers a [problem matcher](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md) for Java after installing the JDK. It scans the log output of subsequent steps and turns `javac` diagnostics into GitHub [annotations](https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message) that appear in the run summary and inline on the affected files. It matches two kinds of lines:
786+
By default, `setup-java` registers a [problem matcher](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md) for Java after installing the JDK. It scans the log output of subsequent steps and turns Java diagnostics into GitHub [annotations](https://docs.github.com/actions/using-workflows/workflow-commands-for-github-actions#setting-a-warning-message) that appear in the run summary and inline on the affected files. It matches three kinds of lines:
787787

788788
- Compiler errors and warnings, e.g. `App.java:12: error: cannot find symbol` (owner `javac`).
789+
- Maven compiler errors and warnings, e.g. `[ERROR] /path/App.java:[12,5] cannot find symbol` (owner `maven-javac`).
789790
- Uncaught-exception header lines, e.g. `Exception in thread "main" ...`; because these lines have no file or line captures, they appear as log/run-level annotations rather than inline file annotations (owner `java`).
790791

791-
This is enabled by default and requires no configuration.
792+
GitHub Actions limits problem matcher annotations to 10 of each severity per step and 50 annotations per job. Additional diagnostics remain available in the build log. Log grouping does not change these limits because every matched diagnostic still counts as an annotation.
792793

793794
### Disabling the problem matcher
794795

795-
There is no action input to turn the matcher off, but you can disable it for the rest of the job with the built-in [`remove-matcher`](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md#remove-a-problem-matcher) workflow command. Pass the matcher **owner** (not a file name); the Java matcher defines two owners, `javac` and `java`, so remove both to fully suppress it:
796+
Set `problem-matcher` to `false` to prevent the matcher from being registered:
796797

797798
```yaml
798799
jobs:
@@ -805,19 +806,13 @@ jobs:
805806
with:
806807
distribution: '<distribution>'
807808
java-version: '21'
808-
809-
- name: Disable the Java problem matcher
810-
run: |
811-
echo "::remove-matcher owner=javac::"
812-
echo "::remove-matcher owner=java::"
809+
problem-matcher: false
813810
814811
- name: Build with Maven
815-
run: mvn -B package --file pom.xml
812+
run: mvn package --file pom.xml
816813
```
817814

818-
***NOTES***:
819-
- `remove-matcher` only stops annotations from being created; the underlying compiler output is unchanged, so a failing `javac`/build still fails the step.
820-
- The command is scoped to the job, so add the step right after `setup-java` (and before your build) in every job where you want the matcher disabled.
815+
Disabling the matcher only stops annotations from being created. Compiler output remains in the log, and compilation errors still fail the build step.
821816

822817
## Publishing using Gradle
823818
```yaml
@@ -1131,4 +1126,3 @@ Notes and caveats:
11311126
- Prefer giving the certificate a stable, descriptive `-alias` so re-runs are idempotent (re-importing the same alias will fail; add `keytool -delete -alias internal-ca ...` first if you re-run within a long-lived runner).
11321127

11331128
This documents the post-install workflow; there is no dedicated action input for supplying a custom `cacerts` file.
1134-

‎src/constants.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ export const INPUT_JDK_FILE = 'jdk-file';
88
export const INPUT_JDK_FILE_DEPRECATED = 'jdkFile';
99
export const INPUT_CHECK_LATEST = 'check-latest';
1010
export const INPUT_SET_DEFAULT = 'set-default';
11+
export const INPUT_PROBLEM_MATCHER = 'problem-matcher';
1112
export const INPUT_VERIFY_SIGNATURE = 'verify-signature';
1213
export const INPUT_VERIFY_SIGNATURE_PUBLIC_KEY = 'verify-signature-public-key';
1314
export const INPUT_SERVER_ID = 'server-id';

‎src/problem-matcher.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as core from '@actions/core';
2+
import {INPUT_PROBLEM_MATCHER} from './constants.js';
3+
import {getBooleanInput} from './util.js';
4+
5+
export function configureProblemMatcher(matcherPath: string): void {
6+
const problemMatcherEnabled = getBooleanInput(INPUT_PROBLEM_MATCHER, true);
7+
8+
if (!problemMatcherEnabled) {
9+
core.debug('Java problem matcher is disabled');
10+
return;
11+
}
12+
13+
core.info(`##[add-matcher]${matcherPath}`);
14+
}

‎src/setup-java.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {fileURLToPath} from 'url';
1414
import {getJavaDistribution} from './distributions/distribution-factory.js';
1515
import {JavaInstallerOptions} from './distributions/base-models.js';
1616
import {configureMavenArgs} from './maven-args.js';
17+
import {configureProblemMatcher} from './problem-matcher.js';
1718

1819
async function run() {
1920
try {
@@ -120,7 +121,7 @@ async function run() {
120121
'..',
121122
'.github'
122123
);
123-
core.info(`##[add-matcher]${path.join(matchersPath, 'java.json')}`);
124+
configureProblemMatcher(path.join(matchersPath, 'java.json'));
124125

125126
await auth.configureAuthentication();
126127
configureMavenArgs();

0 commit comments

Comments
 (0)