Grails 3.0.10 can't resolve MockFor - grails

I'm trying to port an existing Grails 2.2 plugin to Grails 3.0. As such, I would prefer to avoid rewriting its unit tests, which use MockFor
Having created a new 3.0.10 plugin with grails create-plugin, and copied the source files into the appropriate new locations, when I run grails test-app I get:
{path}/FooControllerTests.groovy: 4: unable to resolve class groovy.mock.interceptor.MockFor
# line 4, column 1.
import groovy.mock.interceptor.MockFor
^
I haven't yet done anything to build.gradle.
$ grails --version
| Grails Version: 3.0.10
| Groovy Version: 2.4.5
| JVM Version: 1.7.0_91
... the Groovy 2.4.5 API docs show groovy.mock.interceptor.MockFor should be present: http://docs.groovy-lang.org/2.4.5/html/gapi/index.html?groovy/mock/interceptor/MockFor
What am I missing?
EDIT:
Modifying gradle.properties and changing grailsVersion to 3.0.9 seems to work (regardless of whether I tell SDK to use 3.0.9 or 3.0.10).

I had a similar problem. A plugin was pulling in a older version of Groovy (2.3.X). I had to find it and exclude the groovy required by that plugin.
My build.gradle file now has this:
compile("org.gebish:geb-junit4:0.10.0") {
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
}
I found this with the gradle dependencies command. I looked for the groovy-all entries and found the plugin that forced an older version of groovy.

Related

How to install grails db-reverse-engineer

Trying to use the Grails db-reverse-engineer plugin. As this plugin doesn't work with Grails 3 I used SDKMAN to install older versions of Grails just to generate the models. First tried version 2.5.2 (which was still incompatible with the tutorial) and then spun back to 2.2.5. Following the tutorial still fails to install the plugin:
$grails create-app reveng-test
| Created Grails Application at /home/user/pnvStuff/grails/reveng-test
$ cd reveng-test
$ grails install-plugin db-reverse-engineer
| Environment set to development.....
| Warning The install-plugin command is deprecated and may be removed from a future version of Grails. Plugin dependencies should be expressed in grails-app/conf/BuildConfig.groovy. See http://grails.org/doc/2.2.x/guide/conf.html#pluginDependencies.
| Error resolving plugin [name:db-reverse-engineer, group:org.grails.plugins, version:latest.integration]. Plugin not found.
| Error Plugin not found for name [db-reverse-engineer] and version [not specified]
I also tried installing the plugin by referencing it in the plugins section of the BuildConfig.groovy.
runtime ':db-reverse-engineer:0.5.1'
How can I get this plugin installed to generate the needed domain classes?
Grails 2.x (and 1.x for that matter) plugins are now in a repository that isn't included in BuildConfig.groovy by default. You need to add the below Maven repo to your dependency resolution block.
grails.project.dependency.resolution = {
repositories {
mavenRepo "http://repo.grails.org/grails/repo/"
...

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.

Grails Standalone Plugin Not Found

I'm trying to use the grails standalone plugin with a new grails project but I can't get it to work.
I've added it as a plugin dependency in my BuildConfig.groovy file:
plugins {
compile: ":standalone:1.2.3"
}
But I get the following error when I attempt to run grails prod build-standalone:
Script 'BuildStandalone' not found, did you mean:
1) InstallDependency
2) Stats
3) InstallJQuery
4) CreateMultiProjectBuild_
5) TestApp
I tried running grails clean, grails clean-all, grails refresh-dependencies, and grails compile as answered in this question, but nothing seems to help. I would expect refresh-dependencies to either download the necessary artifacts or fail trying.
What am I doing wrong?
Here is my environment:
Mac OS X 10.9.5
JDK 1.8.0_05
Grails v2.4.4 installed with GVM
Always run grails compile after editing dependencies in BuildConfig.groovy; this triggers dependency resolution and installs the plugin, downloads the jars and adds them to the classpath etc. Once that happens the plugins' scripts will resolve.

Cannot install Grails plugin with Eclipse (Grails 2.3.1)

i have Grails 2.3.1.
when i try to install new plugins , i have the following console message :
Since Grails 2.3, it is no longer possible to install plugins using the install-plugin command.
Plugins must be declared in the grails-app/conf/BuildConfig.groovy file.
Example:
grails.project.dependency.resolution = {
...
plugins {
compile ":console:1.2"
}
}
Since Grails 2.3, it is no longer possible to install plugins using the install-plugin command.
Plugins must be declared in the grails-app/conf/BuildConfig.groovy file.
Instead of using install-plugin (or an IDE feature like you're using that runs install-plugin for you), add a dependency in the plugins section in BuildConfig.groovy:
plugins {
compile ":console:1.2"
}
install-plugin adds entries in application.properties but that approach isn't configurable enough, so we deprecated install-plugin in 2.2 and removed it in 2.3. As you can see, when you run the script, it does nothing but does give you the code that you need to add yourself.

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.

Resources