I want to create a sample app in Grails with Neo4J. (on IntelliJ)
After creating a simple app and added the necessary configurations inside Buildconfig.groovy
Repo
mavenRepo 'http://m2.neo4j.org/content/repositories/releases/'
Plugin
compile ":neo4j:2.0.0-M02"
I want to use MySql and Neo4J at the same time (adding mapping inside the domain model, when I want neo4j).
But I have this error:
Error |
2014-12-14 19:05:59,261 [localhost-startStop-1] ERROR context.GrailsContextLoaderListener - Error initializing the application: No bean named 'sessionFactory' is defined
Message: No bean named 'sessionFactory' is defined
Line | Method
->> 104 | postProcessBeanFactory in org.grails.datastore.gorm.plugin.support.PersistenceContextInterceptorAggregator
What am I doing wrong ?
having same problem - if I removed the neo4j plugin - and create an ordinary domain class+test works fine
as soon as you enable the neo4j plugin (2.0.0-M2) - and run the same test again it fails with the errors above -
no idea how enabling the neo plugin removed the sessionFactory bean that grails normally setsup
something cooky going on
tried to cheat and added this to the resources.groovy beans
...
sessionFactory(ConfigurableLocalSessionFactoryBean) {
dataSource = ref('dataSource')
hibernateProperties = ["hibernate.hbm2ddl.auto": "create-drop",
"hibernate.show_sql": "true"]
}
and tried to re run the test - still fails as it says that in error
..Message: No such property: ConfigurableLocalSessionFactoryBean for class: resources
so its somewhere deep in the bowels...
Finally I found a solution: Do not use this plugin. I prefer to use a micro service architecture. I created an application with Spring Boot, Groovy and Neo4J. I omitted controllers, model and spring repositories.
build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.2.RELEASE")
}
}
apply plugin: 'groovy'
apply plugin: 'idea'
apply plugin: 'spring-boot'
jar {
baseName = "it.luis"
version = '0.1-SNAPSHOT'
}
repositories {
mavenCentral()
jcenter()
maven { url "http://m2.neo4j.org/content/repositories/releases/" }
maven { url "https://repo.spring.io/libs-release" }
}
dependencies {
// compile 'org.codehaus.groovy:groovy-all:2.4.0'
compile localGroovy()
compile("org.springframework.boot:spring-boot-starter-web")
compile("org.springframework.boot:spring-boot-starter")
compile("org.springframework:spring-context")
compile("org.springframework:spring-tx")
compile("org.springframework.data:spring-data-neo4j")
compile("org.hibernate:hibernate-validator")
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("javax.el:javax.el-api:2.2.4")
testCompile("junit:junit")
/* Swagger */
compile "com.mangofactory:swagger-springmvc:0.9.5"
/* Stormpath */
compile "org.sonatype.oss:stormpath-spring-security"
runtime "com.stormpath.sdk:stormpath-sdk-httpclient:0.9.3"
}
Application.groovy
package it.luis
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
import org.springframework.boot.autoconfigure.SpringBootApplication
/**
* Created by Luigi on 01/03/2015.
*/
#SpringBootApplication
#EnableAutoConfiguration
class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class,args)
}
}
Neo4JConf.groovy
package it.luis
import com.mangofactory.swagger.plugin.EnableSwagger
import org.neo4j.graphdb.GraphDatabaseService
import org.neo4j.graphdb.factory.GraphDatabaseFactory
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.data.neo4j.config.EnableNeo4jRepositories
import org.springframework.data.neo4j.config.Neo4jConfiguration
import org.springframework.web.servlet.config.annotation.EnableWebMvc
/**
*/
#Configuration
#EnableNeo4jRepositories(basePackages = "it.luis")
#ComponentScan("it.luis")
#EnableWebMvc
#EnableSwagger
class EngineConfiguration extends Neo4jConfiguration {
EngineConfiguration() {
setBasePackage("it.luis")
}
#Bean
GraphDatabaseService graphDatabaseService() {
return new GraphDatabaseFactory().newEmbeddedDatabase("neo4j.db");
}
}
Related
We have created a pipeline shared library using Groovy and referenced that in one of java project. Build is getting success for shared library while running individual build, but when we reference the shared library and run the jenkins pipeline build of java project, it is getting failed with the below error.
org.jenkinsci.plugins.workflow.cps.CpsCompilationErrorsException: startup failed:
file:/var/lib/jenkins/jobs/Pipeline%20Test/jobs/pipeline-test/branches/develop/builds/10/libs/c3-shared-library/src/com/test/c3/http/JenkinsHttpClient.groovy: 6: unable to resolve class jodd.http.HttpRequest
# line 6, column 1.
#Grab("org.jodd:jodd-http:5.1.0")
c3-shared-library - JenkinsHttpClient.groovy:
#! /usr/bin/groovy
package com.test.c3.http
import com.cloudbees.groovy.cps.NonCPS
import groovy.json.JsonBuilder
#Grab("org.jodd:jodd-http:5.1.0")
import jodd.http.HttpRequest
import jodd.http.HttpResponse
class JenkinsHttpClient implements Serializable {
private String userAgent
JenkinsHttpClient(String userAgent = "Jenkins"){
this.userAgent = userAgent
}
Herewith attached jenkins configuration. Please check and provide your valuable inputs.
Shared Library Pipeline build.grade:
group "com.test.c3"
version "1.0.0-develop-SNAPSHOT"
apply plugin: 'maven'
apply plugin: 'groovy'
repositories {
mavenCentral()
}
compileGroovy {
groovyOptions.configurationScript = file("gradle/config.groovy")
}
sourceSets {
groovy {
main.groovy.srcDirs += 'src/'
main.groovy.srcDirs += 'vars/'
test.groovy.srcDirs += 'tests/'
}
}
dependencies {
compile "org.apache.ivy:ivy:2.5.0"
compile 'org.codehaus.groovy:groovy-all:2.5.9'
compile 'org.jodd:jodd-http:5.1.0'
compile 'com.cloudbees:groovy-cps:1.31'
testImplementation group: 'junit', name: 'junit', version: '4.4'
}
I am using Grails spring security core plugin version 3.0.3.
The debug statements when configuring the spring security core framework are printed twice and the filter chain is also initialized twice
WARN grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin -
Configuring Spring Security Core ...
Configuring Spring Security Core ...
WARN grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin - ... finished
configuring Spring Security Core
... finished configuring Spring Security Core
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 "org.grails.plugins:hibernate:4.3.10.5"
}
}
plugins {
id "io.spring.dependency-management" version "0.5.2.RELEASE"
}
version "0.1"
group "restservicesapp"
apply plugin: "spring-boot"
apply plugin: "war"
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: "org.grails.grails-web"
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-starter-actuator"
compile "org.springframework.boot:spring-boot-autoconfigure"
provided "org.springframework.boot:spring-boot-starter-tomcat"
compile "org.grails.plugins:hibernate"
compile "org.grails.plugins:cache"
compile "org.hibernate:hibernate-ehcache"
runtime "mysql:mysql-connector-java:5.1.38"
compile 'org.grails.plugins:spring-security-core:3.0.3'
compile ('org.grails.plugins:spring-security-rest-gorm:2.0.0.M2') {
exclude group: 'org.grails.plugins', module: 'spring-security-core'
}
testCompile "org.grails:grails-plugin-testing"
testCompile "org.grails.plugins:geb"
//console "org.grails:grails-console"
}
task wrapper(type: Wrapper) {
gradleVersion = gradleWrapperVersion
}
Do you have org.grails.plugins:cxf into your build.gradle ? Possibly two context are being created. One for your main app and other for your /services/*. Move the cfx dependency in gradle file above spring security plugin and then you should see spring security being configured once only. I have been struggled with this more then 2 weeks now. But this solved this issue for me. For me it actually was an issue as the spring security being configured second time it was giving my NPE at times. See this question from myself only.
Update
My above assessment proved wrong. The real solution is, add below snippet to your build.gradle
configurations.runtime {
exclude module: "cxf"
}
I believe Spring Security is not being configured twice. One line of output is from logging, the other is a println.
Below is some code from grails.plugin.springsecurity.SpringSecurityCoreGrailsPlugin:
Closure doWithSpring() {{ ->
ReflectionUtils.application = SpringSecurityUtils.application = grailsApplication
SpringSecurityUtils.resetSecurityConfig()
def conf = SpringSecurityUtils.securityConfig
boolean printStatusMessages = (conf.printStatusMessages instanceof Boolean) ? conf.printStatusMessages : true
if (!conf || !conf.active) {
if (printStatusMessages) {
String message = '\n\nSpring Security is disabled, not loading\n\n'
log.warn message
println message
}
return
}
log.trace 'doWithSpring'
if (printStatusMessages) {
String message = '\nConfiguring Spring Security Core ...'
log.warn message
println message
}
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 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.
I'm developing a web application, using Grails 2.2.3 with Ember.js (rc3). I'm using IntelliJ IDEA 12.1 Utlimate as IDE and also the IntelliJ TeamCity CI Server - everything's on Windows 7 Professional SP1. Now I wanted to use Gradle 1.7 to better organize my build tasks (combining Grails, Grunt, testing and so on...) and I expected paradise but all I got was hell...
As soon as I started to use the gradle.build file and started JetGradle in IntelliJ IDEA it started to scan and index files over and over (actually it is still running now - 14 hours and counting), the IDE is blocked and I can't do anything... it's really frustrating.
If it's of any interest, here's my gradle.build:
import org.apache.tools.ant.taskdefs.condition.Os
import org.gradle.api.tasks.Exec
import org.grails.gradle.plugin.GrailsTask
buildscript {
repositories {
maven { url "http://my.company.archiva:8080/repository/internal" }
maven { url "http://repo.grails.org/grails/repo" }
}
dependencies {
classpath "org.grails:grails-gradle-plugin:2.0.0-SNAPSHOT",
"org.grails:grails-bootstrap:2.2.3"
}
}
apply plugin: "grails"
apply plugin: "base"
repositories {
maven { url "http://my.company.archiva:8080/repository/internal" }
maven { url "http://repo.grails.org/grails/repo" }
}
grails {
grailsVersion "2.2.3"
}
configurations {
all {
exclude module: "commons-logging"
exclude module: "xml-apis"
exclude module: "grails-plugin-log4j"
exclude module: "slf4j-log4j12"
}
test {
exclude module: "groovy-all"
}
compile {
exclude module: "hibernate"
}
compileOnly
}
dependencies {
compile("com.my.company:grails-custom-plugin1:0.1.7#zip")
compile("com.my.company:grails-cusotm-plugin:0.2#zip")
compile("com.my.company:backendapi:1.1")
compile("org.mozilla:rhino:1.7R4")
compile("io.netty:netty:3.3.1.Final")
compile("com.google.protobuf:protobuf-java:2.4.1")
compile("org.grails.plugins:cache:1.0.1")
compileOnly "org.grails:grails-plugin-tomcat:$grails.grailsVersion" // No tomcat-*.jar in the war
bootstrap "org.codehaus.groovy:groovy-all:2.0.5"
}
/*
GRADLE Wrapper
*/
task wrapper(type: Wrapper) {
gradleVersion = '1.7'
}
/*
GRUNT Section
*/
task npm(type: Exec) {
group = "Build"
description = "Installs all Node.js dependencies defined in package.json"
workingDir "web-app"
commandLine = ["npm.cmd", "install"]
inputs.file "package.json"
outputs.dir "node_modules"
}
task production(type: GruntTask) {
gruntArgs = "prod"
}
class GruntTask extends Exec {
private String gruntExecutable = Os.isFamily(Os.FAMILY_WINDOWS) ? "grunt.cmd" : "grunt"
private String switches = "--no-color"
private String workDir = "web-app"
String gruntArgs = ""
public GruntTask() {
super()
this.setExecutable(gruntExecutable)
this.workingDir(workDir)
}
public void setGruntArgs(String gruntArgs) {
this.args = "$switches $gruntArgs".trim().split(" ") as List
}
}
/*
WAR creation
*/
task war(type: GrailsTask) {
command "war"
env "prod"
}
Is anybody out there who is able to help me? I searched the internet up and down but it seems that either nobody is using the combination of Grails, Ember.js, Gradle, IntelliJ IDEA or everything is dead simple and I'm just to stupid to use the tools...
I don't recommend to use the Gradle integration in IDEA 12 as it's too limited. (IDEA 13 will be better.) Instead you can use Gradle's "idea" plugin to generate IDEA files. Not sure how well all of this works together with Grails. Grails' own build tool is deeply integrated with the rest of Grails, and from what I've heard, using anything else means to make compromises. (I don't have first-hand experience though.) There have been plans for Grails to switch over its built-in build tool to Gradle one day.
PS: I'd search the IDEA issue tracker and file an issue if there is none.