Adding in-place plugin to grails 3 project - grails

In grails 2.x, we were allowed to add an in place plugin by adding following in BuildConfig.groovy
grails.plugin.location."my-plugin" = "../my-plugin"
My question is, can we add our local plugins similarly in-place in grails3.0 as well or there is some other way to do this in grails.
Actual purpose is to test the plugin whether it's working properly or not before pushing it to bintray.

Yes, there is. Grails 3 is based on Gradle so multi-project gradle builds solve your issue.
Basically you add dependency as:
compile project(':../my-custom-plugin')
and has to modify settings.gradle to include plugin:
include '../my-custom-plugin'
Check Grails documentation on Plugins and Multi-Project Builds in http://grails.github.io/grails-doc/latest/guide/plugins.html
Other way is to install plugin in local maven repository using gradle publishToMavenLocal command and resolve if from there, before publishing to Bintray or other dependency repository.
Additionally since Grails 3.1.1, reloading is now supported for 'inline' plugins. Check https://github.com/grails/grails-core/releases/tag/v3.1.1 and http://grails.io/post/138665751278/grails-3-gradle-multi-project-builds
It is done using grails { plugins { syntax. Copied from docs:
grails {
plugins {
compile ":hibernate"
compile project(':myplugin')
}
}

This multi-project thing is a bit too big to answer in a short post. I just recently started with it, but, thankfully, I now have the hang of it. There's a tutorial on my site with a plugin handling the domain classes and services and all other sub-projects (just one, a web application in this example) using the plugin. The code is also downloadable. Here's the link: http://www.databaseapplications.com.au/grails-multi-app.jsp Make no mistake, there are a few things to watch out for.

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 generate zip file for a grails plugin

I wrote a Grails plugin, lets say PluginA which has dependency on another plugin, lets say PluginB, which I wrote myself too, these both plugins are being used by a main project. I am trying to build a continious integration system for this project using jenkins, so far I managed to setup everything in Jenkins. But while building the project, I get this error
Zip C:\Users\me\project\PluginA\grails-PluginA-0.1.zip is not a valid plugin
So, how do I generate that zip file, I noticed that all my other plugins have that zip file but I don't remember building them. I also tried to do a grails compile-plugin but I got an error saying that few classes were not found as they were in PluginB. So, how can I specify that PluginA has dependency on PluginB while running a grails command?
It's not entirely clear, but I believe the problem you are having occurs when trying to build the main project and not the plugins, so I will address that situation.
Since the error message mentions a zip file, I will also assume you are using Grails 2.x. If you are using Grails 3.x, then stop reading now and add info on how you are specifying your dependencies.
Key info: In my experience plugins don't come with their dependencies; I've had to re-declare them in my top-level projects. I have no idea if that is the intent of the grails plugin design, but I have found it works to do so.
Step 1: Build PluginB and install it to your local maven repo using
grails maven-install
Step 2: Specify PluginB as a dependency for PluginA in its app/conf/BuildConfig.groovy
Step 3: Build PluginA and install it to your local maven repo using the same command as for PluginB.
Step 4: In your main project, specify dependencies on BOTH PluginA and PluginB in app/conf/BuildConfig.groovy
Step 4 is the key.
If I've misinterpreted your problem, sorry about that! Please provide some more detail on exactly which part is failing and I'll let you know if I have any info on it.

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

What are inline plugins?

What is an inline plugin in Grails 2.X? How to make a plugin inline? I can find the documentation for Grails 3 but not for Grails 2.
Inline plugins in Grails 2.x are outlined in the documentation section for plugins.
From the documentation:
An application can load plugins from anywhere on the file system, even
if they have not been installed. Specify the location of the
(unpacked) plugin in the application's
grails-app/conf/BuildConfig.groovy file
Creating an inline plugin is done using the grails create-plugin command, just like a non-inline plugin.
The only real difference between an inline-plugin and regular plugin is how it is referenced by your application. A normal plugin is pulled from a repository (such as maven) while an inline-plugin exists in source format local to the application that is using it. Take for example:
/usr/foo/grails/MyApplication
/usr/foo/grails/MyInlinePlugin
/usr/foo/grails/MyOtherInlinePlugin
The above application (MyApplication) can include the two plugins listed as inline plugins by using the following in the BuildConfig.groovy
// BuildConfig.groovy
grails.plugin.location.'my-inline-plugin' = "../MyInlinePlugin"
grails.plugin.location.'my-other-inline-plugin' = "../MyOtherInlinePlugin"
Overall inline plugins are useful when developing (or testing) a plugin as well as creating modular Grails applications.
You can find the documentation in this URL: Grails Documentation
Go to the section: User guide for older versions
And select your version of Grails.
Here you can find, for example, the documentation of Grails 2.5.0: Grails Documentation 2.5.0
The inline plugins can help you to debug an application or change the code of your plugins to do your tests, instead of apply the changes in the plugin and when it's released, test if it's OK. It's very useful to change different plugins in the same time.
Hope this helps!

Grails Plugin Maven Integration

I'm trying to create Mavenized Grails application. Everything works fine but as I understood all the dependencies (all .jars like mysql-connector and also all grails (public) plugins like spring-security-core plugin) should be listed in pom.xml.
The thing is that I don't know how to include public grails plugins (is there any Maven repository for that, or should I include used plugins into my local repo?). Or is the proper way how to handle grails plugin to list them in "application.properties" and let the grails to manage these plugins?
Thank you for any comment.:-)
Mateo
You can specify your plugin dependencies in grails-app/conf/BuildConfig.groovy, for example:
grails.project.dependency.resolution = {
plugins {
runtime ':hibernate:1.2.1'
}
}
Update
In response to your comments below, a plugin dependency specified in BuildConfig.groovy (or application.properties) will still be resolved by Grails rather than Maven. I don't think there's any way that you can get Maven to resolve a Grails plugin dependency, because Maven can only work with JAR dependencies in Maven repositories. Remember, Grails plugins are not (typically) available from Maven repositories.
If you want to hand as much control as possible over to Maven, you can try excluding the JARs from your plugin dependencies, e.g.
plugins {
runtime( "org.grails.plugins:hibernate:1.2.1" ) {
excludes "javassist"
}
}
and add them to your pom.xml instead. Here be dragons (see below).
Editorializing
FWIW, unless you really have to build your Grails project with Maven (e.g. because another Maven project depends on it), my advice would be don't. I say this because Maven is very much a second-class citizen in the world of Grails build tools. The usual way to build a Grails app is using the built-in GAnt commands. Future versions of Grails will move towards Gradle as the default build tool, so it seems that Maven will be an afterthought for the forseeable future
By default, Grails plugins are included at the source level. A plugin zip is expanded, and the plugin source is compiled as part of the grails build process.
Since 2.0, grails can use binary plugins. You can depend on plain old JARS if those jars represent binary grails plugins.
Binary grails plugins can be referenced by normal maven coordinates.
Your project's BuildConfig.groovy is where you specify maven repositories and binary plugins.

Resources