java - 无法找到方法 sun.misc.Unsafe.defineClass

标签 java spring-boot gradle

我正在使用 jdk-10.0.2gradle 4.7,在构建我的项目时出现此错误。

    Unable to find method 'sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;'.

Possible causes for this unexpected error include:
Gradle's dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
Re-download dependencies and sync project (requires network)

The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
Stop Gradle build processes (requires restart)

Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.

In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

最佳答案

我有同样的问题(但使用 JDK 11):

Unable to find method 'sun.misc.Unsafe.defineClass(Ljava/lang/String;[BIILjava/lang/ClassLoader;Ljava/security/ProtectionDomain;)Ljava/lang/Class;'.

与你一样使用 gradle 4.7 版本。

我的 gradle-wrapper.properties 文件是:

    distributionBase=GRADLE_USER_HOME
    distributionPath=wrapper/dists
    zipStoreBase=GRADLE_USER_HOME
    zipStorePath=wrapper/dists
    distributionUrl=https\://services.gradle.org/distributions/gradle-4.7-all.zip

为了解决这个问题,我使用参数 distributionUrl 更改为 4.9 版本的包装器:

 distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip

并在没有任何错误的情况下重建项目。

关于java - 无法找到方法 sun.misc.Unsafe.defineClass,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55918972/

相关文章:

java - 为什么 Eclipse 会编译它,而 javac 不会?

java - 如何使主键以特定字母开头?

java - 可以将整数值分配给 char 但不能将整数变量分配给 char

java - 使用 JDBC 驱动程序在 Android 应用程序和 Oracle DB 之间建立连接

java - Spring Boot @PreDestroy 注释不起作用

java - 多对多的 JPA Criteria API 规范

java - Rabbitmq 消费者

java - Libgdx gradle 项目编译失败

c++ - 添加原生静态依赖

java - JBoss Gradle