简体   繁体   中英

Groovy and IntelliJ - getting code compiled

I have IntelliJ 12 and some groovy code (along with a pile of java code) in a project.

In intelliJ, i can see class A's import of some groovy code, and i have also included the library that has that code.

However, while the package itself is in one colour (for the import), the actual class being imported is in red, which implies an issue of some sort. Hovering the mouse over it reveals no issue though.

When i run a "make" or a "rebuild project" is where the problems start - i get

Groovyc: unable to resolve class com.blah.blah.blah.A

How can i resolve this?

Currently, my project setup is like so:

Under "Libraries" in (Project Structure -> Project Settings -> Libraries) I have:

the jar file with all the groovy code the src jar file with all the groovy code

In the "Modules" section i have the - well, i don't know what to call it, the column isn't labelled - the library name from the libraries section associated with the src and class files, and the little "export" button beside it is ticked.

Incidentally, opening the class in intelliJ never shows the source code, which given the source is included struck me as weird.

Is there anything else I should need to do?

I've worked this one out, but if anybody knows why groovy cannot be in the "Resource Patterns" list and wants an upvote, do chime in

Oh, right.

I removed the !?*.groovy entry from the list of, um, entries in the File : Settings -> Compiler -> Resource Patterns thingy.

It doesn't seem to matter if "use external build" is on or off for this, but the !?*.groovy ; entry cannot be there.

I wonder if anybody knows why?

I had the same problem and had to Add Framework Support and add Groovy to the project to get round this problem.

I created the project using gradle.

I just got your question in my Google results as I had a similar issue. My problem was that I was able to get the groovy code in my IntelliJ 12 project to compile ok, but it wasn't getting wired in properly when I tried to run unit tests within the IDE.

After some investigation, I uncovered that groovy and logback libraries were all set up in the project to be available in the runtime stage of the Maven build of the project, but that resulted in them not being available in the test stage. To fix this, I ended up manually updating the groovy-all and the logback libraries scope from runtime to provided under File->Project Structure->Modules->Dependencies . This allowed me to both compile and test within the IDE while including the Groovy modules as well as the Java modules.

Perhaps you had something similar going on in your project?

Six years later, I also just got this question near the top of my search results.

In my project my Unable to load class 'groovy.text.SimpleTemplateEngine' problem was actually due to a codenarc issue. I was able to resolve the issue by adding the following to build.gradle:

// codenarc version issue work-around
configurations.codenarc {
    resolutionStrategy.eachDependency { DependencyResolveDetails d ->
        if (d.requested.group == 'org.codehaus.groovy') {
            d.useVersion '2.4.7'
        }
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM