Resolving view from webflow when running app with run-web - grails

I have grails app that uses plugins to modularize app. Structure of app is as follows:
pluginA
pluginB
pluginMain
On one of those plugins (say pluginA) I have controller that uses Spring Webflow (using Spring Webflow 2.0.8.1).
Plugins are resolved locally in BuildConfig.groovy of pluginMain (grails.plugin.location.'pluginA' = "../pluginA"
grails.plugin.location.'pluginB' = "../pluginB").
When running app with run-app views used by webflow are resloved OK.
But, when I run app with run-war controller from pluginA tries to resolve view from location pluginMain/WEB-INF/grails-app/views/controllerName/flowName/nameOfView.jsp instead from pluginA
so I am getting HTTP 404 not found error.
I am using grails 2.3.7 and java jdk 1.7.
Please help!

The location that it is looking for in the run-war situation is the standard location for resolving page and flow views. You are likely getting into trouble by attempting to create a war file using inline plugins (the grails.plugin.location).
The inline plugin support is really nice when developing plugin functionality, but it has its quirks, particularly when you get multiple dependent plugins in play. At some point you have to break down and start publishing your plugins.
Try publishing the plugin to your local Maven repository using the "maven-install" command. Then change your BuildConfig.groovy file to reference the installed version of the plugin.
My normal workflow is something like this:
Develop the new plugin functionality using an inline plugin definition in BuildConfig.groovy, testing with run-app and run-test until I'm happy.
Publish a SNAPSHOT version of the plugin (ie. 1.0.1-SNAPSHOT) and update BuildConfig.groovy to point to the snapshot and test using run-app and run-war eg:
compile (":ark-kpi:1.0.1-SNAPSHOT")
Publish your plugin in release form either to your local maven repository (maven-install) or a public repository like a locally running Artifactory if you want to share with colleagues (publish-plugin).
You should read the guide section on plugins and configuration for details on setting up repositories.

Related

Upgrading a plugin fails going from Grails 3.1.11 to 3.2.2

I'm working on a Grails plugin whose main contribution is a taglib. In Grails 3.1.11 it worked ok. I also have a simple Grails app just for testing the plugin. Enter Grails 3.2.2.
After migrating plugin and app to 3.2.2 the plugin shows no signs of life. The plugin doWithApplicationContext closure is no longer executed at app startup. The taglib is not found by gsp:s. I did the migration by creating a new plugin and app with Grails 3.2.2 and then fill in the sources.
Sorry for this vague question, but what strings should I pull to find out what's wrong?
Edit 1: Yes, I did the sanity check to have the app depend on a non-existing version of the plugin and got the expected conflict. So it's not that the plugin is totally decoupled from the app.
Edit 2: After setting DEBUG logging on packages grails.plugins and org.grails.plugins a warning message appeared. It came from org.grails.plugins.CorePluginFinder. It couldn't find the plugin descriptor (...Plugin.groovy). I examined the plugin jar, found the plugin descriptor class in a file hierarchy rooted in BOOT-INF. Clearly the plugin loader didn't look into that hierarchy. I thought I was seeing a Grails bug because I didn't know about Boot repackaging. I added a post here to that effect, but after getting Graeme's answer I deleted the post because it detracted attention.
What you are seeing is that if you run gradle assemble on a plugin then the bootRepackage task is run which re-packages the plugin JAR as a runnable JAR which is not what you want when you plan to use the plugin from an application.
If you simply run gradle publish or gradle publishToMavenLocal or gradle jar then you get the JAR file that has not been re-packaged by Boot. As far as I am aware this is not a change from Grails 3.1.
You can also disable Boot repackaging all together in the plugin build.gradle if you never plan to use the plugin as an actual application or runnable JAR file:
bootRepackage.enabled = false

How to resolve external dependencies defined in a Grails plugin in a Grails 2.2.x application

I asked this question on the Grails user list but didn’t get a response, so I’ll rephrase it here. I’m the author of a Grails plugin (https://github.com/kensiprell/grails-atmosphere-meteor), which has two external dependencies defined in BuildConfig.groovy.
When the plugin is installed in a new Grails 2.2.x application, the external dependencies are not resolved in the app. When running it I get "unable to resolve class" errors on the import statements for the classes defined in the plugin’s dependencies.
A plugin user should be able to insert the plugin dependency in an app’s BuildConfig.groovy and have the two external dependencies resolved automatically. grails.project.dependency.resolution.legacyResolve should be the default value of false.
Additionally, I want to test the plugin using https://github.com/kensiprell/grails-plugin-test-script before publishing it to the Grails plugin portal. I have an artifactory repo running on localhost (defined as localPluginReleases in the plugin's BuildConfig.groovy).
The plugin is built using Grails 2.2.3 and uses release plugin version 2.2.1. I've tried varying combinations of the below without success:
grails clean
grails compile
grails maven-install
grails generate-pom
grails package-plugin
grails publish-plugin --noScm --repository=localPluginReleases
grails maven-deploy --repository=localPluginReleases
What is the correct step-by-step to get this working?

How do I create a Grails skeleton project for plugin development?

I am working with a (sort of) framework built on top of Grails. This framework is a set of Grails plugins that add functionality to the Grails app (e.g. user authentication). This framework is a bit of a pain to setup, as it requires around 64 lines of site specific configuration in the apps's Config.groovy file.
I want to develop my addons to this app as plugins. That is, the Grails app would really just be a set of installed plugins and some configuration files.
I have created a local Maven style repository to hold all of my plugins. Thus, I can add plugin dependencies to the BuildConfig.groovy file and they will be installed automatically (side question: is it possible to specify the install order?).
So my question is, how do I create skeleton project for developing my plugins that would:
Include the base configuration for my application (the aforementioned 64 lines)
Allow me to do a grails package-plugin to package only the plugin's code
You can use the post-installation hooks mechanism: http://grails.org/doc/latest/guide/plugins.html#hookingIntoBuildEvents
Not really an ideal setup for me, but the following works:
Create the "base" application: cd ~/GrailsDev/ && grails create-app my-app
Configure my-app as desired/required
Create your dependent plugin: cd ~/GrailsDev/ && grails create-plugin my-app-plugin
Add the new plugin to the app by editing "~/GrailsDev/my-app/grails-app/conf/BuildConfig.groovy" and appending the line: grails.plugin.location.'my-app-plugin' = "../my-app-plugin"
You can now run the my-app Grails application and the plugin will be included. When your plugin is fully developed, you can do grails package-plugin from within the "~/GrailsDev/my-app-plugin" directory to package your plugin.
use gradle. you can specify the order and package your plugin alone.
e.g. include the required plugins as git modules (for easy versioning) and gradle modules (for building your plugin) in your plugin project.
this setup will serve your requirements well I suppose.
https://github.com/grails/grails-gradle-plugin
IntelliJ does have a template for gradle-backed grails applications and plugins.

How to run a local plugin in Grails 2.0?

In Grails, there is a variant how to include local plugin from sources. According to docs, one may type in BuildConfig.groovy:
// Useful to test plugins you are developing.
grails.plugin.location.shiro =
"/home/dilbert/dev/plugins/grails-shiro"
// Useful for modular applications where all plugins and
// applications are in the same directory.
grails.plugin.location.'grails-ui' = "../grails-grails-ui"
The problem is that it doesn't work in Grails 2.0.RC1. I've tried to do grails clean, to install plugin with grails install-plugin and to place it to BuildConfig.groovy. Still unable to resolve.
This works for me
grails.plugin.location.shiro = "/home/dilbert/dev/plugins/grails-shiro"
Where shiro is the name of the plugin (not the name of the directory it's in). Make sure the path to the plugin is either an absolute path or the relative path to the plugin from the application.
I've found that this sometimes doesn't work if the plugin is listed in application.properties or BuildConfig.groovy, so if it is, remove it, then execute grails clean and restart the app.
You can also install the plugin into your local maven cache.
The documentation speaks about this:
3.7.10 Deploying to a Maven Repository
maven-install
The maven-install command will install the Grails project or plugin artifact into your local Maven cache:
grails maven-install
This has the advantage of allowing you to include the plugin in your parent application using the more common ":plugin-name:version" syntax
Which allows your application to determine the best place to retrieve the plugin when in production. From an internal maven-repo or equivalent.
With Grails 3.x there is another way to do this. Suppose you've a grails app and plugin (source code) inside the same project directory:
/my-project
---/my-app
---/grails-shiro
To run your local plugin, you must create a settings.gradle file in the my-projectdirectory specifying the location of your application and plugin:
include 'my-app', 'grails-shiro'
Then add the dependency in your application's build.gradle:
compile project(':grails-shiro')
You've done.
Look at the plugins documentation for more information.
Surround the plugin name with quotes in case it contains dashes:
grails.plugin.location.'plugin-name-with-dashes' = "<path>"
You can add the .zip file for the plugin in your /lib and it will be installed.
Example:
compile ":myPlugin:1.0"
File:
/lib/myPlugin-1.0.zip
Note: You have to zip the content of the plugin folder.
Source: http://grails.1312388.n4.nabble.com/Insert-own-local-plugin-into-build-config-td4646704.html

Grails dependencies or Maven

I'm using STS latest version (2.7) and latest grails as well. After I created a freshly grails project in STS it freezes in the updating grails dependencies for a long time and it comes out as a timeout error. And it follows by some GroovyObject error, but the project still runs fine in command-line. So I ditched STS for refreshing dependencies, and I included the dependency in BuildConfig.groovy and use grails compile but I still got ClassNotFound error when compiling, it's like grails didn't pick up the Ivy CLASSPATH. So, I'm thinking of changing it to Maven to resolve any dependencies.
My question would be which one is better and integrated seamlessly in STS or Eclipse?, but I still want to use grails commands, not maven.
If your project is just a grails project - use grails dependencies.
I've experience with mavenized grails project, and plain grails project. First is good when you have multimodule project, and only one of them is grails module. At this case you'll lost all grails commands, you need to use commands like mvn grails:run-app and it's complicated thing to pass arguments into commands :(

Resources