gradle / kotlin-dsl-samples

Samples builds using the Gradle Kotlin DSL
https://gradle.org/kotlin/
Other
3.71k stars 434 forks source link

compileJava and javaDoc tasks spamming with warnings: class file for kotlin.DeprecationLevel not found #1301

Closed dkorobtsov closed 5 years ago

dkorobtsov commented 5 years ago

Expected Behavior

compileJava and javaDoc tasks should show deprecation warnings (if any is found)

Current Behavior

compileJava and javaDoc tasks show following warnings instead: warning: unknown enum constant DeprecationLevel.WARNING reason: class file for kotlin.DeprecationLevel not found warning: unknown enum constant DeprecationLevel.ERROR warning: unknown enum constant DeprecationLevel.ERROR warning: unknown enum constant DeprecationLevel.WARNING warning: unknown enum constant DeprecationLevel.ERROR warning: unknown enum constant DeprecationLevel.ERROR 6 warnings

Context

No functional impact, just annoying - build log is red.

Steps to Reproduce (for bugs)

Compiling only java sources. Gradle build configured in Kotlin DSL. Tasks configuration:

   tasks.withType(JavaCompile::class) {
        options.encoding = StandardCharsets.UTF_8.displayName()
        options.isDebug = false
        options.isDeprecation = false
    }

    tasks.withType(Javadoc::class) {
        isFailOnError = true
        options.outputLevel = JavadocOutputLevel.QUIET
        (options as StandardJavadocDocletOptions)
                .addStringOption("Xdoclint:none", "-nodeprecated")
    }

    val sourceSets = project.the<SourceSetContainer>()

    val sourceJar by tasks.creating(Jar::class) {
        from(sourceSets.getByName("main").allJava)
        this.archiveClassifier.set("sources")
    }

    val javadocJar by tasks.creating(Jar::class) {
        from(tasks.getByName("javadoc"))
        this.archiveClassifier.set("javadoc")
    }

    artifacts.add("archives", sourceJar)
    artifacts.add("archives", javadocJar)

Btw, adding following compiler args suppresses warnings for CompileJava task:

        options.compilerArgs.add("-nowarn")
        options.compilerArgs.add("-Xlint:none")

But nothing helps with Javadoc.

Your Environment


Gradle 5.1-rc-1

Build time: 2018-12-13 06:00:04 UTC Revision: 0937d57caa43dabc31d331dea6c9c0cf72de8607

Kotlin DSL: 1.1.0 Kotlin: 1.3.11 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_172 (Oracle Corporation 25.172-b11) OS: Mac OS X 10.14.2 x86_64

IntelliJ IDEA 2018.3.1 (Ultimate Edition) Build #IU-183.4588.61, built on December 4, 2018

Kotlin plugin: v1.3.11-release-IJ2018.3-1

scumbkt19 commented 5 years ago

I'm seeing this same issue on upgrade from Gradle 4.10 to Gradle 5.2.1, we're not using the kotlin DSL at all, and because we're running with -Werror this is breaking now.


Gradle 5.2.1

Build time: 2019-02-08 19:00:10 UTC Revision: f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL: 1.1.3 Kotlin: 1.3.20 Groovy: 2.5.4 Ant: Apache Ant(TM) version 1.9.13 compiled on July 10 2018 JVM: 1.8.0_144 (Oracle Corporation 25.144-b01) OS: Mac OS X 10.13.6 x86_64

eskatos commented 5 years ago

It's a bit hard to get why kotlin.DeprecationLevel would be searched for. Could you please provide a complete reproducer?

dkorobtsov commented 5 years ago

@eskatos btw, figured out the root cause. Issue reproduces when in Java project dependencies contain some library written in Kotlin that has @Deprecated annotations. In my particular case root cause was recent okio update - when biggest part of okio library was switched to Kotlin (including deprecations):

Check this class for example: https://github.com/square/okio/blob/2b65a6cb391ebc93c324d5d3a4d6cdc056bf47e7/okio/jvm/src/main/java/okio/ByteString.kt

So, steps to reproduce are pretty simple:

  1. Create Java project
  2. Add some Kotlin lib with @Deprecated annotations as a dependency
  3. Build the project (Log will be crowded with errors)

Workaround: adding kotlin std-lib to classpath solves the issue. Still - adding it if Kotlin is not used in particular project at all only to suppress exception feels like overkill.

All in all, issue is not related to Kotlin DSL. Any ideas where this ticket should go instead?

eskatos commented 5 years ago

The okio artifact doesn't expose its dependency on kotlin-stdlib but it apparently leaks some kotlin-stdlib types like kotlin.Deprecated, hence the class file for kotlin.DeprecationLevel not found messages from javac and javadoc. @dkorobtsov, please report against okio.

@scumbkt19, could you please confirm that what you are experiencing has a similar cause?

scumbkt19 commented 5 years ago

ooo, that makes a lot of sense, mine is coming from okhttp, which probably traces back to that same lib.

Created https://github.com/square/okio/issues/562, sounds like closing this ticket is appropriate

eskatos commented 5 years ago

Thank you for confirming.