Issue
I created a spring boot project which uses gradle. The project has a settings.gradle file, and i used groovy class in this file but can not be imported. The code is used to include sub modules.
import groovy.io.FileType // can not be imported
import java.nio.file.Paths
rootProject.name = 'godlenfire'
String rootPath = rootProject.projectDir.path
['app'].forEach {
File dir = Paths.get(rootPath, it).toFile()
dir.traverse([maxDepth: 3, nameFilter: 'build.gradle', type: FileType.FILES]) {
def module = relativePath(it.parent).replace File.separator, Project.PATH_SEPARATOR
include module
logger.lifecycle("include ${module}")
}
}
Thanks.
I excepted to import groovy class in .gradle file successfully.
Here is the gradle-wrapper.properties
Solution
I was able to reproduce your issue by playing with Preferences | Build, Execution, Deployment | Build Tools | Gradle | Use Gradle from
option in IntelliJ. The idea is that this value should point to the valid Gradle binaries.
In my example below I'm using Gradle wrapper which means that Gradle will always be downloaded if it's missing.
However, when I reproduce the issue I'm just using the "Specified location" option that points to a random directory without Gradle binaries which causes my IntelliJ to "break".
So, make sure that option is configured properly in your IntelliJ. You can also make sure that you are able to run gradle
commands within the terminal as I mentioned in my comment to the question (if you are using Gradle wrapper you should likely run ./gradlew
commands).
Answered By - Dmitry Khamitov
Answer Checked By - Terry (JavaFixing Volunteer)