How do I use handlebars-asset-pipeline with Grails? - grails

I'm close to giving up here -- there's roughly 5 different repositories with different versions of handlebars-asset-pipeline with different instructions, and I can't get any of them to work.
I'm using Grails 3.1.1 with the default build.gradle created by init-app, added handlebars-asset-pipeline 2.7 to both the buildscript and normal dependencies, and put a foo.hbs file into grails-app/assets.
Now, when running gradlew compileAssets, the templates get compiled correctly, so the plugin is doing something, but I was expecting it to also work when running the application via grails run-app. Is it wrong of me to expect that? If not, can someone be so kind as to give me a working example of how to integrate the template precompiler?

I find specifying assets instead of runtime is the thing that trips me up. I can get it to work adding the following
buildscript {
...
dependencies {
...
classpath "com.bertramlabs.plugins:asset-pipeline-gradle:2.14.6"
}
}
apply plugin: 'com.bertramlabs.asset-pipeline'
runtime "com.bertramlabs.plugins:asset-pipeline-grails:2.14.3"
assets 'com.bertramlabs.plugins:handlebars-asset-pipeline:2.14.6'

I don't use it but since you use Gradle I'm quite sure you can add it as your own task with dependsOn: 'compileAssets'. Check out example for Android.

Related

Grails 3 and Spring Security Plugin

I've just recently started working with Grails, and I'd like to test out the Spring Security Plugin. I'm using Grails v3.0.0RC2, and I'm finding it difficult to come across accurate documentation for it with a lot of things.
I'm looking at the Grails page for the Spring Security Plugin, located at http://grails.org/plugin/spring-security-core, and it tells me to add the following to grails-app/conf/BuildConfig
plugins {
…
compile ':spring-security-core:2.0-RC4'
…
}
Now, Grails 3 has done away with the BuildConfig, and moved over to using Gradle. So I figured I could just that compile line to my "dependencies" section in build.gradle and it would work, like so:
dependencies{
...
compile:":spring-security-core:2.0-RC4"
}
However, that did not work. I get the error "Could not find :spring-security-core:2.0-RC4...".
Then I figured, 'Hey, it's a plugin, let me try prefacing it with "org.grails.plugins" like I see elsewhere in the build.gradle file:
dependencies{
...
compile:"org.grails.plugins:spring-security-core:2.0-RC4"
}
And still no go.
I have gotten it to compile by adding the dependency found on search.maven.org, like so:
dependencies{
...
compile 'org.springframework.security:spring-security-core:4.0.0.RELEASE'
}
But I don't think thats the proper way to do, because Grails documentation says I should have access to the command
grails s2-quickstart
once the plugin is installed, which I do not when I do it using the Maven repo.
I'm sure there's a simple configuration error I'm making, as I'm very new to both Grails, Spring, and Gradle, so I appreciate any help that can be provided.
The Spring Secuirty core plugin for Grails is not Grails 3 compatible. However, since Grails 3 is based on Spring Boot you can use the Spring Security Starter for Spring Boot instead.
This has been discussed on the Grails developers mailing list and going forward many Grails plugins will not be moved to Grails 3 and instead will be replaced by pure Spring solutions.
Update
Since this question was originally asked there has been a Spring Security plugin created for Grails 3.x. It can be found here: https://bintray.com/grails/plugins/spring-security-core/view
The "Spring Security Starter for Spring Boot" is a good starting point, but if you want to save yourself some time trying to figure out how to get it to work with Grails, check out this helpful blog post.
I wrote the blog post #Jamie referenced in his answer and I added a new blog post describing how to use the Gorm domain classes from Spring-Security-Core plugin from Grails 2.
dependencies {
...
compile 'org.grails.plugins:spring-security-core:3.0.4'
...
}
This is what I used and it worked for me

Grails 3 does not have wrapper?

Does Grails 3.0.x no longer have the ability to create wrappers anymore?
The documentation doesn't seem to have the Grails wrapper section anymore.
Is there an alternative way which we can use the gradle wrapper to execute grails commands such as create-controller?
Does Grails 3.0.x no longer have the ability to create wrappers
anymore?
No.
Is there an alternative way which we can use the gradle wrapper to
execute grails commands such as create-controller?
Not for commands like create-controller, no.
We may re-introduce grailsw. File a feature request at https://github.com/grails/grails-core/issues if you would like to track that.
The Grails wrapper is back as of Grails 3.2.3:
http://docs.grails.org/3.2.x/guide/introduction.html#whatsNewGrailsWrapper
I have an app created with Grails 3.1.x, then upgraded to Grails 3.2.6, but the files such as 'grailsw' did not appear in my project root, and I'm not sure how to get them added via some command in the project.
When I create a new app using Grails 3.2.6, the new files are in the project root (grailsw, grailsw.bat, grails-wrapper.jar). I assume they can be copied over to an app like mine: a quick test of this worked for me.

Grails: Unable to generate views

This is a very basic thing and I have no idea why am not able to do this. I am using Grails 2.3.5
I have a domain class com.trail.AuditTrail and I want it scaffolded views. So, here are the steps I followed:
ran grails create-controller com.trail.AuditTrail, this returned a message saying it generated:
grails-app/controller/trail/AuditTrailController
grails-app/views/auditTrail (just the folder!)
It also created AuditTrailControllerSpec.groovy.
Then I added the line static scaffold = true in the Controller.
Then ran generate-views to create the views, but nothing got created !
IMPORTANT: In fact grails says that there is no command called as generate-views. When I did grails help it didn't list generate-views. So, I thought may be 2.3.5 doesn't have the command and tried generate-all. This too failed. To my surprise, grails help didn't show up generate-all too !
Then I found this bug: https://jira.grails.org/browse/GRAILS-10530. So, I tried clean, refresh-dependencies, compile and then generate-all. But still the same problem.
I thought my local grails setup is messed up. So, asked my colleague. He too sees the same problems.
My problem is I am not able to create the default template GSPs out of the domain.
Scaffolding functionality was extracted from Grails core in 2.3, so you need to install scaffolding plugin for Grails 2.3.5 to be able to use generate-all, generate-views GANT scripts.
P.S. I suggest you to switch to Grails 2.3.6 or 2.3.7. For more details take a look at this article http://www.gopivotal.com/security/cve-2014-0053
for that right click on action then click on generate view

Ruby on Rails equivalent for Maven Archetypes

Maven Archetypes are handy ways to get a project up and going in no time flat. Rails is kinda like an archetype in and of itself. However, I'm curious to know if there are any Rails equivalents for Maven Archetypes.
For example, I want to create an Archetype with full authentication already built in via Authlogic. With Maven Archetypes I would need to build a project with it already ready to go, create my archetype and start working back parameterizing things that should be parameterized. Then anyone can make a Rails project with Authlogic set up by filling out a few questions during the archetype generate command and boom! Fully functional Rails app with Authlogic built in.
Is there a Rails Equivalent? Are Generators expected to do this? Is this just not Rails-y?
I think that rails app templates are the most similar thing to Maven Archetypes. http://railscasts.com/episodes/148-app-templates-in-rails-2-3 is a good starting point to get an opinion about them.
Perhaps you are looking for Modules and Mixins?
I'm not sure but rails casts might have something else to add.

Is it possible to exclude grails plugin from production environment?

I would like to use certain plugin in development environment, but would like to exclude this plugin from production and from generated war. What is the easiest way to accomplish this?
Yes, using plugin scopes. From http://grails.org/1.1+Release+Notes:
Plugins can now be scoped using either the environment or predefined build scopes:
def environments = ['dev', 'test']
def scopes = [excludes:'war']
The plugins will only load in those environments and will not be packaged into the WAR file. This allows "development-only" plugins to not be packaged for production use.
I don't believe that there is a way to achieve this without editing the plugin itself (as Jean pointed out)
If you have control over the plugin then that will work, but if you just wanted to configure this as you were 'using' it, then you will need to copy and run a patched version of the plugin with your modifications. You'd customizing it by utilizing a custom location for that plugin in your grails-app/conf/BuildConfig.groovy file.
If you want to exclude the plugin in certain environment, you need to do this:
runtime (':plugin:version') {
if (Environment.current == Environment.PRODUCTION) {
export = false
}
}
You can use the excludes property in your config.groovy:
production {
grails.plugin.excludes='console,classDiagram'
}
But there seems to be some confusion as to if it will exclude it from both 'run-app' and 'war'. I will try to check today and verify

Resources