Gradle groovy build-logic can't use any import statements

已回答

Hello, I am working on reworking a large buildscript. Trying to migrate it to build-logic so it can be reused between projects.
It functions fine at the gradle level, the build works. But in IntelliJ I can't import any classes, it results in "Cannot resolve symbol"
Is there any way to fix this? We have multiple on our project some of which (Me) uses Eclipse so I'd rather not switch to kotlin as that is not supported in any IDE besides IntelliJ. 

It works if I put it in the app\build.gradle, but not in build-logic\convention\src\main\groovy\test.convention.gradle

Any help would be greatly appreciated, been bashing my head against gradle all week.

Upload id: 2026_08_23_23eEd3pbqbSDWnz73LSGEW (files: idea64_CUxLr5cDdq.png, gradle-build-logic-groovy.zip)

 

0

LexManos This is a known limitation, tracked as IDEA-260351. A *.gradle precompiled script plugin is resolved against the build script classpath, not against the compile classpath of the module that holds it. Your convention module declares commons-lang3 and the gradleutils plugin marker, so both classes are on that module's compile classpath, and the editor does not see that classpath. The import goes red, getByType falls back to Object, and every property access after that degrades. Gradle compiles the same file correctly, which matches what you see.

Please vote and watch it for updates: Watching YouTrack issues.

There is no IDE-side setting that fixes it, but moving the logic out of the script does. Write the convention as a Groovy class that implements Plugin<Project> under build-logic/convention/src/main/groovy, then register that class in a gradlePlugin { plugins { ... } } block instead of relying on the *.gradle file name. A .groovy file is an ordinary module source, so the editor resolves it against the module's own dependencies.

 One build-logic/convention module, both variants importing the same two classes, one of them from the module's own source root: the *.gradle script reports Cannot resolve symbol as an error on both import lines, and the Plugin<Project> class reports nothing. Gradle configures and runs both.

It stays in Groovy, so it doesn’t push your Eclipse users to the Kotlin DSL, and the result is a plain plugin jar. I ran it on a minimal project rather than on yours.

0

请先登录再写评论。