Unverified Commit d1374f8a authored by Bruno Borges's avatar Bruno Borges Committed by GitHub
Browse files

Make Java problem matcher opt-in (#1326)

Default the problem-matcher input to false so setup-java no longer
registers Java compiler and uncaught-exception annotations unless
explicitly enabled with problem-matcher: true.

Fixes #1322

Co-authored-by: default avatarCopilot App <[email protected]>
parent 5fb63c9b
Loading
Loading
Loading
Loading
+2 −2
Changes for README.md: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -59,7 +59,7 @@ steps:
- Warm JDK-cached jobs can reuse cached release metadata, avoiding vendor API calls while retaining a stale-metadata fallback for vendor outages and rate limits.
- Maven configuration now supports multiple server credentials and custom dependency-resolution repositories.
- Maven signing keys are imported into an isolated temporary GPG home instead of the runner's default keyring.
- Set `problem-matcher: false` to disable Java compiler and uncaught-exception annotations.
- Java compiler and uncaught-exception annotations are now disabled by default. Set `problem-matcher: true` to enable them.
- GraalVM distributions now set `GRAALVM_HOME` in addition to `JAVA_HOME`.
- Invalid boolean values, unsupported distribution/package/platform combinations, and mismatched Maven toolchain ID counts now fail with targeted errors.
- Renamed environment-variable-name inputs so they are not mistaken for secret values:
@@ -155,7 +155,7 @@ steps:
| `check-latest` | Check remote metadata for the latest version satisfying the version spec before using the runner tool cache. | `false` |
| `force-download` | Always download Java and replace any matching version in the tool cache. | `false` |
| `set-default` | Add Java to `PATH` and set `JAVA_HOME`. When `false`, only version-specific `JAVA_HOME_<major>_<arch>` variables are set. | `true` |
| `problem-matcher` | Register Java compiler and uncaught exception problem matchers. | `true` |
| `problem-matcher` | Register Java compiler and uncaught exception problem matchers. | `false` |
| `verify-signature` | Verify downloaded Java package signatures when supported. Explicitly setting this to `true` makes verification failures fatal. | Distribution-dependent; see [Download integrity and signatures](#download-integrity-and-signatures) |
| `verify-signature-public-key` | One or more ASCII-armored GPG public keys used for signature verification. Concatenate multiple armored key blocks. Custom keys replace the bundled distribution keys. | |
| `token` | Token for fetching GitHub.com-hosted version manifests, useful on GitHub Enterprise Server when unauthenticated requests are rate-limited. | `${{ github.token }}` on GitHub.com; empty string on GHES |
+10 −1
Changes for __tests__/problem-matcher.test.ts: 10 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -27,7 +27,16 @@ describe('configureProblemMatcher', () => {
    jest.resetAllMocks();
  });

  it('registers the Java problem matcher by default', () => {
  it('does not register the Java problem matcher by default', () => {
    configureProblemMatcher('/matchers/java.json');

    expect(mockInfo).not.toHaveBeenCalled();
    expect(mockDebug).toHaveBeenCalledWith('Java problem matcher is disabled');
  });

  it('registers the Java problem matcher when explicitly enabled', () => {
    inputs[INPUT_PROBLEM_MATCHER] = 'true';

    configureProblemMatcher('/matchers/java.json');

    expect(mockInfo).toHaveBeenCalledWith('##[add-matcher]/matchers/java.json');
+2 −2
Changes for action.yml: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -138,9 +138,9 @@ inputs:
    required: false
    default: false
  problem-matcher:
    description: 'Whether to register the Java problem matcher (compiler errors/warnings and uncaught exceptions). Set to "false" to disable annotations.'
    description: 'Whether to register the Java problem matcher (compiler errors/warnings and uncaught exceptions). Disabled by default; set to "true" to enable annotations.'
    required: false
    default: true
    default: false
outputs:
  distribution:
    description: 'Distribution of Java that has been installed'
+1 −1
Changes for dist/setup/index.js: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -36747,7 +36747,7 @@ async function getJavaDistribution(distributionName, installerOptions, jdkFile)
function configureProblemMatcher(matcherPath) {
    const problemMatcherEnabled = (0,util/* getBooleanInput */.Vt)(constants/* INPUT_PROBLEM_MATCHER */.Wt, true);
    const problemMatcherEnabled = (0,util/* getBooleanInput */.Vt)(constants/* INPUT_PROBLEM_MATCHER */.Wt, false);
    if (!problemMatcherEnabled) {
        setup_java_core/* debug */.Yz('Java problem matcher is disabled');
        return;
+5 −5
Changes for docs/advanced-usage.md: 5 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -1310,7 +1310,7 @@ jobs:

## Java problem matcher (compiler annotations)

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:
Java [problem matcher](https://github.com/actions/toolkit/blob/main/docs/problem-matchers.md) registration is disabled by default. Set `problem-matcher: true` to have `setup-java` register the matcher after installing the JDK. When enabled, 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:

- Compiler errors and warnings, e.g. `App.java:12: error: cannot find symbol` (owner `javac`).
- Maven compiler errors and warnings, e.g. `[ERROR] /path/App.java:[12,5] cannot find symbol` (owner `maven-javac`).
@@ -1318,9 +1318,9 @@ By default, `setup-java` registers a [problem matcher](https://github.com/action

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.

### Disabling the problem matcher
### Enabling the problem matcher

Set `problem-matcher` to `false` to prevent the matcher from being registered:
Set `problem-matcher` to `true` to enable annotations, including in workflows that previously relied on default registration:

```yaml
jobs:
@@ -1333,13 +1333,13 @@ jobs:
        with:
          distribution: '<distribution>'
          java-version: '21'
          problem-matcher: false
          problem-matcher: true

      - name: Build with Maven
        run: mvn package --file pom.xml
```

Disabling the matcher only stops annotations from being created. Compiler output remains in the log, and compilation errors still fail the build step.
Omit `problem-matcher` or set it to `false` to prevent this action invocation from registering the matcher. Compiler output remains in the log, and compilation errors still fail the build step. This does not unregister matchers already registered by other steps or earlier action invocations.

## Publishing using Gradle
```yaml
Loading