Migrate to Java 11 with gradle; UnsupportedOperationException

Viktor V. picture Viktor V. · Oct 8, 2018 · Viewed 14.8k times · Source

Trying to switch from jdk 10 to 11 and cannot figure out what library invoke this exception:

Caused by: org.gradle.api.GradleException: failed to read class file ../../SomeTestFile.class
...
...
Caused by: java.lang.UnsupportedOperationException
        at org.objectweb.asm.ClassVisitor.visitNestMemberExperimental(ClassVisitor.java:248)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:651)
        at org.objectweb.asm.ClassReader.accept(ClassReader.java:391)
        at org.gradle.api.internal.tasks.testing.detection.AbstractTestFrameworkDetector.classVisitor(AbstractTestFrameworkDetector.java:124)

I'm using gradle wrapper(v4.10.2) with the following build.gradle:

buildscript {
    ext {
        springBootVersion = '2.0.5.RELEASE'
        schemaDownloadVersion = '1.6'
        generateAvroVersion = '0.14.2'
    }
    repositories {
        mavenCentral()
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "http://packages.confluent.io/maven/" }
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
        classpath("gradle.plugin.com.amit.plugin.download-registry:registry-schema-download-plugin:${schemaDownloadVersion}")
        classpath("com.commercehub.gradle.plugin:gradle-avro-plugin:${generateAvroVersion}")
    }
}

apply plugin: 'java'
apply plugin: 'jacoco'
apply plugin: 'org.springframework.boot'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.amit.plugin.download-registry'
apply plugin: 'com.commercehub.gradle.plugin.avro'

group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = 11

repositories {
    mavenCentral()
}

ext {
    springCloudVersion = 'Finchley.RELEASE'
    jaxbVersion = '2.3.0'
    activationVersion = '1.1.1'
    jmockitVersion = '1.43'
    lombokVersion = '1.18.2'
}

jacoco {
    toolVersion = '0.8.2'
}

dependencies {
    compile('org.springframework.cloud:spring-cloud-starter-oauth2')
    compile("javax.xml.bind:jaxb-api:${jaxbVersion}")
    compile("com.sun.xml.bind:jaxb-core:${jaxbVersion}")
    compile("com.sun.xml.bind:jaxb-impl:${jaxbVersion}")
    compile("javax.activation:activation:${activationVersion}")
    compileOnly("org.projectlombok:lombok:${lombokVersion}")
    testCompile("org.jmockit:jmockit:${jmockitVersion}")
    testCompile('org.springframework.boot:spring-boot-starter-test') {
        exclude(group: 'org.mockito')
    }
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

...

Investigating this problem I have figure out only that gradle itself, lombok and jmockit uses asm library which probably can cause this exception. Could someone answer me what library invoke this exception?

UPDATE

I have found that article about the same problem: https://matsumana.info/blog/2018/09/25/gradle-with-jdk11/ which point to the gradle issue here https://github.com/gradle/gradle/issues/5120 So it means gradle still not support Java 11 yet?

Answer

Jorn Vernee picture Jorn Vernee · Oct 8, 2018

Java 11 added nest based access, so any byte code writing APIs like ASM had to be updated to support the class-file changes.

Looking at the source code for that method in the 6.2.1 version of ASM (which is the one that gradle seems to be using):

  @Deprecated
  public void visitNestMemberExperimental(final String nestMember) {
    if (api < Opcodes.ASM7_EXPERIMENTAL) {
      throw new UnsupportedOperationException();
    }
    if (cv != null) {
      cv.visitNestMemberExperimental(nestMember);
    }
  }

The API level required is 7 which is currently in beta. I guess they are waiting for a release version of ASM 7 before updating the dependency.