Intellij IDEA 无法导入 Gradle 项目 - "Could not initialize class javax.crypto.SunJCE_b"

Intellij IDEA can't import Gradle project - "Could not initialize class javax.crypto.SunJCE_b"

我正在做一个 Gradle 项目。当我 gradle run 时,该项目下载依赖项并运行得很好。这是我的 build.gradle 文件:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
    }
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'application'

mainClassName = 'myProject.MyMainClass'

repositories {
    mavenCentral()
}

dependencies {
    // The production code uses the SLF4J logging API at compile time
    compile 'org.slf4j:slf4j-api:1.7.7'
    compile 'org.jsoup:jsoup:1.7.2'

    testCompile "junit:junit:4.11"
}

jar {
    baseName = 'myproject-service'
    version = '0.1.0'
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

现在我想在Intellij IDEA中导入项目。

Import Gradle project >> Use default gradle wrapper (recommended) >> OK

但是,当我点击“确定”时,出现了一个对话:

Could not initialize class javax.crypto.SunJCE_b

查看日志,上面写着

org.gradle.tooling.GradleConnectionException: Could not run build action using Gradle distribution 'https://services.gradle.org/distributions/gradle-2.3-bin.zip'.
...
Caused by: java.lang.NoClassDefFoundError: Could not initialize class javax.crypto.SunJCE_b
    at javax.crypto.KeyGenerator.a(DashoA13*..)
...
2015-03-18 21:31:17,751 [2354198]   WARN - nal.AbstractExternalSystemTask - Could not initialize class javax.crypto.SunJCE_b 
com.intellij.openapi.externalSystem.model.ExternalSystemException: Could not initialize class javax.crypto.SunJCE_b
    at org.jetbrains.plugins.gradle.service.project.AbstractProjectImportErrorHandler.createUserFriendlyError(AbstractProjectImportErrorHandler.java:106)
...

我不知道如何让这个项目工作。 None 我从外部存储库导入的文件在 IDEA 中工作而没有这个(它们都显示为红色)。任何帮助,将不胜感激。我在:

解决方案:

仍然不知道问题出在哪里。我尝试了所有我能在网上找到的建议和我能想到的一切:安装不同版本的 java,安装不同的 IDEA,尝试使用原始密码策略文件,尝试使用无限强度策略文件等等。 None 其中有效。

然而,起作用的是选择 "Use a local gradle distribution",而不是使用默认包装器。我给了它我的 gradle 安装路径 (/usr/local/gradle-2.3),由 运行 which gradle 找到(这将为您提供可执行文件的路径,即 /usr/local/gradle-2 .3/bin/gradle,但我只拿了目录部分)。现在我可以使用 gradle!!

进行构建

我最好的猜测是 gradle 插件安装了一些 gradle 的其他发行版,但我的项目没有正确设置。

我希望这对在 Intellij IDEA 中努力使用 gradle 的其他人有所帮助。