Is it possible to use GroovyPageParser or GroovyPagesTemplateEngine outside of grails - grails

I have created an angular application under grails. I would like to separate it now from grails and make it a gradle application (generation of the final files would be gradle job). However in the interim I would still like to use my taglibs How can I render gsp under gradle without grails loaded?
TIA
Pascal

There is GSP for Spring Boot a.k.a Standalone GSP available.
See examples: https://github.com/grails/grails-boot/tree/master/sample-apps/gsp
Example of a standalone Spring Boot groovy script: https://github.com/grails/grails-boot/blob/master/sample-apps/gsp/script/app.groovy (requires currently the provided run_app.sh script for launching)
It doesn't support all Grails taglibraries. Only sitemesh and render taglibs are supported of the Grails core taglibs.
However, you can reuse taglibraries if you annotate them with the grails.gsp.TagLib annotation and register them as beans in the application context that runs the Spring Boot application.

Related

What is the corresponding artifact for Config.groovy of grails 2.x in grails 3.x?

I want to migrate an application from grails 2.4.4 to grails 3.3.9.
As the structure of the conf directory in grails 2.x is completely different from 3.x, there is no config.groovy in 3.x anymore. In config.groovy of 2.x I used to define lists of constants for my select boxes like:
metals=['au','ag','pl']
and I accessed them via
static List getMetals() {
grails.util.Holders.config.metals
}
in my groovy code.
What is the corresponding way in 3.x?
I would start by checking out the upgrade guides:
http://docs.grails.org/latest/guide/upgrading.html
http://docs.grails.org/3.2.0/guide/upgrading.html#upgrading2x
config.groovy, by default becomes application.yml, but you can convert that to application.groovy, and there is a script in the external config plugin that will help with that:
http://plugins.grails.org/plugin/grails/external-config
In general it is conserdered back practice to use the holders, it would be better to use either an injected bean/service
GrailsApplication grailsApplication
grailsApplication.config.etc
Or wire in a bean using resources. The only reason to use holders is in another object that is outside of grails, that for some reason, you can't wire up as a bean. In that cases there is now a Holders class, that you can get the config from. Here's some other ways to get at the config from an OCI blog:
http://grailsblog.objectcomputing.com/posts/2016/08/31/retrieving-config-values.html

spring security plugin grails 3 quick start artifacts

Spring Security in Grails 3 sets up a login page view and controller after following the quick start guide.
https://grails-plugins.github.io/grails-spring-security-core/v3/index.html#s2-quickstart
There should be auth.gsp, loginController.groovy created somewhere automatically. They are not visible in the app workspace. Where are they?
They're in the plugin, in both the 2.x and 3.x plugins. To override any of them, create a file with the same name and put it in the same relative location in your app and Grails will use yours instead.

grails command line application

I have a grails web application with a domain model and a hibernate datasource persistence.
I would like to write now a command line tool in groovy to access also this domain model and the hibernate datasource.
Any ideas how I can do this?
regards
Vanigor
You can use Spring Boot as described in this article.
That example creates a small web UI, but Boot can be configured as a CLI app.

Order of Grails Bootstrap classes

On one of our feature branches of our project we have a strange issue with running our grails integration tests. In our application we have the base project and one plugin, which relies on data from the base application. The default data is created in the "Bootstrap" Classes of the project and the plugin.
since yesterday the bootstrap of the plugin is called before the base bootstrap, and fails, because of the missing data from the application. This happens only if we run the integration tests, and only on our buildserver (Windows Server 2012 with Atlassian Bamboo).
test-app -integration --stacktrace -non-interactive
how can we fix this problem?
Grails makes no guarantees about ordering of BootStrap classes so it isn't something that should be relied about in your application.
If you need to control ordering of logic that is run at startup there are better solutions, for example you could use the platform-core plugin's event model to trigger an event in your application that your plugin listens to once the data it needs is in place. See http://grails-plugins.github.io/grails-platform-core/guide/events.html

What is a Grails Plugin? What does it mean to Install a Plugin?

I used Grails recently, and added Grails plugin for JQuery, but I don't think it did anything more than just copy some jQuery files over.
So far, I have seen info only on 'how to install and use' plugins...but I can't find anything that describes the concept of a plugin.
Can somebody please tell me, what is a Grails Plugin? And what does it mean to 'Install' a plugin?
A Grails plugin is (or should be) a self-contained bundle of functionality that can be installed into a Grails application. When a Grails plugin is installed, it can do any of the following:
define additional Spring beans
modify the generated web.xml
add new methods to the application's artefacts (controllers, domain classes, services, etc.)
provide new tag libraries
make additional resources and classes available to the application
provide new Grails commands
For example, when you install the JQuery plugin
the JQuery JavaScript files are added to the application
a new Grails tag <jq:jquery> is added to the application
a new Grails command grails install-plugin jquery is added to the application
When you install a Grails plugin, that plugin's functionality is made available to the installing application. However, the plugin itself is not actually copied into the application, only the plugin name and version is added to the application's application.properties file. The plugin itself is downloaded to $HOME/.grails and the application loads it from there.
The structure of a Grails plugin project is identical to that of a Grails application, with the exception of a configuration file (known as a plugin descriptor) that is included in a plugin's root directory.
Well, a Grails plugin is some piece of software that extends the frameworks funcionalities in some manner. Generally, installing a plugin in Grails means copying it to your Grails folder, so projects can refer to it and Grails will know where to find it.
Grails plugins have this folder structure:
grails-app
controllers
domain
taglib
service
etc
lib
src
java
groovy
web-app
js
css
So anything it has there will also be available to the application that uses it. For example, the Searchable plugin has a service class which you can use to perform advanced searchs in your own domain classes .
The jQuery plugin you mentioned has the jQuery .js file, and a tag to include that file.
For information on creating plugins, see http://grails.org/doc/latest/guide/12.%20Plug-ins.html
A plugin is just a set of functionality around a desired purpose. So the Spring Security plugin provides a way to lock down your app, assign roles to users, restrict access, whatever. The Searchable plugin allows you to integrate advanced searching into your app. There are lots of plugins
The point is to provide useful functionality so that you don't have to implement hard things yourself. Someone did something useful, and they wanted to contribute back to the community, so they organized their functionality and made it available.
A plugin is code and configuration, like any functionality you would implement yourself.
There is some documentation here: http://grails.org/doc/latest/ref/Plug-ins/Usage.html

Resources