forked execution breaks includeTargets in Grails _Events.groovy plugin - grails

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

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 3.1.10 exclude spring-boot-starter-tomcat plugin from war generation

If I leave the "spring-boot-starter-tomcat" plugin dependency set to compile in the gradle build file I get the following error messages deploying to a standalone Tomcat 7 server:
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-core-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/servlet/Servlet.class
Aug 18, 2016 2:51:19 AM org.apache.catalina.loader.WebappClassLoader validateJarFile
INFO: validateJarFile(/usr/share/tomcat/webapps/ROOT/WEB-INF/lib/tomcat-embed-el-8.0.36.jar) - jar not loaded. See Servlet Spec 3.0, section 10.7.2. Offending class: javax/el/Expression.class
If I change the dependency to provided I can deploy to Tomcat but get the following error attempting to run or debug within IntelliJ IDEA 15:
ERROR org.springframework.boot.SpringApplication - Application startup failed
org.springframework.beans.factory.BeanDefinitionStoreException: Failed to process import candidates for configuration class [orderserver.Application]; nested exception is java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.IllegalStateException: Failed to introspect annotated methods on class org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport
...
Caused by: java.lang.NoClassDefFoundError: javax/servlet/ServletContext
...
Caused by: java.lang.ClassNotFoundException: javax.servlet.ServletContext
How can I exclude these dependencies from the war file generation while retaining the ability to run/debug within IDEA?
Even better is there a way to generate a single war file that has embedded Tomcat for standalone execution that can also be deployed to a Tomcat container?
This issue was resolved by changing the dependency to provided and using a "Grails" run/debug configuration instead of the "Application" configuration that was set when I created the project with IDEA 15.

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 :)

Writing a Grails Script that references another Script

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

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

Resources