Intellij IDEA can’t import Gradle project – “Could not initialize class javax.crypto.SunJCE_b”

I’m working on a Gradle project. The project downloads dependencies and runs perfectly fine when I do gradle run. Here’s my build.gradle file:

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'
}

Now I want to import the project in Intellij IDEA.

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

However, when I hit OK it comes up with a dialogue saying:

Could not initialize class javax.crypto.SunJCE_b

Looking in the logs, it says

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)
...

I have no idea how to get this project to work. None of my imports from external repositories work inside IDEA without this (they all appear red). Any help would be appreciated. I’m on:

  • Intellij IDEA 13.1.6
  • Java EE 7 (jdk1.7.0_75.jdk)
  • Gradle 2.3
  • Mac OS X

Answer

SOLUTION:

Still have no idea what the issue is. I tried all the suggestions I could find online and everything I could think of: Install a different version of java, install a different IDEA, try using the original cryptography policy files, try using the unlimited strength policy files and more. None of these worked.

What did work, however, was selecting “Use a local gradle distribution”, instead of using the default wrapper. I gave it my gradle install path (/usr/local/gradle-2.3), found by running which gradle (that will give you the path to the executable, namely /usr/local/gradle-2.3/bin/gradle, but I just took the directory part). Now I can build using gradle!!

My best guess is that the gradle plugin installed some other distribution of gradle that wasn’t set up properly for my project.

I hope this is helpful to anyone else struggling with using gradle in Intellij IDEA.

Leave a Reply

Your email address will not be published. Required fields are marked *