IntelliJ not remembering Groovy SDK configuration
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.
Please sign in to leave a comment.
See http://stackoverflow.com/a/42518961/104891.
Unfortunately, didn't work.
Delete .idea directory, iml and ipr files, edit build.gradle to include Groovy dependency, reimport the project from build.gradle.
For future readers, this was solved by adding these two lines to my root gradle file.
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
}
}
}
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:
(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.
Here is what worked for me, hopefully it will help someone else:
I completed wiped the ~/.cache/JetBrains directory.
So which dependencies should I add in a Java only project that has Groovy Jenkinsfile?
@Martin Schröder Does this thread answers your question? https://intellij-support.jetbrains.com/hc/en-us/community/posts/115000140204-Setting-up-Groovy-completion-for-Jenkins-Pipelines-consumers