best way to create a grails 3 app for web - grails

I have previously used "grails create-app myapp" and the resultant application has web built in - e.g. I can scaffold or modify my views.
I see that there are various profiles, including "web". Web has various features. What is not clear is what the consequence of adding or not adding features, and why "web" is different from no profile.
Web profile features are:
Provided Features:
asset-pipeline - Adds Asset Pipeline to a Grails project
events - Adds support for the Grails EventBus abstraction
geb - Adds Geb 1.1.1 and WebDriver 2.47.1 to run functional tests
geb2 - Adds Geb 2, WebDriver 3.6.0 and Webdriver binaries Gradle Plugin dependencies to run functional tests. Requires JDK8.
gsp - Adds support for GSP to the project
hibernate4 - Adds GORM for Hibernate 4 to the project
hibernate5 - Adds GORM for Hibernate 5 to the project
json-views - Adds support for JSON Views to the project
less-asset-pipeline - Adds LESS Transpiler Asset Pipeline to a Grails project
markup-views - Adds support for Markup Views to the project
mongodb - Adds GORM for MongoDB to the project
neo4j - Adds GORM for Neo4j to the project
rx-mongodb - Adds RxGORM for MongoDB to the project
The confusing thing is whether I select web profile or not, and select hibernateX or not, I get hibernate anyway.
I know I dont need mongodb, neo4, rx-mongodb, geb, geb2, but surely everyone needs asset-pipeline etc. Should I chose json-views, hibernate5, gsp etc? If I forget to add these, how can they be added later?

Does not matter what the default generated build.gradle file contains, you can remove the items you don't need straight away.
So, you should pick
asset-pipeline
gsp
hibernate4/5
and the web-profile.
The same is true for adding new plug-ins or dependencies: you can do it any time later.
You should strive to keep the dependencies at minimum, as they mihgt have internal (version) conflicts.

Related

Precedence among plugins when choosing view

I have a rather monolithic Grails 2 application that I am attempting to upgrade to Grails 3 (specifically 3.2.7) and refactor into a set of plugins - the current app uses various services on Amazon AWS, I want to refactor it so I can more easily switch to Microsoft Azure or OpenStack.
At present, the big app uses various plugins including Spring Security UI, and the app overrides some of the GSP views from the plugin with its own. In the refactored scenario I have the main app (which will implement the AWS-specific bits), depending on a "core" plugin (with the cloud-agnostic functions) which in turn depends on spring-security-ui. The problem I'm having is that when I put my custom auth.gsp view in the "core" plugin rather than in the top-level app, it no longer overrides the s2ui version of the same view. If I copy the "core" plugin's auth.gsp to the same location in the top-level app, it overrides correctly.
In general, if I have app depends-on plugin1 depends-on plugin2, is there a way to ensure that when I run the app, views provided by plugin1 take precedence over the same views provided by plugin2?
The core plugin will need to specify it should be loaded after spring security ui. You can do that with:
def loadAfter = ['springSecurityUi']
This is documented here: http://docs.grails.org/latest/guide/plugins.html#understandingPluginLoadOrder

How to share Domain Codebase between Grails 2 and Grails 3

At the moment, we have multiple grails applications built on grails 2.5.0
Our Model is in a grails plugin (2.5.0), published to a local maven repository. So far everything works great.
Now we want to create a new application with Grails 3, which relies on some of the basic Domains located in a grails2 plugin (User, Group, etc).
What would be the best way, to share those ? I dont want to maintain two code-bases for our model, one for v2 and one for v3 ...
The only thing which came into my mind is, building everything in plain groovy Classes / Interfaces, and then extending / implementing the Model in both grails2 and grails3 plugins
core-model (contains Interfaces, abstract classes)
grails-model-v2
grails-model-v3
You're on the right track. The domain classes will probably work unchanged, but the problem is the grails plugin projects are incompatible. So you can use a plain groovy project to house your domains and then have each plugin depend on the domain project. The tricky part is telling grails that those plain groovy classes are domains. In grails 3 you can probably just apply the groovy traits that grails automatic applies to domains using doWithSpring(). I think grails 2 uses metaClass to accomplish the same thing, so the approach might be similar.

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

Is it possible to add Grails MVC classes at deployment time?

I'm writing a Grails app which I'd like 3rd parties to augment at runtime. Ideally they would be able to add a JAR/WAR to the webapp directory which contains new domain, controller and service classes, new views, and other content.
Is there a simple way to do this within grails? Would it be simplest to create a startup script which copies the new classes etc. into the relevant directories and then updates grails.xml and web.xml?
You will be able to do this in version 2 of grails in which plugins will be also OSGI plugins http://jira.codehaus.org/browse/GRAILS/fixforversion/15421
It seems that the Grails plugins will actually fit quite well for this: http://www.grails.org/Understanding+Plugins
A plugin can do just about anything... One thing a plugin cannot do though is modify the web-app/WEB-INF/web.xml or web-app/WEB-INF/applicationContext.xml files. A plugin can participate in web.xml generation, but not modify the file or provide a replacement. A plugin can NEVER change the applicationContext.xml file, but can provide runtime bean definitions

Resources