Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrate to Java 11 with gradle; UnsupportedOperationException

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?

like image 999
Viktor M. Avatar asked Oct 08 '18 11:10

Viktor M.


People also ask

Is Gradle compatible with Java 11?

The minimum version of Gradle that supports Java 11 is 5.0 . You would need to upgrade to version 7.0 or above for Android.

How do I change Java version to Gradle project?

Set the JDK version Open your project in Android Studio and select File > Settings... > Build, Execution, Deployment > Build Tools > Gradle (Android Studio > Preferences... > Build, Execution, Deployment > Build Tools > Gradle on a Mac). Under Gradle JDK, choose the Embedded JDK option. Click OK.

What version of Java does Gradle use?

Compiling and testing Java 6/7 Gradle can only run on Java version 8 or higher. Gradle still supports compiling, testing, generating Javadoc and executing applications for Java 6 and Java 7. Java 5 and below are not supported.


2 Answers

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.

like image 130
Jorn Vernee Avatar answered Sep 27 '22 20:09

Jorn Vernee


ASM v7 has been released.

Gradle issue has been closed and fix is available at Gradle 5.0 RC1 or later.

Binaries should be soon available for download.

like image 27
Mikhail Kholodkov Avatar answered Sep 27 '22 20:09

Mikhail Kholodkov