Error installing Grails plugin to local maven repository - grails

I have created a Grails plugin using Grails 2.3.3 and trying to use the plugin in a Grails application which was also created using Grails 2.3.3. Now, to use the plugin in the application, it needs to be published to a plugin repository first. So I attempted to publish the plugin into the local repository by using the commands:
grails clean
grails compile
grails maven-install
For the grails maven-install command I selected the option 2)InstallPlugin. But then got an error:
Error installing plugin: No such property: ERROR_MESSAGE for class: Inst
allPlugin (Use --stacktrace to see the full trace)
Ran the last command above with option --stacktrace and --verbose but did not get any clue as to what the problem might be. I also removed %HOME%/.grails directory and reran the above commands and still came with the same error.
After googling, I found a JIRA for this issue which was closed stating that it happens when Grails version is changed and cleaning up cache files will get rid of this issue. However, that solution is not working for me and, by now, I have spent couple of hours trying to fix this. Also I did not change my Grails version.
Has anyone faced this issue with Grails 2.3.3 or with any recent version of Grails? What was the solution?

Don't use install-plugin, add a dependency in BuildConfig.groovy.
I don't know where the 2)InstallPlugin "option" is coming from. The maven-install script packages your plugin and generates a POM file and the other files needed to be a valid published plugins. Then it copies these files to your local M2 directory, e.g. if your plugin name is "mycoolplugin" the files are copied to $HOME/.m2/repository/org/grails/plugins/mycoolplugin
Now you can "install" the plugin as if it had been published in a remote repo. Add a dependency in the app's BuildConfig.groovy using the usual format, e.g.
plugins {
build ":tomcat:7.0.50"
compile ":scaffolding:2.0.1"
runtime ":hibernate:3.6.10.7"
...
compile ":mycoolplugin:0.1"
}

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.

Custom Plugin transitive Dependency resolution in BuildConfig.groovy Grails 2.2.3

tl;dr version
Dependencies of my custom grails plugin weren't getting inherited and resolved by projects I installed the plugin to.
Install the latest version of the release plugin to your plugin (fixes the issue for jar dependencies)
Clear out any references to plugins that might exist in your BuildConfig.groovy file (fixes the issue for plugin dependencies)
grails maven-install to make the plugin available in the mavenLocal() source
Long version
So, I've been trying to create a custom grails plugin for internal use at my University.
I'd really like it if putting the plugin in your BuildConfig.groovy file's plugins closure would automatically install not just the plugin, but all the dependencies defined for the plugin in its BuildConfig.groovy file (or, after packaging, its dependencies.groovy file).
Looking at the instructions, I have setup the BuildConfig.groovy file for my project with this in the repositories closure:
flatDir name:'my-plugin', dirs:'/Users/me/workspace-ggts/myplugin'
Then added this to the plugins closure:
compile(":grails-my-plugin:0.1")
That does install the plugin correctly, but it doesn't resolve any of the plugin's dependencies or needed plugins. Here's the three main closures in the plugin's BuildConfig.groovy file:
repositories {
grailsCentral()
mavenCentral()
mavenRepo "http://www.mygrid.org.uk/maven/repository"
def jbossResolver = new org.apache.ivy.plugins.resolver.URLResolver()
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/com/sun/media/[module]/[revision]/[artifact]-[revision].[ext]")
jbossResolver.addArtifactPattern("https://repository.jboss.org/nexus/content/groups/public-jboss/javax/media/[module]/[revision]/[artifact]-[revision].[ext]")
resolver jbossResolver
}
dependencies {
compile (
[group:'javax.media', name:'jai-core', version:'1.1.3'],
[group:'com.sun.media', name:'jai-codec', version:'1.1.3']
)
compile "net.java.dev.jai-imageio:jai-imageio-core-standalone:1.2-pre-dr-b04-2013-04-23" //this jar comes from the mygrid mavenRepo
}
plugins {
build(":tomcat:$grailsVersion",
":release:1.0.0") {
export = false
}
compile ":spring-security-core:1.2.7.3"
compile ":wslite:0.7.2.0"
}
If I run the plugin using grails run-app, it resolves all of those dependencies just fine. It's only when the plugin is installed to a project that automatic dependency resolution fails.
I've tried making the plugin a maven artifact, and copying it to my local repository. In those cases, I removed the flatDir line from the repositories closure and replaced it with mavenLocal(). Again, the plugin itself installs, but none of the specified dependencies do.
I've tried setting legacyResolve in BuildConfig.groovy to true, but this also fails to install either the jars or the needed plugins (like wslite).
I even tried manually specifying compile(":grails-my-plugin:0.1") {transitive: true}, but it still won't resolve the plugins.
Between all of the above attempts I've uninstalled my plugin, run grails clean on the project, deleted the contents of the ~/.grails/2.2.3/cached-installed-plugins/ directory, and poured libation while intoning the holy name of Burt Beckwith, but I still can't get transitive resolution.
One other noteworthy thing: I've run a dependency-report on the project. It lists my plugin among the dependencies, but the report says that the plugin itself has no dependencies.
I also ran refresh-dependencies myAppDeps.xml in order to get a dependency report. It contains none of the plugin's dependencies that aren't also dependencies of a vanilla grails project.
Grails plugins in the public repositories get their dependencies resolved automagically (try putting spring-security-ldap in your BuildConfig.groovy file as an example, and spring-security-core will install). Does transitive resolution simply not work for local plugins? Are there any ways to make it work, like tacking something into _Install.groovy?
Update
So, I tried dmahapatro's suggestion. That did work for getting the jars on which myPlugin depends installed in the project; thus, the project compiles and the dependency report contains the needed jars. However, the plugins that myPlugin depends on are still not getting installed into the projects that I install myPlugin too. When I try to run the app after a successful compilation, I get this error:
| Error Error: The following plugins failed to load due to missing dependencies: [myPlugin]
- Plugin: myPlugin
- Dependencies:
- springSecurityCore (Required: 1.2 > *, Found: 1.2.7.3)
- jquery (Required: 1.7 > *, Found: 1.8.3)
! wslite (Required: 0.7.2 > *, Found: Not Installed) [INVALID]
Further Update
So, I decided to try to isolate the problem. I created a fresh plugin (grails create-plugin transitiveDep), and a fresh project (grails create-app horseradish). I copied the relevant portions of BuildConfig.groovy from my working projects into each, changing the plugin dependency from my-plugin to transitive-dep.
Lo and behold, horseradish successfully installed all the needed dependencies (wslite, springSecurityCore). It even asked if I wanted to install the older version of jQuery.
So, nothing is wrong with my environment. I suspect at this point that something else is wrong with the plugin's configuration. It was originally written in Grails 2.0.1, then upgraded to 2.2.3. I've also tried installing it into a fresh app, just like I did my transitive-dep plugin, but with it still failed to resolve plugin dependencies. I'll post an update when I've figured out exactly where the issue is.
Final Update
So, the thing keeping the plugins from installing was that myPlugin referenced them in the application.properties file as well as BuildConfig.groovy. If I deleted the references to them there before packaging, the plugin installed just fine.
I also noticed that I still had the old Grails version (2.0) in myPluginGrailsPlugin.groovy file, as well as a dependsOn map that doesn't seem to be needed anymore. I removed/altered those lines, but it wasn't until clearing out the old references in application.properties that things really started working.
Notably, I also had to clear out my ~/.grails/2.2.3, ~/.grails/ivy-cache folders, and ~/.m2/repository/org/grails/plugins/ directories after making changes to myPlugin, or my projects would still try to install the old versions. I got so tired of doing that, I made a shell script to do it:
cd ~/.grails/2.2.3/
rm -r *
cd ~/.grails/ivy-cache/
rm -r *
cd ~/.m2/repository/org/grails/plugins/
rm -r *
Important actions to note and rectify (w.r.t Grails 2.2.3):
Check your application.properties file. There should not be any reference to installed plugins in application.properties. If you had been installing plugins using the install-plugin command (which I discourage now since it will no longer be available), they were likely be written to that file. Delete any lines referencing installed plugins before you do a grails refresh-dependencies and grails maven-install.
Upgrade release plugin inside your plugin to v2.2.1
as below if you are using latest version of grails.
......
build(":tomcat:$grailsVersion",
":release:2.2.1") {
export = false
}
.......
When you do grails maven-install on the plugin, the resultant zip created will be named as grails-my-plugin.zip if the plugin project name is MyPlugin, but when you refer the plugin in your grails application (retrieving from .m2 local repo), you have to refer the plugin as
compile ':my-plugin:0.1' //instead of "grails-my-plugin"
Observation:
I was facing issues (related to svn plugin) using release:1.0.0 (deliberately downgraded to replicate your issue) when testing so it is a better idea to upgrade to version 2.2.1 if you are using Grails 2.2.* etc. You would not be able to use v3.0.0 unless you use Grails 2.3 as mentioned in the doc.
It did not complain anything when I used mygrid repo while testing. [http://www.mygrid.org.uk/maven/repository]
Once my-plugin was added to my application I was able to compile my app where it installed spring security core referred from my-plugin.
Dependency report showed the transitive dependencies as well.
Tested in Grails 2.2.3
on the plugin project run package-plugin. it will generate the dependency file for you. Than you should not get this dependency issue.
I had a similar issue of application not detecting transitive dependencies from plugin.
My plugin's grails version was 2.3.4 and the app that used the plugin was 2.1.0.
The plugin was packaged using grails publish-plugin and manually uploaded to a private Maven compatible repository(Artifactory).
Grails 2.3.4 doesn't generate dependencies.groovy and the app didn't figure out the transitive dependencies and failed compilation.
As #rittinger mentioned in this post custom-plugin-dependencies-groovy-is-ignored pom does the trick. When I manually uploaded the plugin.zip file to Artifactory, it generated a pom file which didn't have a <dependencies/> section.
But when I followed the release plugin instructions and uploaded the plugin to Artifactory, the generated pom file had <dependencies/> section. Afterwards the App didn't have any problems resolving transitive dependencies.

Grails always tries to uninstall plugin

Each time I'm runnin Grails app, it tries to uninstall an plugin (resources-1.2.RC2). When it installed using IntelliJ IDEA, it uninstall it sucessfully, I see:
| Uninstalled plugin [resources]
and fails with:
| Error Fatal error during compilation org.apache.tools.ant.BuildException:
srcdir "***/2.1.1/projects/***/plugins/resources-1.2.RC2/grails-app/resourceMappers"
does not exist! (Use --stacktrace to see the full trace)
Notice, that I can install this plugin only by using InteliJ IDEA, when I'm trying to install it from command line (using grails install-plugin resources) it logs only:
| Plugin not installed.
If plugin isn't installed, and i'm doing grails run-app, it writes (each time!):
| Warning No plugin [resources-1.2.RC2] installed, cannot uninstall
app fails because cannot find required classes from resources plugin.
--
I guess it's happening because of corrupted config inside ~/grails (I've tried to uninstall it some time ago), and it execute this action on each run. But I can find.
I even tried to remove project dir from ~/.grails/2.1.1/projects - not helped.
How I can stop it from removing this plugin? Whre grails stores infomration what plugin it shoud uninstall?
PS Also, I can't understand, why plugins { compile ":resources:1.2.RC2" } in BuildConfig.groovy not used by grails? I always need to run install-plugin command to make it working?
Actually, install-plugin is deprecated. Use BuildConfig.groovy instead. To get everything set up properly, delete all plugins from your application.properties file. Then add them to your BuildConfig.groovy.
IntelliJ is not really good with catching these kind of updates, so you might have to run refresh-dependencies manually after updating your BuildConfig. That is properly why it didn't work before.

Installing Nimble for Grails

I came across Nimble yesterday, but couldn't get past Step 1, configuring BuildConfig.groovy to find the Nimble's remote repository.
My BuildConfig.groovy file is one line:
grails.plugin.repos.discovery.intient="http://intient.com/downloads/grails/
Here is the message I get when running grails install-plugin nimble 0.2:
Welcome to Grails 1.1.1 - http://grails.org/
Licensed under Apache Standard License 2.0
Grails home is set to: /opt/dev/sdks/grails-1.1.1
Base Directory: /home/wraith/dev/source/demo
Running script /opt/dev/sdks/grails-1.1.1/scripts/InstallPlugin.groovy
Environment set to development
No authentication for svn repo at intient ...
Reading remote plugin list ...
Reading remote plugin list ...
Reading remote plugin list ...
Plugin 'nimble' was not found in repository. If it is not stored in a configured repository you will need to install it manually. Type 'grails list-plugins' to find out what plugins are available.
This is the first time I have tried to install a plugin not in the official repository. What is the best way to narrow down if it is a problem at Intient.com or with my configuration?
Follow these instructions with the following modifications:
Step 1 is correct
Instead of using the remote repository, download the zipped plugin
Move the plugin to ~/dev/plugins
grails install-plugin ~/dev/plugins/grails-nimble-0.2.zip
Steps 3-5 are correct
We were performing some maintenance on intient.com and the load balancer wasn't providing this content for the last 12 hours or so (oops!).
Should be sorted now but the steps Wraith Monster gave above work for a manual install as well.
Once Grails 1.2 proper hits Nimble will be part of the official plugin repo and we won't need to worry about this at all.
you could always download the zip file for the plugin and install it manually
Download source code from http://github.com/intient/nimble
Unzip under your plugins directory of your project (usually under ${USER_HOME}/.grails/<grails-version>/projects/<myproject>/plugins)
Rename the extracted folder into "nimble-0.2"
Remove from BuildConfig the line grails.plugin.repos.discovery.intient="http://intient.com/downloads/grails/"
Edit the file application.properties of your project and add the line plugins.nimble=0.2
If not installed under your project, you should install the plugins : shiro (version 1.0-SNAPSHOT at least) and mail (>0.6). (run command grails install-plugin <pluginName> <version>)
Start directly from Step 3
It should work (at least, it worked for me). Good luck

Resources