Viriato
Viriato

Reputation: 3011

Cannot add Groovy code to an existing Maven Java project "def cannot be resolved to a type"

This might be something very simple but I cannot seem to get it right. I have a Spring MVC 3.0 application and I would like to use some groovy code.

Problem

When I add Groovy code (Groovy Classes) and I start defining my variables the IDE (SpringSource Tool Suite in my case) tells me "def cannot be resolved to a type"

What I have done

  1. Created a source folder named src/main/groovy
  2. Created a .groovy Class added a method with def msg = 'Hello'
  3. Added Groovy libraries to Classpath
  4. Did a Project/Clean through the IDE
  5. The IDE (STS) still tells me "def cannot be resolved to a type"

If I create a simple Groovy Project I can interchange groovy/java with no problem but now that I am adding Groovy to something that I already had it does not seem to be picking up that I am trying to do groovy in those groovy files. I have Groovy on the classpath, Groovy nature and everything. Not sure what else to do so that STS stops flagging my groovy code as errors.

Thanks.

Upvotes: 3

Views: 3585

Answers (2)

Chris Willmore
Chris Willmore

Reputation: 133

  1. Ensure you have Groovy installed (yum, aptitude, etc).
  2. Right click your project.
  3. Select "Groovy" -> "Add Groovy libraries to classpath" The project should automatically rebuild and the problem is resolved.

Upvotes: 1

tolitius
tolitius

Reputation: 22509

You have to install a Groovy Eclipse plugin.

Open you Dashboard, click on "Extensions" tab (of the Dashboard), check the "Groovy Eclipse" option:

enter image description here

and click install.

Once it is installed, it'll ask you to restart Spring Tool Suite => do it.

Then right click on your project => "Configure" => "Convert to Groovy Project"

Upvotes: 4

Related Questions