How do I suppress JRE deprecation warning

We want to treat warnings as errors to improve code quality, so we’re using the allWarningsAsErrors compiler option in Gradle. We’ve cleaned up our project, but the problem is that we have these two last remaining warnings in dependent library, which we need to suppress:

e: warnings found and -Werror specified
w: /Users/richie/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.2.20/1ba23e74292b5af8980efde762fdd44fb61ddc2/kotlin-stdlib-jre7-1.2.20.jar: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead
w: /Users/richie/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre8/1.2.20/f77d7863695e17041b50ebe5e2f87e5314a2c812/kotlin-stdlib-jre8-1.2.20.jar: kotlin-stdlib-jre8 is deprecated. Please use kotlin-stdlib-jdk8 instead

We cannot use a source code suppression (@Suppress annotation), because these JRE warnings are not associated with a line or file.

So how do we suppress these warnings so that we can treat all “real” warnings as errors.

If I understood the problem correctly, then you have a dependency to kotlin-stdlib-jre7 and kotlin-stdlib-ire8.

Why don’t you replace these dependencies to kotlin-stdlib-jdk7 and kotlin-stdlib-jdk8? That should fix this problem. (You might need to clean the project after this change so that the build works again.)

Kind regards,

Konrad

You can exclude library dependencies like this:

dependencies {
  compile('com.example:library:1.0') {
     exclude group: 'org.jetbrains.kotlin', module : 'kotlin-stdlib-jre7'
     exclude group: 'org.jetbrains.kotlin', module : 'kotlin-stdlib-jre8'
  }
}

then simply add kotlin-stdlib-jdk8 (assuming you do not have it already) and it will pull kotlin-stdlib-jdk7 and kotlin-stdlib. In most cases the library in question should work fine.

1 Like

BOOM! Fixed. Thanks @forinil2 !