Can you use the Grails Wrapper to upgrade Grails? - 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.

Related

Grails 3.3.x with gradle 4.x does not work?

Grails 3.3.0 does not work with gradle 4.x is that right?
I have problems running intergation test (dependency injection does not work) when running them with gradle via integrationTest or build task.
BTW: Why isn't there a grails-3.0 tag?
Grails 3.3.0 does not work with gradle 4.x is that right?
It really depends on what you are doing, but there have been issues identified. https://github.com/grails/grails-core/issues/10713

How do I configure installation of plugins in Grails 3.0.4?

I'm porting an application from Grails 2.4.2 to Grails 3.0.4, and I'm having problems with some plugins that were installed previously. Specifically one that is referenced in a GSP page. The particular plugin is called google-visualizer, and I've found some info here:
https://github.com/bmuschko/grails-google-visualization/blob/master/grails-app/views/formatter/index.gsp
However, I am clueless as to how to install this. I have not found the particular jar file in any maven repo, so I can't add it as a Gradle dependency. In general, where is it documented how to install existing plugins in Grails 3.X? I've read the documentation on how to port existing plugins, but that's not what I'm trying to do. I simply want to tell Grails/Gradle that I'd like to use this particular plugin and have it resolve the dependencies for me. I've tried this syntax as shown here:
https://grails.org/plugins/tag/grails3
Example:
compile ":quartz:1.0.2"
I've put that line in the dependencies block in my build.gradle file, but it doesn't work. I get errors from Gradle. Is there a particular Maven repo that has to be added for plugins? Any help with this is appreciated. Thanks.
Grails 1.x and 2.x plugins are sadly not compatible with Grails 3.x.
You can find the plugins that already have been ported to Grails 3 at: https://bintray.com/grails/plugins/
The grails-google-visualization plugin is not released in a Grails 3 version, but from the repo, it appears that work has started on upgrading.
You can see the progress on a Grails 3 version in this issue: https://github.com/bmuschko/grails-google-visualization/issues/49
Benjamin searched for a new maintainer back some time ago, and found a volunteer - see this tread for details: https://twitter.com/bmuschko/status/498610606896066560
For those plugins that are most important, the Grails Core team maintains a list here: https://github.com/grails/grails-core/wiki/Grails-3-Priority-Upgrade-Plugins
Some of the old plugins will be replaced by their Gradle counterpart, fx. the codenarc plugin, that exist in a Gradle version already.
A simple way is to find out the JAR file for the plugin and then use them in Grails 3.0.4. In this way there is no need to change the source code of the plugin

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.

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.

Getting Grails version from within plugin _install.groovy script

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.

Resources