IntelliJ not remembering Groovy SDK configuration

Answered

Whenever I do a ./gradlew idea, IntelliJ gives me this message ("Groovy SDK is not configured for module") on all my Groovy files in this project:

Clicking "Configure Groovy SDK" brings up this:

This fixes the problem - but only until I do another ./gradlew idea, at which point it forgets the Groovy SDK all over again.  This is extremely annoying.

 

Here are the global libraries for my project.  As you can see, Groovy is there.

What's the deal?  I have worked on many other projects at work that use Groovy, and have never had this problem before.  Going to any other project is completely fine - I can ./gradlew idea all day long and it persists my Groovy SDK. 

I am on MacOS, and using IntelliJ Ultimate Build #IU-181.5281.24, version 2018.1.5.

2
8 comments
Avatar
Permanently deleted user

Unfortunately, didn't work. 

  1. Deleted the project and imported the root build.gradle
  2. Got the "Groovy SDK is not configured" message. 
  3. Configured the SDK
  4. Clicked the "Refresh Gradle project" to do what ./gradlew idea used to do.
  5. "Groovy SDK not configured" message is back.
0

Delete .idea directory, iml and ipr files, edit build.gradle to include Groovy dependency, reimport the project from build.gradle.

0
Avatar
Permanently deleted user

For future readers, this was solved by adding these two lines to my root gradle file.

testCompile group: 'org.codehaus.groovy', name: 'groovy', version: '2.5.0'
testCompile group: 'org.codehaus.groovy', name: 'groovy-test', version: '2.5.0'

My full file:

plugins {
id 'company-name.plugin-plugin' version '1.0.0-rc.132'
}

dependencies {
resolutionRules group:'company-name', name: 'gradle-resolution-rules', version: '12.0.0'
}

group = 'company-name'
version = '1.0.0-SNAPSHOT'

subprojects {

apply plugin: 'idea'
apply plugin: 'maven-publish'
apply plugin: 'findbugs'
apply plugin: 'checkstyle'

version = parent.version
group = parent.group

sourceCompatibility = 1.8
targetCompatibility = 1.8

configurations {
checkstyleConfig
}

task extractCheckstyle(type: Copy) {
dependsOn configurations.checkstyleConfig
ext.checkstyleDir = "${buildDir}/checkstyle"

from {
configurations.checkstyleConfig.collect { zipTree(it) }
}
into checkstyleDir
}

checkstyleMain.dependsOn extractCheckstyle
checkstyleTest.dependsOn extractCheckstyle

checkstyle {
toolVersion ="7.6.1"
sourceSets = [sourceSets.main, sourceSets.test]
config = resources.text.fromFile(extractCheckstyle.checkstyleDir + "/config/checkstyle.xml")
configProperties.samedir = extractCheckstyle.checkstyleDir + "/config/"
}

findbugs {
toolVersion = "3.0.1"
sourceSets = [sourceSets.main] //don't run against tests
ignoreFailures = true //checkFindbugsReport task will handle the failure
excludeFilterConfig = resources.text.fromString("<FindBugsFilter><Match><Bug category=\"EXPERIMENTAL\" /></Match></FindBugsFilter>")
}

ext.versions = [
logback: '1.2.2',
slf4j: '1.7.25',
logstash: '4.9',
awssdk: '1.11.86',
lambdacore: '1.2.0',
icon: '1.1.0'
]

dependencies {
checkstyleConfig group: 'company-name', name: 'checkstyle-config', version: '0.9.7'

compileOnly group: 'org.projectlombok', name: 'lombok', version: '1.16.16'

compile group: 'ch.qos.logback', name: 'logback-classic', version: versions.logback
compile group: 'org.slf4j', name: 'jcl-over-slf4j', version: versions.slf4j
compile group: 'org.slf4j', name: 'jul-to-slf4j', version: versions.slf4j
compile group: 'org.slf4j', name: 'log4j-over-slf4j', version: versions.slf4j

testCompile group: 'org.codehaus.groovy', name: 'groovy', version: '2.5.0'
testCompile group: 'org.codehaus.groovy', name: 'groovy-test', version: '2.5.0'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.hamcrest', name: 'java-hamcrest', version: '2.0.0.0'
testCompile group: 'org.spockframework', name: 'spock-core', version: '1.0-groovy-2.4'
testCompile group: 'org.objenesis', name: 'objenesis', version: '1.2'
testCompile group: 'cglib', name: 'cglib-nodep', version: '2.2'
}

tasks.idea {
dependsOn = [ cleanIdeaModule, extractCheckstyle, ideaModule ]
}

idea.module.iml {
beforeMerged { module ->
module.dependencies.clear()
}
}

task checkFindBugsReport {
doLast {
def xmlReport = findbugsMain.reports.xml
if (xmlReport.destination.exists()) {
def slurped = new XmlSlurper().parse(xmlReport.destination)
def bugsFound = slurped.BugInstance.size()

slurped.BugInstance.each {
System.err <<
"Findbugs violation ${it.@category} : ${it.@type} in ${it.SourceLine.@classname}: ${it.SourceLine.@start}\n"
}

if (bugsFound > 0) {
throw new GradleException(
"$bugsFound FindBugs rule violations were found. See the report at: $xmlReport.destination")
}
}
}
}

findbugsMain.finalizedBy checkFindBugsReport

task analyze {
dependsOn = [findbugsMain, checkstyleMain, checkstyleTest]
}

task lambdaZip(type: Zip) {
from compileJava
from compileGroovy
from processResources
into('lib') {
from configurations.runtime
}
}
}
0
Avatar
Permanently deleted user

Hi there,
I had a similar issue but with simple java project. Thanks to Twilcock's answer I figured out how to fix this issue. Just modify build.gradle like next:


sourceSets {
    groovyUtils
}

dependencies {
    groovyUtilsCompile 'org.codehaus.groovy:groovy-all:2.5.1'
    groovyUtilsCompile 'org.apache.ivy:ivy:2.4.0'
}

(I added 'org.apache.ivy:ivy:2.4.0' dependency as well in order to use @Grab annotations).

Refresh gradle project and then in your Run/Debug Groovy configuration select Module = <projectName>_groovyUtils.

0
Avatar
Permanently deleted user

Here is what worked for me, hopefully it will help someone else:

 

I completed wiped the     ~/.cache/JetBrains directory. 

0
Avatar
Permanently deleted user

So which dependencies should I add in a Java only project that has Groovy Jenkinsfile?

0

Please sign in to leave a comment.