Writing a Grails Script that references another Script - grails

I am using the Grails release plugin, see: http://grails.org/plugin/release, version 2.2.0 to publish plugin to a local repo.
I want to write my own Grails script which invokes: publish-plugin and then does a little bit extra.
I try:
includeTargets << grailsScript("_GrailsInit")
includeTargets << grailsScript("_ReleasePlugins")
target(main: "This script packages the plugin and deletes any directories that are not needed and created by Grails") {
println(">>packageTypes()")
publishPlugin()
//...
}
setDefaultTarget(main)
I get:
| Error Error executing script PublishTypes: _ReleasePlugins (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
java.lang.ClassNotFoundException: _ReleasePlugins
at java_lang_ClassLoader$loadClass.call(Unknown Source)
Any ideas?
Thanks

Related

Why am I getting groovy.lang.MissingPropertyException for TRACE?

In groovy file I've imported jars groovy.util.logging.Log4j and
org.apache.log4j.Level for using #Log4jand I'm setting log level as: log.setLevel(Level.TRACE) in the constructor.
Now while executing the script I'm getting groovy.lang.MissingPropertyException: No such property: TRACE for class: org.apache.log4j.Level but when I replace TRACE with INFO it executes successfully.
So what will be the reason for this?
Do you use multiple version of log4j in your application?
[log4j-1.2.16.jar & lower to log4j-1.2.12.jar which doesn't support TRACE]
In this case,lower version might have been taken into consideration by your groovy script.If you are executing script in LINUX,append $GROOVY_HOME/lib/log4j-1.2.16.jar to $CLASSPATH at the end. This works!!!

Grails-Camel Plugin won't install or run

Please note: Although this question involves a lib called Apache Camel I really think this is just a question about how modern Grails plugins work.
I am on Grails 2.4.2 here, and I am trying to use Apache Camel with Grails and found the Grails Routing plugin annd cannot even get it to install.
The directions say to install by issuing a grails install-plugin routing. When I do this I get:
grails install-plugin routing
Starting process on LT-IE-ZH/10.10.99.14
Loading Grails 2.4.2
|Configuring classpath
.
|Environment set to development
......Warning
|
Since Grails 2.3, it is no longer possible to install plugins using the install-plugin command.
Plugins must be declared in the grails-app/conf/BuildConfig.groovy file.
Example:
grails.project.dependency.resolution = {
...
plugins {
compile ":routing:1.3.2"
}
}
So I modify my BuildConfig.groovy like so:
plugins {
// plugins for the build system only
build ":tomcat:7.0.54"
compile ":routing:1.3.2"
...lots of other stuff omitted for brevity
}
Then the plugin says to create routes, issue a grails create-route <RouteName>. So I do exactly that:
grails create-route OrderListener
Starting process on LT-IE-ZH/10.10.99.14
Loading Grails 2.4.2
|Configuring classpath
|Running pre-compiled script
|Script 'CreateRoute' not found, did you mean:
1) CreateFilters
2) CreatePom
3) CreateApp_
4) CreateController
5) CreateHibernateCfgXml
Please make a selection or enter Q to quit:
What is going on here?!? How do I install/use this plugin?!? Am I losing my mind, or does this plugin simply not work?
Update
I run grails clean-all, then grails refresh-dependencies then grails create-route OrderListener and I get:
Loading Grails 2.4.2
.
|Environment set to development
.....Error
|
groovy.lang.MissingMethodException: No signature of method: CreateRoute.createArtifact() is applicable for argument types: () values: []
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
Error |
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
Error |
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Error |
at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
Error |
<huge stacktrace omitted>
Error |
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:207)
Error |
at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:68)
Error |
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
Error |
at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
Error |
... 68 more
Whenever you make a change in BuildConfig.groovy be sure to run grails compile to trigger dependency resolution, which will download new and updated plugins and jars, and it will also compile your code which helps to ensure that things are minimally compatible at least.
But the core issue here is that the plugin's CreateRoute.groovy script is badly broken. It's missing an important include and doesn't come close to calling createArtifact correctly. As a workaround until the authors get this fixed, create a script in your app's scripts folder called CreateCamelRoute.groovy with this content:
includeTargets << grailsScript('_GrailsCreateArtifacts')
target(createCamelRoute: "Creates a new Camel Route.") {
createArtifact(type: 'Route', path: 'grails-app/routes', name: argsMap.params?.get(0) ?: 'Example', suffix: 'Route')
}
setDefaultTarget(createCamelRoute)
It's intentionally named differently from the original because if Grails finds two with the same name it asks which one to use. This way you can just run
grails create-camel-route com.foo.bar.OrderListener
and it will work. Note that I changed the example a bit to include a package - always use packages :)

forked execution breaks includeTargets in Grails _Events.groovy plugin

seem to have more stupid issues with forked Execution in grails than anything else
using grails 2.4.4 on GGTS 3.6.3, groovy 2.3.7, 64bit
trying to repair another plugin (its out of date and i'm trying to fixit). had problems. pared all back to a simple plugin and demo project that includes the plugin from the local workspace
in DemoProject I do the local include of the plugin like this in buildConfig.groovy
grails.plugin.location.DummyPlugin = "../DummyPlugin"
so far so good. without adding an _Events.grooy and running the DemoProject all starts ok and plugin loads.
now add an _Events.groovy to the plugins /script folder. In that file I have this line right at top
import grails.util.BuildSettingsHolder as build
import groovy.xml.MarkupBuilder
includeTargets << grailsScript("_GrailsPackage")
now when you run the demo project you get an error like this
|Running Grails application
Error |
Error loading event script from file [E:\workspace\ggts3.6.2-workspace\DummyPlugin\scripts\_Events.groovy] No such property: classLoader for class: java.lang.Object (NOTE: Stack trace has been filtered. Use --verbose to see entire trace.)
groovy.lang.MissingPropertyException: No such property: classLoader for class: java.lang.Object
at grails.util.BuildSettings$1.doCall(BuildSettings.groovy:409)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at _Events.run(_Events.groovy:29)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.createEventListener(ForkedTomcatServer.groovy:147)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.createTomcatRunner(ForkedTomcatServer.groovy:104)
at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1270)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.runInternal(ForkedTomcatServer.groovy:82)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.run(ForkedTomcatServer.groovy:66)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer$run.call(Unknown Source)
at org.grails.plugins.tomcat.fork.ForkedTomcatServer.main(ForkedTomcatServer.groovy:60)
Error |
Error loading event script from file [E:\workspace\ggts3.6.2-workspace\DummyPlugin\scripts\_Events.groovy] No such property: classLoader for class: java.lang.Object
|Server running. Browse to http://localhost:8080/DemoDummyProject
if you got back to the DemoProject and stopped forked Execection by setting grails.project.fork =[] and run again it all works fine - no errors.
so essentially forked execution screws up the plugins includeTargets action.
how do you fix this whilst std forked config is now enabled as default - any clues? advice requested

Grails application using grails-gradle-plugin gets PermGen space error upon run-app

I have a multi-project gradle build that has several Grails app.
One of these app contains many artefacts (controllers, services, groovy code, etc...).
When I run it using the gradle grails-run-app command, I get the following error:
| Error Server failed to start: PermGen space (Use --stacktrace to see the full trace)
We tried to add to buildConfig.groovy the following
disable.auto.recompile=true
and add the following to the gradle.properties
-XX:MaxPermSize=1G -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled
But the error remain
I am using:
Grails 2.3.1, Gradle 1.8 and grails-gradle-plugin 2.0.0-SNAPSHOT
Any ideas ?
Eduardo
Add the following lines to the begin of your gradle.build
import org.grails.gradle.plugin.GrailsTask
tasks.withType(org.grails.gradle.plugin.GrailsTask) { Task t ->
t.jvmOptions {
jvmArgs '-Xms32m -Xmx1524m -XX:PermSize=32m -XX:MaxPermSize=512m -XX:+UseCompressedOops -XX:+UseConcMarkSweepGC -XX:+UseParNewGC'.split(' ')
}
}
It runs every grails task with the specified jvm args.
Check this link

"Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter" error while running a simple GEB program

I have:
java version "1.6.0_37"
Java(TM) SE Runtime Environment (build 1.6.0_37-b06-434-10M3909)
Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01-434, mixed mode)
Grails 2.2.0
Groovy 2.0
GEB core 0.7.2
and all the required jars.
I am trying to run a simple GEB program:
#Grapes([
#Grab("org.codehaus.geb:geb-core:0.7.2"),
#Grab("org.seleniumhq.selenium:selenium-firefox-driver:2.28.0"),
#Grab("org.seleniumhq.selenium:selenium-support:2.15.0")
])
import geb.Browser
Browser.drive {
go "http://googel.com/"
assert title == "Google"
}
and as I run this I am seeing the above mentioned exception:
Exception in thread "main" java.lang.ClassNotFoundException: org.codehaus.groovy.tools.GroovyStarter
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
Basically your GROOVY_HOME is either pointing to wrong location or not accessible. Just correct it and job done.
I faced this when I was trying to execute a groovy script as part of some migration activity.
The problem was simple. In my case it was not able to see the path of groovy installation.
When I used full path of $GROOVY_HOME/bin/groovy <script>
It worked.
It has nothing to do with Geb -- your environment is misconfigured.
Have a look at this groovy user mailing list thread.
Another thing is that as far as I know Geb 0.7.2 is compiled with Groovy 1.8.6 and I don't know if it's compatible with Groovy 2.0.
Download Groovy Binary From http://groovy.codehaus.org/Download
Download zip: Binary Release
Extract Local Disk say D;\GROOVY\ groovy-2.3.9
It contains the Folder Structure D:. ├───bin ├───conf ├───embeddable ├───indy ├───lib └───META-INF
Go to Control Panel\User Accounts\User Accounts  Change My Environment Variables
Set/new GROOVY_HOME = D:\GROOVY\groovy-2.3.9 (don’t put : semicolon)
Set PATH = C:\Program Files\Java\jdk1.8.0_25\bin;%GROOVY_HOME%\bin;
Add groovy-all.jar to CLASSPATH
D:\ GROOVY\ \groovy-2.3.9\embeddable\groovy-all-2.3.9.jar;.
Close and Open Command and Say –groovy
For console -groovyConsole

Resources