Home > Enterprise >  Can not import groovy class in settings.gradle for java project in IDEA
Can not import groovy class in settings.gradle for java project in IDEA

Time:09-11

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.

enter image description here

I excepted to import groovy class in .gradle file successfully.


Here is the gradle-wrapper.properties

point to a valid directory with Gradle binaries

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". point to a directory without Gradle binaries

import is broken

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

  • Related