install plugins manually? - grails

is it possible to install and uninstall plugins manually in grails??
if yes, how can it be done?

If the commands are failing for some reason, you can remove them by:
delete the entry for the plugin from application.properties
delete the plugin folder from ~/.grails/grails version/projects/project name/plugins

(Grails 2.2.4) To add a plugin that exists for example in your grails-project-dir\lib\the-grails-plugin-0.1.zip directory. Edit your grails-project-dir\grails-app\BuildConfig.groovy to include the following
plugins {
// ....
compile "lib:the-grails-plugin:0.1"
}
This will update your ivy-cache with folder called lib\the-grails-plugin
e.g: [user-home]\.grails\ivy-cache\lib\the-grails-plugin

For Grails 2.x, that's what the
grails install-plugin <plugin>
and
grails uninstall-plugin <plugin>
commands are for. See the command line reference at http://www.grails.org/doc/latest/.

Well, I know this is an old question, but it's probably a good idea to say here that since Grails 2.0, the best way to install a plugin is to update BuildConfig.groovy, adding it in the plugins section:
plugins {
// ....
compile ":console:1.2"
}
The scripts for installing/uninstalling plugins are deprecated and will likely be removed because they have issues regarding scopes and transitive dependencies.
If you want to install a plugin that is not in the central repositories, you can install the plugin in your Maven cache with grails install and then you'll be able to use it in your applications the same way.

Related

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

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.

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.

I can't install spring-security-core plugin in Grails

I have windows 7 and Grails-2.0.4. Trying to install plugin spring-security-core. I've tried from everywhere: cmd, Idea, SPS. Nothing works. Everywhere the same error:
!Error resolving plugin [name: spring-security-core, group: org.grails.plugins, version: latest.integration(1.2.7.3 in SPS)]. Plugin not found.
!Error Plugin not found for name [spring-security-core] and version[not specified(1.2.7.3 in SPS)]
I tried to put the zip-file of this plugin in different directories. Doesn't work. With connection everything is OK. Help me please.
Check the repositories section of your BuildConfig dependencies, and add the following if it is not already there:
grailsRepo "http://grails.org/plugins"
The grails plugin repository moved earlier this year and the old repository does not contain any plugin versions released since April 2012. I don't remember exactly which versions of Grails will use the new repository by default, the change happened somewhere around 2.0.3/4.
The preferred way to install it is to add a dependency in BuildConfig.groovy. The syntax for this is listed for each plugin, in this case from http://grails.org/plugin/spring-security-core: compile":spring-security-core:1.2.7.3"(look for the 'Dependency' section at the top). So theplugins` section of your BuildConfig.groovy should look like this:
plugins {
runtime ":hibernate:$grailsVersion"
build ":tomcat:$grailsVersion"
...
compile ":spring-security-core:1.2.7.3"
}
Alternatively you can install it with the install-plugin script:
$ grails install-plugin spring-security-core
but the dependency approach is the better way.

Resources