gradleintellij-ideajvm-argumentserrorprone

Set -Xmaxerros and -Xmaxwarns in Gradle to display all ErrorProne messages


I have created a script that runs ./gradlew build -x and then counts all occurences of error: [SomeError] and warning: [SomeWarning] from the output.

#!/bin/bash

# Run './gradlew build -x test' and capture the output
build_output=$(./gradlew build -x test 2>&1)

# Extract error URLs from the build output and count their occurrences
error_urls=$(echo "$build_output" | grep -o -P '(error|warning):\s*\[([^]]+)\]' | sort | uniq -c)

# Create a mapping file with error URLs and occurrence counts
echo "$error_urls" | while read -r count url; do
    printf "| %-50s | %-5s |\n" "$url" "$count" >> error_mapping.txt
done

I'm getting this output for ./gradlew build -x:

Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
100 errors
100 warnings
only showing the first 100 errors, of 262 total; use -Xmaxerrs if you would like to see more
only showing the first 100 warnings, of 227 total; use -Xmaxwarns if you would like to see more

I want to display all messages to have a total of 489 entries in my map.

This is my config in build.gradle.kts:

import net.ltgt.gradle.errorprone.errorprone

plugins {
  id("net.ltgt.errorprone") version "3.1.0" apply false
}


subprojects {
  plugins.withType<JavaPlugin> {
    apply(plugin = "net.ltgt.errorprone")
    dependencies {     
      add("errorprone", "com.google.errorprone:error_prone_core:2.16")

    }
    tasks.withType<JavaCompile>().configureEach {
      options.errorprone {
        disableWarningsInGeneratedCode.set(true)
      }
    }
  }
}

I tried multiple things:

What else can I do?


Solution

  • On the right track

    Update to the following:

    subprojects {
        plugins.withType<JavaPlugin> {
            apply(plugin = "net.ltgt.errorprone")
            dependencies {
                add("errorprone", "com.google.errorprone:error_prone_core:2.16")
            }
            tasks.withType<JavaCompile>().configureEach {
                options.errorprone {
                    disableWarningsInGeneratedCode.set(true)
                    compilerArgs.addAll(listOf("-Xmaxerrs", "1000", "-Xmaxwarns", "1000"))
                }
            }
        }
    }
    

    N.B.
    The Java compiler (javac) does have default limits for the maximum number of errors / warnings displayed. The default limits are set to prevent an overwhelming output in the case of large number of errors / warnings.

    Default and maximum values for -Xmaxerrs and -Xmaxwarns may vary depending on the variant/version of the JDK. Common default value is 100 for both errors and warnings, but best to check official documentation.

    In your case, the exception message "only showing the first 100 errors, of 262 total; use -Xmaxerrs if you would like to see more" it indicated that the Java compiler had reached the default limit of 100 errors and suggesting the use of the -Xmaxerrs option to increase the limit if you want to see more. Duplicated for the warnings.

    Also a side note, the value can be set to "0", which will disable the limit and setting it to infinity, but this is discouraged.