Grails with Vaadin 8 - 'Failed to load the widgetset" - grails

I am a newbie in the areas in Grails and Vaadin 8, and I’m having a bit of trouble trying to add widgets to my Vaadin/Grails application.
To begin, I created a grails/Vaadin app using the me.przepiora.vaadin-grails:web-vaadin8:0.3 profile. I edited the build.gradel file, as advised and
ran the command ”gradle wrapper --gradle-version 4.0” (again, as advised by the profile setup).
Here is my build.gradle after applying the edit:
apply plugin:"com.devsoap.plugin.vaadin"
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://dl.bintray.com/macprzepiora/gradle-plugins/" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.devsoap.plugin:gradle-vaadin-plugin:1.2.0.beta1-macprzepiora2"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.8"
}
}
version "0.1"
group "foobar"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "com.vaadin:vaadin-spring-boot-starter:2.+"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.5.Final"
compile "org.grails.plugins:gsp"
console "org.grails:grails-console"
profile "me.przepiora.vaadin-grails:web-vaadin8:0.3"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.8"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails:grails-web-testing-support"
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
plugins {
id 'com.devsoap.plugin.vaadin' version '1.3.1'
}
assets {
minifyJs = true
minifyCss = true
}
The resulting grails/Vaadin app worked fine, displaying a button which , when pressed, displayed an error message.
I then tried to enhance the app slightly, by replacing the button with a Vaadin Tree, backup by a TreeData instance.
Unfortunately, when I did this, I got the error message:
“Widgetset 'com.vaadin.DefaultWidgetSet' does not contain implementation for com.vaadin.ui.Tree Check its component connector's #Connect mapping, widgetsets GWT module description file and re-compile your widgetset. In case you have downloaded a vaadin add-on package, you might want to refer to add-on instructions.”
After a google search I found something that appeared to be related at:
How do I fix 'com.vaadin.DefaultWidgetSet' does not contain implementation for com.vaadin.addon.charts.Chart
Based on this, I added the line #Widgetset("AppWidgetset") to my GrailsUI class (the only class in my project that inherits from com.vaadin.ui.UI).
After doing this, I get a new runtime error:
“Failed to load the widgetset: ./VAADIN/widgetsets/AppWidgetset/AppWidgetset.nocache.js?1525623851485”
I feel so frustrated - it feels like i’m really close to a working application, if only I knew the magi incantation :-(

Related

Grails 3 upgrade - unable to resolve class grails.plugin.rendering.pdf.PdfRenderingService

I inherited a multi-module grails application based on Grails 2.5.4.
I installed groovy 3.0.4 and grails 3.3.11, and I completed the grails upgrade tasks base on the tutorial provided on the official website (https://docs.grails.org/3.0.x/guide/upgrading.html).
I'm dealing with tons of code adaptation but I'm bumping on a particular issue as I try to build the project, I'm facing the following issue:
C:\repo\upgraded-app\myapp-web\grails-app\services\bitt\PdfRenderingService.groovy: 9: unable to resolve class grails.plugin.rendering.pdf.PdfRenderingService
# line 9, column 1.
#Transactional
^
The code involved is the following:
import com.lowagie.text.pdf.BaseFont
import grails.transaction.Transactional
import grails.util.Environment
import org.w3c.dom.Document
import org.xhtmlrenderer.pdf.ITextRenderer
#Transactional
class PdfRenderingService extends grails.plugin.rendering.pdf.PdfRenderingService {
...
and my build.gradle file is the following:
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
}
}
version "0.1"
group "bitt.web"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
compile project(':../bitt-core')
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.16.Final"
compile "org.grails.plugins:gsp"
compile 'org.grails.plugins:spring-security-core:3.2.3'
compile 'org.grails.plugins:spring-security-acl:3.2.1'
compile 'org.grails.plugins:grails-markdown:3.0.0'
compile 'org.grails.plugins:rendering:2.0.3'
compile 'org.grails.plugins:excel-export:2.1'
compile 'org.grails.plugins:grails-cookie:2.0.3'
compile 'org.grails.plugins:spring-security-ui:3.0.2'
compile 'org.grails.plugins:http-builder-helper:1.1.0'
compile 'org.grails.plugins:audit-logging:3.0.6'
console "org.grails:grails-console"
profile "org.grails.profiles:web"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.postgresql:postgresql:9.4-1203-jdbc42"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.15.1"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-web-testing-support"
testCompile "org.grails.plugins:geb:1.1.2"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:2.47.1"
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
tasks.withType(Test) {
systemProperty "geb.env", System.getProperty('geb.env')
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}
assets {
minifyJs = true
minifyCss = true
includes = ["fonts/*"]
}
The code above mentioned is working fine in Grails 2... but now provokes a compilation error with Grails 3 ... any idea why ?
Thanks.
Upgrading between major Grails versions is not that easy, as Gradle config has big differences.
I suggest you use Grails Starter to get a sample app, unpack the build.gradle, gradle.properties from there, and merge your old config (mostly dependencies) into it.
Configuration has also changed from .groovy files to .yml, consider migrating them as well.

*unable to resolve class" issue when upgrading from grails 2.5.4 to grails 3.3.11

I inherited a multi-module grails application based on Grails 2.5.4.
It's working nice and well, but I need to upgrade to 3.x.
I installed groovy 3.0.4 and grails 3.3.11, and I completed the grails upgrade tasks base on the tutorial provided on the official website (https://docs.grails.org/3.0.x/guide/upgrading.html).
As I try to build the project, I'm facing multiple *unable to resolve class" issues related to bases classes such as:
Starting a Gradle Daemon (subsequent builds will be faster)
:compileAstJava NO-SOURCE
:compileAstGroovy NO-SOURCE
:processAstResources NO-SOURCE
:astClasses UP-TO-DATE
:compileJava NO-SOURCE
:configScript
:compileGroovy
startup failed:
C:\repo\upgraded-app\myapp-core\grails-app\domain\bittt\holders\Exclusion.groovy: 5: unable to resolve class org.grails.databinding.BindingFormat
# line 5, column 1.
import org.grails.databinding.BindingFormat
^
C:\repo\upgraded-app\myapp-core\grails-app\domain\bittt\migration\CustomsLgcy.groovy: 5: unable to resolve class org.postgresql.core.Query
# line 5, column 1.
import org.postgresql.core.Query
^
C:\repo\upgraded-app\myapp-core\grails-app\services\bittt\ExclusionService.groovy: 13: unable to resolve class org.grails.web.servlet.mvc.GrailsParameterMap
# line 13, column 1.
import org.grails.web.servlet.mvc.GrailsParameterMap
^
C:\repo\upgraded-app\myapp-core\grails-app\services\bittt\NotificationService.groovy: 12: unable to resolve class org.grails.commons.GrailsApplication
# line 12, column 1.
import org.grails.commons.GrailsApplication
^
...
My myapp.core build.gradle file contains the following:
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.15.1"
}
}
version "0.1"
group "myapp.core"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-plugin"
apply plugin:"org.grails.grails-plugin-publish"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.16.Final"
compile "org.grails.plugins:gsp"
compile 'org.grails.plugins:spring-security-core:3.2.3'
compile 'org.grails.plugins:spring-security-acl:3.2.1'
compile "org.grails.plugins:phonenumbers:0.10"
console "org.grails:grails-console"
profile "org.grails.profiles:web-plugin"
provided "org.grails:grails-plugin-services"
provided "org.grails:grails-plugin-domain-class"
runtime "org.glassfish.web:el-impl:2.1.2-b03"
runtime "com.h2database:h2"
runtime "org.apache.tomcat:tomcat-jdbc"
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.15.1"
testCompile "org.grails:grails-gorm-testing-support"
testCompile "org.grails.plugins:geb"
testCompile "org.grails:grails-web-testing-support"
testCompile "org.grails.plugins:geb:1.1.2"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
testRuntime "org.seleniumhq.selenium:selenium-chrome-driver:2.47.1"
}
bootRun {
jvmArgs('-Dspring.output.ansi.enabled=always')
addResources = true
String springProfilesActive = 'spring.profiles.active'
systemProperty springProfilesActive, System.getProperty(springProfilesActive)
}
tasks.withType(Test) {
systemProperty "geb.env", System.getProperty('geb.env')
systemProperty "geb.build.reportsDir", reporting.file("geb/integrationTest")
systemProperty "webdriver.chrome.driver", System.getProperty('webdriver.chrome.driver')
systemProperty "webdriver.gecko.driver", System.getProperty('webdriver.gecko.driver')
}
assets {
minifyJs = true
minifyCss = true
}
I don't really understand why I'm getting those errors as the relevant dependencies seem to be in place... anything I'm missing here ?
Thanks :)
C:\repo\upgraded-app\myapp-core\grails-app\domain\bittt\holders\Exclusion.groovy:
5: unable to resolve class org.grails.databinding.BindingFormat #
line 5, column 1. import org.grails.databinding.BindingFormat
In Grails 3.3.11, the package is grails.databinding, not org.grails.databinding (https://github.com/grails/grails-core/blob/v3.3.11/grails-databinding/src/main/groovy/grails/databinding/BindingFormat.java). The package names also changed for org.grails.web.servlet.mvc.GrailsParameterMap (https://github.com/grails/grails-core/blob/v3.3.11/grails-web-common/src/main/groovy/grails/web/servlet/mvc/GrailsParameterMap.java) and import org.grails.commons.GrailsApplication (https://github.com/grails/grails-core/blob/v3.3.11/grails-core/src/main/groovy/grails/core/GrailsApplication.java).
org.postgresql.core.Query is a separate problem. It looks like your project does not express a dependency on the postgres library, so the class isn't available to the app.

Grails - DataTables plugin doesn't exist any longer?

I tried to add --compile "org.grails.plugins:grails-datatables:0.14"-- and also
--compile "org.grails.plugins:grails-datatables:0.15" but none of them where found.
I want to use it with GRAILS-4.0.3 but it doesn't seem possible, is it abandoned in grails?
Ok, I tested with the new URL:s. Not sure if I did it correctly but it failed.
Error initializing classpath: Could not find org.grails.plugins:grails-datatables:0.15.Searched in the following locations:
file:/C:/Users/Lars/.m2/repository/org/grails/plugins/grails-datatables/0.15/grails-datatables-0.15.pom
file:/C:/Users/Lars/.m2/repository/org/grails/plugins/grails-datatables/0.15/grails-datatables-0.15.jar
https://repo.grails.org/grails/core/org/grails/plugins/grails-datatables/0.15/grails-datatables-0.15.pom
https://repo.grails.org/grails/core/org/grails/plugins/grails-datatables/0.15/grails-datatables-0.15.jar
https://repo.grails.org/grails/plugin-releases-local/org/grails/plugins/grails-datatables/0.15/grails-datatables-0.15.pom
https://repo.grails.org/grails/plugin-releases-local/org/grails/plugins/grails-datatables/0.15/grails-datatables-0.15.jar
It looks like I did it correct but it did not find it on the given URL.
build.gradle Looks like this in the beginning:
buildscript {
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "org.grails.plugins:hibernate5:${gormVersion-".RELEASE"}"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.2"
}
}
version "0.1"
group "test"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"asset-pipeline"
apply plugin:"org.grails.grails-gsp"
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
maven { url "https://repo.grails.org/grails/plugin-releases-local" }
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-web-boot"
compile "org.grails:grails-logging"
compile "org.grails:grails-plugin-rest"
compile "org.grails:grails-plugin-databinding"
compile "org.grails:grails-plugin-i18n"
compile "org.grails:grails-plugin-services"
compile "org.grails:grails-plugin-url-mappings"
compile "org.grails:grails-plugin-interceptors"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:async"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:events"
compile "org.grails.plugins:hibernate5"
compile "org.hibernate:hibernate-core:5.1.5.Final"
compile "org.grails.plugins:gsp"
compile 'org.grails.plugins:quartz:2.0.12'
console "org.grails:grails-console"
compile "org.grails.plugins:grails-datatables:0.15"
Gradle.properties looks like this:
grailsVersion=3.3.0
gormVersion=6.1.6.RELEASE
gradleWrapperVersion=3.5
But at this link: https://mvnrepository.com/artifact/org.grails.plugins/grails-datatables/0.15
I found a repository that worked:
Note: this artifact is located at Grails Plugins repository (https://repo.grails.org/grails/plugins/)
I tried to add --compile "org.grails.plugins:grails-datatables:0.14"--
and also --compile "org.grails.plugins:grails-datatables:0.15" but
none of them where found.
You have not indicated which repositories you attempted to resolve those from, but those are available:
https://mvnrepository.com/artifact/org.grails.plugins/grails-datatables/0.14
https://mvnrepository.com/artifact/org.grails.plugins/grails-datatables/0.15
https://repo.grails.org/grails/plugins-releases-local/org/grails/plugins/grails-datatables/0.15/
https://repo.grails.org/grails/plugins-releases-local/org/grails/plugins/grails-datatables/0.14/
I want to use it with GRAILS-4.0.3 but it doesn't seem possible, is it
abandoned in grails?
As far as I know there is not a version of the plugin that is compatible with Grails 4.0.3. The plugin is of course open source (https://bitbucket.org/ben-wilson/grails-datatables/src/master/).

how to get GWT work with Grails 3

I am using Grails latest version i.e 3.1.3, and GWT
I have gone through the gwt/grails plugin and their tutorials , but All of this is for old version of grails , where we had "BuildConfig.groovy" and the format looks different.
Now as we have build.gradle , I cant find a way to put gwt plugin there
What i have tried is : adding
compile "org.grails.plugins:gwt:1.0.2"
now when i run command:
grails create-gwt-module
I get the exception:
Could not resolve all dependencies for configuration ':runtime'.
> Could not find org.grails.plugins:resources:1.2.
Searched in the following locations:
file:/C:/Users/Junaid/.m2/repository/org/grails/plugins/resources/1.2/r
sources-1.2.pom
file:/C:/Users/Junaid/.m2/repository/org/grails/plugins/resources/1.2/r
sources-1.2.zip
https://repo.grails.org/grails/core/org/grails/plugins/resources/1.2/re
ources-1.2.pom
https://repo.grails.org/grails/core/org/grails/plugins/resources/1.2/re
ources-1.2.zip
Required by:
helloworld2:helloworld2:0.1 > org.grails.plugins:gwt:1.0.2
this is my build.gradle:
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0"
classpath "org.grails.plugins:hibernate4:5.0.2"
}
}
version "0.1"
group "helloworld2"
apply plugin:"eclipse"
apply plugin:"idea"
apply plugin:"war"
apply plugin:"org.grails.grails-web"
apply plugin:"org.grails.grails-gsp"
apply plugin:"asset-pipeline"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.grails:grails-core"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:cache"
compile "org.grails.plugins:scaffolding"
compile "org.grails.plugins:hibernate4"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:gwt:2.6.0"
console "org.grails:grails-console"
profile "org.grails.profiles:web:3.1.3"
runtime "org.grails.plugins:asset-pipeline"
runtime "com.h2database:h2"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
testRuntime "org.seleniumhq.selenium:selenium-htmlunit-driver:2.47.1"
testRuntime "net.sourceforge.htmlunit:htmlunit:2.18"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
Did you try to get compile "org.grails.plugins:gwt:1.0.3", the latest version of plugin?
And if it can't be downloaded automatically to download it manually from repo and put in one of searched locations in your local maven repository?
In official plugin docs you can read:
In Grails 2.x plugins were packaged as ZIP files, however in Grails
3.x plugins are simple JAR files that can be added to the classpath of the IDE.
So try to pack plugin to jar according to official deployment docs:
Another way to deploy in Grails 3.0 or above is to use the new
support for runnable JAR or WAR files. To create runnable archives,
run grails package:
grails package

Grails 3.0 and Spring Security Error

In my build.gradle I added this line of code
dependencies {
compile "org.grails.plugins:spring-security-core:3.0.3"
}
Then when I try to use it
import grails.plugin.springsecurity.annotation.Secured
#Secured('ROLE_ADMIN')
class SecureController {
def index() {
render 'Secure access only'
}
It "cannot resolve the symbol springsecurity"
I get the error
Error:(5, 1) Groovyc: unable to resolve class Secured , unable to find class for annotation
Any help would be much appreciated.
Build.gradle **** EDIT
This is the whole build.gradle file
buildscript {
ext {
grailsVersion = project.grailsVersion
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:$grailsVersion"
classpath 'com.bertramlabs.plugins:asset-pipeline-gradle:2.5.0'
classpath "org.grails.plugins:hibernate:4.3.10.5"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.4.RELEASE"
}
version "0.1"
group "securityrolesspring"
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: "asset-pipeline"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
apply plugin: "org.grails.grails-gsp"
ext {
grailsVersion = project.grailsVersion
gradleWrapperVersion = project.gradleWrapperVersion
}
assets {
minifyJs = true
minifyCss = true
}
repositories {
mavenLocal()
maven { url "https://repo.grails.org/grails/core" }
}
dependencyManagement {
imports {
mavenBom "org.grails:grails-bom:$grailsVersion"
}
applyMavenExclusions false
}
dependencies {
compile "org.grails.plugins:spring-security-core:3.0.3"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
compile "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails:grails-dependencies"
compile "org.grails:grails-web-boot"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
compile "org.grails.plugins:scaffolding"
runtime "org.grails.plugins:asset-pipeline"
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
// Note: It is recommended to update to a more robust driver (Chrome, Firefox etc.)
testRuntime 'org.seleniumhq.selenium:selenium-htmlunit-driver:2.44.0'
console "org.grails:grails-console"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
after 'apply plugin: "war"' add a line that says:
apply plugin: "maven"
in your repositories section, after "mavenLocal()" add a line that says:
mavenCentral()
this last recommendation is just cosmetic, but I would move your line:
compile "org.grails.plugins:spring-security-core:3.0.3"
and place it after the
compile "org.grails.plugins:scaffolding" line. it's good form to keep the initial set of grails dependencies pretty much as they are from the initial 'grails create-app' command. the exception to this rule is if you want to replace the logback logging with something else, but that's another story.
finally, you could also change your spring-security-core dependency to version 3.0.4 which is out now.
Spring security core has been updated the package location for #Secured Annotations. I use Grails 3.2.3 and Spring Security Core 3.1.1 int my project and works well. The following is the configuration the I used and is working as was in previos version of spring security core and Grails (2.X).
For installation, you have to add the entry in the dependencies block if your build.gradle file. Details in the oficial documentation for installation section for Spring Security Core
dependencies {
...
compile 'org.grails.plugins:spring-security-core:3.1.1'
...
To use the secured annotations in your controller, there were updates on the import (org.springframework.security.access.annotation.Secured) package and the #Secure annotation you have to assign to "value" the security statement you want to do. For example the annotation for #Secured('ROLE_ADMIN'), have to change like in the following example.
import org.springframework.security.access.annotation.Secured
#Secured(value=["hasRole('ROLE_ADMIN')"])
class SecureController {
def index() {
render 'Secure access only'
}
Detailed configuration are in the oficial documentation page, updates for secured annotation in version 3, and how to define secured annotations.
By importing
import grails.plugin.springsecurity.annotation.Secured
you will be able to resolve your problem.
It will again say that it cannot resolve symbol "Secured" but you need to ignore it because the code will run completely according to your expectation.

Resources