Getting Grails version from within plugin _install.groovy script - grails

One of my plugins needs to behave differently for grails 1.x and 2.x. So I would like to switch based on the grails version used to install the plugin, but I didn't find a way to get the grails version...
Any idea?

You can use grails.util.Metadata.current.getGrailsVersion(). Note that you cannot use the property-access variant (grails.util.Metadata.current.grailsVersion) because Metadata is a Map and this will look for the property stored under the key "grailsVersion" and return null since it's stored under "app.grails.version".

To check your grails version:
grails -version
When installing an older plugin, be sure to configure the version in
application.properties
in your grails project.

Related

Where can I find which versions of groovy work with versions of grails?

Searching around Google I can't find any official compatibility matrix of any sort. For example, I'd like to know if I can safely use Grails 2.3.8 on Groovy 2.3.
You should always use whatever version of Groovy is included with Grails. If you look inside the directory where Grails is installed you can discover which version of Groovy this is. Here's an example from my system:
grails/2.3.8/lib/org.codehaus.groovy/groovy-all/jars$ ls
groovy-all-2.1.9-javadoc.jar groovy-all-2.1.9-sources.jar groovy-all-2.1.9.jar
So Groovy 2.1.9 is the version bundled with Grails 2.3.8. This is the only version of Groovy that is recommended for this Grails version.

Identifying Grails plugin using old Hibernate version

Having updated my Grails app from Hibernate 2.2.4 to 2.2.5, I now get the following every time I run 'grails war':
You currently already have a version of the plugin installed [hibernate-2.2.5]. Do you want to update to [hibernate-2.2.4]? [y,n]
I understand that this is probably because of some requirement in a plugin I'm using, and the normal advice is to run 'grails dependency-report'. I've done that but I'm unsure how to interpret the result and take the necessary action to update the dependency. Any input would be appreciated.
My problem seems to have been to do with having Shiro plugin version 1.2.0 installed. When I updated to 1.2.1, the issue with the Hibernate version was resolved.

Were the generate-* commands removed from Grails 2.3.2?

When I type generate-all, generate-controller or generate-vies, Grails current version (2.3.2) does not recognizes them. However, these commands remains on the Grails documentation. Does anyone knows if these commands were removed (and the docs are not up-to-date)?
Try grails compile first.
These commands are now part of the scaffolding plugin, and you might need to get grails to fetch the plugin

install spring-security-core plugin into plugin, which then is installed in application

I've just switched to grails 2.2 and have got a major plugin problem. I've got an application - my-app and a plugin - my-plugin. I want to install spring-security-core plugin into my-plugin, and then install my-plugin into my-app. When I've done this and did s2-quickstart, so that LoginController got created. I can start my-plugin with no problems now, but when I try to start my-app it complains that it cannot find any springsecurity classes. Errors looks like this:
12: unable to resolve class org.springframework.security.web.WebAttributes # line 12, column 1.
7: unable to resolve class org.springframework.security.authentication.AccountExpiredException # line 7, column 1.
11: unable to resolve class org.springframework.security.core.context.SecurityContextHolder # line 11, column 1.
It looks to me, like only my-plugin can see spring security plugin dependencies, and my-app cannot, so they didn't cascade even thought according to manual they should have.
I've also tryed to install spring-security-core plugin by adding in BuildConfig.conf this:
compile ":spring-security-core:1.2.7.3"
but it didn't work either.
Any ideas?
If you use install-plugin in a plugin, it's only installed locally by adding a line in application.properties. It doesn't get exported as a dependency of your plugin. This could be used for plugins like code-coverage where you want to use it during development and testing but not force users to also install it.
In older versions of Grails the dependsOn map in the plugin descriptor was used to express plugin dependencies. This is now deprecated in favor of dependencies registered in the plugins secton of BuildConfig.groovy. This is both for consistency and to take advantage of the more fine-grained features supported by the dependency DSL including specifying scopes and exclusions. This is also true for applications - don't use install-plugin for either apps or plugins, always use BuildConfig.groovy.
Take a look at the spring-security-ldap plugin's BuildConfig.groovy. It has a compile-scope dependency on the core plugin, plus one for the hibernate plugin that's not exported (since it's just for testing) and a build-scope dependency on the release plugin (also not exported since it's just used to release the plugins).
You should probably using a similar dependency on the core plugin in your BuildConfig.groovy. Delete any plugin references in your application.properties and convert to BuildConfig.groovy syntax and run grails clean followed by grails compile.
Thank you Burt for your advice. I've used it and here's what I came to:
I created a plugin-app and installed spring-security-core plugin in it (using DataSource.groovy, and not install plugin). Then I created a main-app and installed my plugin-app (again using DataSource.groovy). When I did this in grails 2.1.1 everything worked just fine - I could use spring-security in my main-app, so the dependency got pulled just right. When I did everything the same, but in grails 2.2 I couldn't use spring-security in my main-app, so dependencies didn't get pulled. That's why I think this might be some kind of a bug in new grails version.

Can you use the Grails Wrapper to upgrade Grails?

I can't find anything in the Grails docs, but from the wording of the description of the Grails Wrapper, it should be possible.
Can you use Grails (via an installed Grails Wrapper) to upgrade the version of Grails a project (and thus the Wrapper) is using? If so, how?
TIA,
g.
I used to just change grails version in application.properties file and run grailsw wrapper to upgrade wrapper. However this doesn't work when upgrading from 2.1.x to 2.2.x anymore.

Resources