Grails Fixture plugin keeps saying build-test-data plugin is not installed - grails

I have the following dependency declaration in BuildConfig.groovy:
plugins {
test ':build-test-data:2.2.1'
test ':fixtures:1.3'
}
I've already run refresh-dependencies on both the terminal, and my IDE (Eclipse) but every time I run the test I get:
grails.plugin.fixtures.exception.FixtureException: build feature is unavailable as build-test-data plugin is not installed
at grails.plugin.fixtures.builder.FixtureBuilder.assertBuildTestDataPluginInstalledIfNeeded(FixtureBuilder.groovy:135)
at grails.plugin.fixtures.builder.FixtureBuilder.beans(FixtureBuilder.groovy:104)
at grails.plugin.fixtures.builder.FixtureBuilder.build(FixtureBuilder.groovy:82)
at grails.plugin.fixtures.Fixture.build(Fixture.groovy:48)
at grails.plugin.fixtures.FixtureLoader.build(FixtureLoader.groovy:54)
I checked the FixtureBuilder code, and found the following line:
Holders.pluginManager.hasGrailsPlugin('build-test-data')
I created a separate test to check what this line returns, but no matter what plugin (declared in BuildConfig.groovy) I replace 'build-test-data' with, it always returns false.
How do I fix this?

In BuildConfig there are four possible options to configure a plugin:
build
compile
runtime
test
Fixture and Build plugins are configured to be use in test you should to change it to runtime to use them in BootStrap when running the app.

Related

How to run Spock unit tests without intializing Grails environment

I have a Spock unit test in a Grails app. In IntelliJ IDEa I can either run it with grails environment and then it means I wait a minute until the environment loads to run the test even though I do not need the environment.
The other option is to run it with JUnit. This works nicely in a Grails app without my own plugins. However, when I run it in a Grails app that has a plugin of another Grails app I have, it crashes on NoClassFound. It does not see the classes from the plugin that I included.
When I checked in IDEa the project structure, indeed the sources nowhere include a folder where the plugin classes would be included. For some reason the plugins in plugins section in BuildConfig.groovy do not appear in the classpath anywhere, they are not found in the external libraries section or anywhere else.
Is there a way to tell grails not to spin up its environment when running some of my tests? Or how can I include my plugin in the classpath for Groovyc to see it when building for testing?
The problem occurs also when simply pressing Build Project in IntelliJ IDEa. The project we are working with is simply run with grails and is never built (beyond how grails builds it). When you try to build it in IDEa, it fails on NoClassDefFound of plugin class.
Versions:
IntelliJ IDEa 2021.2
Grails 2.5.6
EDIT: Ok, it seems like grails apps are to be tested via their command-linke with grails test-app. When Grails runs in interactive mode, test-app won't have to reinitialize the environment, cause it's already running, so it runs faster.
However, as I found here Slow Grails test starting in Intellij IDEA it seems like there's no way to run grails in interactive mode from within IDEa in a way that would enable IDEa test runs to use such interactive console. Which means I'm forced to run tests via command-line. Not happy.
Edit 2: At some point in time I have managed to get the compiled tested.class to the out folder. This enabled running the test instantly via IDEa circumventing the Grails glory. However, I have no idea how I got it to out folder and after removing it I am unable to compile it again and get it there.

How to declare dependency scope for a local plugin?

I want to install my-plugin.zip with a certain dependency. How can I do this?
This doesn't seem to work inside BuildConfig.groovy:
runtime '/path/to/my/plugin.zip'
If the plugin is already packaged as zip then it can be referred as any other Grails plugin in BuildConfig.groovy. You just need to keep note of 2 things:
Plugin Name [Generally MyPlugin app would have plugin name as my-plugin]
Plugin Version
Then BuildConfig would look like:-
//BuildConfig.groovy
plugins{
runtime ':my-plugin:0.1'
//compile ':my-plugin:0.1'
}
When plugin is packaged it will be available in cached-installed-plugins inside $Userhome/.grails/<version> by default. Also, by default the group is org.grails.plugins. In order to test for compile, build and/or test configurations, try to change as above and run a dependency-report to see the plugin available in corressponding configurations.
Alternative:
There is another "soon-to-be-deprecated" approach to install your plugin.
grails install-plugin <path/to/YourPlugin.zip>
will install the plugin in the application in default, compile, runtime configurations. I would not suggest this approach as install-plugin is going to be deprecated.

Creating and installing a grails plugin - how does my plugin access resources from a plugin its dependent upon during/after install?

This question is an extension from another question I posted here:
In Grails 2, how do you includeTargets from Gant scripts from a plugin your app is dependent upon?
I am writing a grails plugin that is a my-company specific version of the shiro plugin, ex. my-company-shiro. I set shiro as a dependency for my plugin in the BuildConfig.groovy like so:
plugins {compile(":shiro:1.1.4")}
I package the plugin and try to install it to a new grails app called foo:
foo> grails install-plugin ../my-company-shiro/grails-my-company-shiro-01.zip
No problems.
Now, I want to run a script in foo that is part of my-company-shiro which in turn references a script from the shiro plugin:
foo>grails create-auth-controller
I get the following failure:
Error Error executing script CreateAuthController: No such property: shiroPluginDir for class: .....
This occurrs b/c one of my scripts being executed tries to access one of shiro's scripts like so:
includeTargets << new File (shiroPluginDir, "/scripts/_ShiroInternal.groovy")
This reference works when I compile my plugin, but not here when I am installing it in another grails app.
Am I setting the dependency incorrectly in the BuildConfig.groovy such that shiro's files are not being included in my plugin therefor I cannot reference it?
The shiro plugin shows up in my .grails cache my-compnay-shiro/plugins/shiro-1.1.4
When I install my-company-shiro plugin to foo, in the .grails cache foo/plugins/my-company-shiro-0.1/dependencies.groovy and plugin.xml files reference shiro. I do not see any of shiro's scripts or files here, but I have no idea if they are supposed to be copied here.
Is the reference to shiroPlugin incorrect at install time?
Thanks in advance!
grails install-plugin is deprecated, you need to use BuildConfig.groovy instead. I tested here, declaring the custom plugin inside the app and it works, you can use grails.plugin.location to specify the folder of your plugin.
Considering a plugin named shiro-test, the BuildConfig should be:
grails.project.dependency.resolution = {
...
legacyResolve true // whether to do a secondary resolve on plugin installation, not advised and here for backwards compatibility
...
}
grails.plugin.location."shiro-test" = "path/to/plugin"
Then you refresh your dependencies and can run any script from shiro-test.

How to make dependencies of an inline plugin available during run-app in grails 2.1?

I've modified my app to be a grails plugin, which I'm going to include in client-specific applications and customize some bits and pieces.
To test the whole thing, I've included the plugin as inline in the BuildConfig of a test application [bare application created using grails commandline].
grails.plugin.location."engine-plugin"="../../engine-plugin"
I did not install the plugin itself, I did not add a thing into plugins part of the BuildConfig in my app.
Now, in the BuildConfig of the plugin, I've included all of the plugins I require in my engine:
compile (
":asynchronous-mail:0.6",
":famfamfam:1.0.1",
":google-visualization:0.5.3",
":gsp-arse:1.3",
":jquery:1.8.0",
":jquery-ui:1.8.15",
":mail:1.0",
":navigation:1.3.2",
":prototype:1.0",
":quartz2:0.2.3",
":rendering:0.4.3",
":spring-security-core:1.2.7.3",
":spring-security-ui:0.2"
)
Unfortunately, when I run grails run-app in my test app, it can't resolve some classes:
4: unable to resolve class grails.plugins.springsecurity.Secured
# line 4, column 1.
import grails.plugins.springsecurity.Secured
^
Obviously, that's because my app can't see the spring-security-core or it's dependencies.
I've tried changing the scope in my plugin's BuildConfig from compile to build, but that changes nothing. I've tried adding export=true to it - nothing.
Any tips on how to proceed with this?
Thanks
EDIT:
getting the same error when using the packaged plugin instead of inline :/

Grails Inline Plugins: Cannot Upgrade a plugin that is configured via BuildConfig.groovy

Our app is split into a main application and a few plugins. We're using inline plugins via the BuildConfig.groovy file. When it is time to WAR the whole thing up for production I'm getting the following message:
You cannot upgrade a plugin that is
configured via BuildConfig.groovy,
remove the configuration to continue.
And then Grails wants to uninstall the plugin because it can't find it in application.properties. But during development, having it in application.properties causes issues. So when we're ready to create a production WAR, how do we work around this without commenting the plugins in BuildConfig.groovy every time?
BuildConfig.groovy is read rather early in the run process, so not all of environment data is yet available. However, it is interpreted as a regular groovy script, so you could try taking advantage of the fact that the war task is run in production environment:
// BuildConfig.groovy
if (System.getProperty("grails.env") == "development") {
// specify the inplace plugin normally here
}

Resources