Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Groovy and IntelliJ - getting code compiled

Tags:

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

like image 425
bharal Avatar asked Jun 13 '13 10:06

bharal


People also ask

Is Groovy compiled?

Unlike Java, a Groovy source code file can be executed as an (uncompiled) script, if it contains code outside any class definition, if it is a class with a main method, or if it is a Runnable or GroovyTestCase. A Groovy script is fully parsed, compiled, and generated before executing (similar to Python and Ruby).

How do I add Groovy compiler to IntelliJ?

In the Project tool window, right-click the project and from the context menu, select Add Framework Support. In the dialog that opens, select Groovy and click OK. IntelliJ IDEA adds the Groovy SDK to your project and you can add Groovy classes and Groovy scripts.

Is Groovy compiled to Java?

Groovy scripts can use any Java classes. They can be compiled to Java bytecode (in . class files) that can be invoked from normal Java classes. The Groovy compiler, groovyc, compiles both Groovy scripts and Java source files, however some Java syntax (such as nested classes) is not supported yet.

How do I compile in IntelliJ?

Select a module or a project you want to compile and from the main menu, select Build | Build Project ( Ctrl+F9 ). IntelliJ IDEA displays the compilation results in the Review compilation and build output.


1 Answers

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?

like image 179
bharal Avatar answered Nov 07 '22 22:11

bharal