0

I'm using grails 3.3.0 with rest api and gson views. I have the following setup...

Domain Class

package foo

@Resource(uri="/api/bars", readOnly = false, formats = ['json', 'xml'])
class Bar{
    String firstName
    String lastName
}

Controller:

package foo

class BarController extends RestfulController<Building>{

    def show(){
        respond Bar.get(params.id)
    }
}

_bar.gson:

import foo.Bar;

model {
    Bar bar
}

json {
    name bar.firstName
}

_show.gson:

import foo.Bar;

model {
    Bar bar
}

json g.render(template:"bar", model:[bar:bar])

directory layout:

/grails-app/views/
-----------------bar/
--------------------_bar.gson
--------------------_show.gson

This fails during build, test, compile and war with the following error:

Execution failed for task ':compileGsonViews'.
foo_bar_show_gson: 3: unable to resolve class foo.Bar

I followed the documentation but I cannot get around this. Please help!

Michael J. Lee
  • 12,278
  • 3
  • 23
  • 39

2 Answers2

5

I have the same issue, my problem got solved when I change the views-gradle version to the 1.2.7

classpath "org.grails.plugins:views-gradle:1.2.7"
0

After looking through github issues this seems to be caused by the rest profile and running on a Windows machine. If I start a new project using the web profile everything works fine.

Michael J. Lee
  • 12,278
  • 3
  • 23
  • 39
  • I was facing the same issue. I tried to run application using gradle build and build fialed at gsonViewCompile. I ran it with grails run-app and it ran without any error. So this points to a fact that it is an issue with gradle version because compilation failes with gradle clean build but works fine with ./gradlew clean build (a gradle wrapper supplied along with project) – Priyank Thakkar Oct 15 '17 at 09:43