I am using Grails 2.2.4 and audit-trail plugin 2.0.3.
I previously installed the plugin using the deprecated "grails install-plugin" and it works. But now I try using BuildConfig. I have this configuration:
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.8.3"
runtime ":resources:1.2"
build ":tomcat:$grailsVersion"
runtime ":database-migration:1.3.2"
compile ':cache:1.0.1'
runtime ":audit-trail:2.0.3"
runtime ":spring-security-core:1.2.7.3"
}
But now the columns for createdBy, editedBy, createdDate and editedDate are not created in the database for domain with annotation #gorm.AuditStamp
My Config.groovy has this:
grails {
plugin{
audittrail{
createdBy.field = "createdBy"
editedBy.field = "editedBy"
createdDate.field = "createdDate"
editedDate.field = "editedDate"
}
}
}
Thank you
You need to add the plugin in compile scope
compile ":audit-trail:2.0.3"
so that the AST transformation would kick in at compile time to add the configured fields to the domain class.
Related
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.
I am currently trying to build a Grails project using Gradle to easily integrate some repositories. I have created a new directory, and from said directory I have created the following build.gradle file as instructed from this site:
http://grails.github.io/grails-gradle-plugin/docs/manual/guide/introduction.html
buildscript {
repositories {
jcenter()
}
dependencies {
'org.grails:grails-gradle-plugin:2.1.0'
}
}
apply plugin: 'grails'
grails {
grailsVersion = '2.4.0' // Specifies the Grails version to use
groovyVersion = '2.3.1' // Specify the Groovy version to use (should match the version that ships with the above Grails version)
springLoadedVersion = '1.2.0.RELEASE' // Specify the Spring Loaded version to use
}
repositories {
jcenter()
grails.central() //Adds the Grails Central Repository for resolving Grails plugins (replaces grailsPlugins(), grailsCentral() from BuildConfig.groovy)
}
dependencies {
bootstrap 'org.grails.plugins:tomcat:7.0.50.1'
compile 'org.grails.plugins:scaffolding:2.0.2'
compile 'org.grails.plugins:cache:1.1.1'
runtime 'org.grails.plugins:hibernate:3.6.10.8' //or 'org.grails.plugins:hibernate4:4.3.1.1'
runtime 'org.grails.plugins:database-migration:1.3.8'
runtime 'org.grails.plugins:jquery:1.11.0'
runtime 'org.grails.plugins:resources:1.2.2'
//runtime 'mysql:mysql-connector-java:5.1.24'
//runtime 'org.postgresql:postgresql:9.3.1100-jdbc41'
//Additional resources capabilities
//runtime 'org.grails.plugins:zipped-resources:1.0.1'
//runtime 'org.grails.plugins:cached-resources:1.1'
//runtime 'org.grails.plugins:yui-minify-resources:0.1.5'
//Alternate to the resources plugin
//compile 'org.grails.plugins:asset-pipeline:1.5.0'
//Additional asset-pipeline capabilities
//compile 'org.grails.plugins:sass-asset-pipeline:1.5.1'
//compile 'org.grails.plugins:less-asset-pipeline:1.5.0'
//compile 'org.grails.plugins:coffee-asset-pipeline:1.5.0'
//compile 'org.grails.plugins:handlebars-asset-pipeline:1.0.0.3'
}
When I try to build using gradle init, I am confronted with this error:
FAILURE: Build failed with an exception.
Where:
Build file '/home/ian/grailsDir/deadness/build.gradle' line: 10
What went wrong:
A problem occurred evaluating root project 'deadness'.
Plugin with id 'grails' not found.
How can I get the Grails plugin? I am currently running Grails 2.5.0 and Gradle 2.4. I tried it with an earlier version of Grails as well.
The stacktrace is:
* Exception is:
org.gradle.api.GradleScriptException: A problem occurred evaluating root project 'deadness'.
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:76)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl$1.run(DefaultScriptPluginFactory.java:148)
at org.gradle.configuration.DefaultScriptPluginFactory$ScriptPluginImpl.apply(DefaultScriptPluginFactory.java:156)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:39)
at org.gradle.configuration.project.BuildScriptProcessor.execute(BuildScriptProcessor.java:26)
at org.gradle.configuration.project.ConfigureActionsProjectEvaluator.evaluate(ConfigureActionsProjectEvaluator.java:34)
at org.gradle.configuration.project.LifecycleProjectEvaluator.evaluate(LifecycleProjectEvaluator.java:55)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:487)
at org.gradle.api.internal.project.AbstractProject.evaluate(AbstractProject.java:85)
at org.gradle.execution.TaskPathProjectEvaluator.configureHierarchy(TaskPathProjectEvaluator.java:42)
at org.gradle.configuration.DefaultBuildConfigurer.configure(DefaultBuildConfigurer.java:35)
at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:129)
at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:106)
at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:86)
at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:90)
at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(ExecuteBuildActionRunner.java:28)
at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildActionRunner.java:35)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:41)
at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:28)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:50)
at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.execute(DaemonUsageSuggestingBuildActionExecuter.java:27)
at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:40)
at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.java:169)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:237)
at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:210)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:35)
at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRuntimeValidationAction.java:24)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:206)
at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:169)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
at org.gradle.launcher.Main.doAction(Main.java:33)
at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:54)
at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:35)
at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: org.gradle.api.plugins.UnknownPluginException: Plugin with id 'grails' not found.
at org.gradle.api.internal.plugins.DefaultPluginManager.apply(DefaultPluginManager.java:110)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.applyType(DefaultObjectConfigurationAction.java:113)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.access$200(DefaultObjectConfigurationAction.java:36)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction$3.run(DefaultObjectConfigurationAction.java:80)
at org.gradle.api.internal.plugins.DefaultObjectConfigurationAction.execute(DefaultObjectConfigurationAction.java:136)
at org.gradle.api.internal.project.AbstractPluginAware.apply(AbstractPluginAware.java:46)
at org.gradle.api.plugins.PluginAware$apply.call(Unknown Source)
at org.gradle.api.internal.project.ProjectScript.apply(ProjectScript.groovy:34)
at org.gradle.api.Script$apply$0.callCurrent(Unknown Source)
at build_cgy5iob1jp300dugadkqvpnyl.run(/home/ian/grailsDir/deadness/build.gradle:10)
at org.gradle.groovy.scripts.internal.DefaultScriptRunnerFactory$ScriptRunnerImpl.run(DefaultScriptRunnerFactory.java:74)
... 35 more
Please, note that the following code...
dependencies {
'org.grails:grails-gradle-plugin:2.1.0'
}
...should be:
dependencies {
classpath 'org.grails:grails-gradle-plugin:2.1.0'
}
This must solve the issue.
I am trying to use the gradle-grails-plugin to build an existing (small) Grails project. Should this work? What is the relationship between the dependencies in build.gradle and the ones specified in buildConfig.groovy?
In any event, I have two projects, so the topmost build.gradle file is in the parent directory and looks like:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.2.0.RC1"
}
}
task wrapper(type: Wrapper) {
gradleVersion = '2.3'
}
and then the build.gradle in the Grails project looks like:
apply plugin: "grails"
repositories {
grails.central() //creates a maven repo for the Grails Central repository (Core libraries and plugins)
}
grails {
grailsVersion = '2.4.4'
groovyVersion = '2.3.9'
springLoadedVersion '1.2.0.RELEASE'
}
dependencies {
bootstrap "org.grails.plugins:tomcat:7.0.55.3"
compile 'org.grails.plugins:asset-pipeline:3.0.1'
compile 'org.grails.plugins:scaffolding:2.1.2'
compile 'org.grails.plugins:cache:1.1.8'
runtime 'org.grails.plugins:hibernate4:4.3.1.1'
runtime 'org.grails.plugins:database-migration:1.3.8'
runtime 'org.grails.plugins:jquery:1.11.0'
}
However, when I run ./gradlew war, I get back:
Caused by: java.long.ClassNotFoundException: grails.artefact.Service
Can anyone shed some light on this? There are practically no references to that via Google, it seems to be a Grails 3.x class? Also, I am using Java 1.7.
Class grails.artefact.Service is indeed accessible from v3.0 of grails framework - as can be seen here.
With the following statement grailsVersion = '2.4.4' v2.4.4 is specified to be used and it all looks ok. What spoils the build is the following dependencies entry:
compile 'org.grails.plugins:asset-pipeline:3.0.1'
In this package there is a class asset/pipeline/grails/AssetProcessorService that imports the mentioned grails.artefact.Service which isn't loaded at runtime (probably because of v2.4.4 used).
Unfortunately I can't suggest any solution apart from the trivial like excluding this dependency. I am not a grails developer nor have I set the environment up.
Hopes that helps somehow.
Sorry Grails noob here.
I am looking at a project which has some references to JUnit in its test code. I am trying to figure out how JUnit is being added to the classpath. I go to the BuildConfig.groovy file and I see no explicit reference to JUnit.
The dependencies are:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
runtime 'postgresql:postgresql:9.0-801.jdbc4'
compile 'com.thoughtworks.xstream:xstream:1.4.2'
compile 'spy:spymemcached:2.8.9'
compile "org.grails:grails-webflow:$grailsVersion"
compile 'org.infinispan:infinispan-core:5.1.0.CR2'
}
The plugin dependencies are:
plugins {
test(":spock:0.7") {
exclude "spock-grails-support"
}
runtime ":jquery:1.7.2"
runtime ":resources:1.1.6"
// Uncomment these (or add new ones) to enable additional resources capabilities
//runtime ":zipped-resources:1.0"
//runtime ":cached-resources:1.0"
//runtime ":yui-minify-resources:0.1.4"
build ":tomcat:$grailsVersion"
compile ":geoip:0.2"
compile ':cache:1.0.0'
compile ":quartz:1.0-RC9"
//compile ":quartz-monitor:0.3-RC2"
compile ":grails-melody:1.45"
compile ':webflow:2.0.0', {
exclude 'grails-webflow'
}
}
So any ideas on what could be bringing in the Junit jar or how I'd find out what it is?
Thanks.
JUnit is part of the grails packaging by default. You should be able to find junit jar in lib of grails bundle which you would have downloaded from grails.org in
GRAILS_HOME\lib\junit\junit\jars
You can also verify how it is added to the project by running grails dependency-report on the project and looking for junit jar in test scope.
The latest version of junit shipped with Grails 2.2.3 is junit-4.10.
I'm trying to build a Grails 2.0 application using private plugins:
mycompany-frontend = Grails Application
mycompany-core = Grails plugins for domain classes
In the mycompany-core plugin, I created some domain classe and added a joda-time dependency in BuildConfig.groovy:
plugins {
build(":tomcat:$grailsVersion",
":release:1.0.1",
":svn:1.0.2") {
export = false
}
build(":joda-time:1.3.1")
}
in the mycompany-frontend app, I have the following BuildConfig.groovy:
plugins {
runtime ":hibernate:$grailsVersion"
runtime ":resources:1.1.5"
build "mycompany:mycompany-core:0.1-SNAPSHOT"
build ":svn:1.0.2"
build ":spring-security-core:1.2.7"
build ":tomcat:$grailsVersion"
}
I also removed grails.plugins entries from application.properties to avoid confusion.
But at the end, the mycompany-frontend cannot find the model classes from mycompany-core plugin.
What should I look/fix to get this working?
Have you tried to define the dependency to your core-plugin as runtime-/compile-dependency instead of build?