Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 21 suppress compiler "preview feature" warnings - how?

Tags:

java

How do I silence the Java 21 compiler from nagging about me using preview features? Here is what I have tried so far, UNSUCCESSFULLY:

  • In my Gradle build file, I added -Xlint:all:
tasks
        .withType(JavaCompile)
        .configureEach {
            java {
                sourceCompatibility = javaVersion
                targetCompatibility = javaVersion
                options.incremental = true
                options.encoding = 'UTF-8'
                options.compilerArgs += [
                        "--enable-preview",
                        "-Xlint:all",
                        "-Xlint:-preview"
                    ]
            }

        }
  • Add @SuppressWarnings("preview") to all module-info.java definitions.

Sampling of compiler warnings (files truncated with ... for brevity):

.../DataLoader.java:373: warning: [preview] string templates are a preview feature and may be removed in a future release.
                            logger.log(SEVERE, STR."Error after \{sheet}/\{rowCounter[0]}, \{t}");
                                                   ^
.../DataLoader.java:373: warning: [preview] string templates are a preview feature and may be removed in a future release.
                            logger.log(SEVERE, STR."Error after \{sheet}/\{rowCounter[0]}, \{t}");

warning: [preview] class file .../Named.class) uses preview features of Java SE 21.
warning: [preview] class file for .../ExcelWorkbook$ExcelSheet.class uses preview features of Java SE 21.
warning: [preview] class file for ../Store.class) uses preview features of Java SE 21.
warning: [preview] class file for .../ExcelWorkbook$Field.class uses preview features of Java SE 21.
like image 910
Hristo Stoyanov Avatar asked Dec 23 '25 02:12

Hristo Stoyanov


1 Answers

@andrewJames pointed to the solution in the comments:

options.compilerArgs += [
 "--enable-preview",
 "-Xlint:-preview"
]
like image 67
Hristo Stoyanov Avatar answered Dec 24 '25 17:12

Hristo Stoyanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!