Cannot see updates on Grails (2.4.3) Plugin - grails

I have a Grails PRJ (2.4.3) with multiple plugin
MAIN PRJ
Plugin A
Plugin B
In Main PRJ the buildConfig.groovy is:
plugins {
// plugins for the build system only
build ":tomcat:7.0.55"
// plugins for the compile step
compile ":scaffolding:2.1.2"
compile ':cache:1.1.7'
compile ":asset-pipeline:1.9.6"
compile ":plugin-a:0.1"
compile ":plugin-b:0.3"
}
After modification on pluginA I execute :
grails clean
grails maven-install
grails mavel-deploy (for remote nexus)
On Main PRJ
grails clean
grails refresh-dependencies
grails run-app
But when the project starts I cannot see the updates on the PluginA. I must increase version in the plugindescriptor. After this I can see the updates!
Now..
Is possibile to avoid the version increase?
What is the best
practice to dev with multiple plugin?
Thanks in advance
Luis

Delete the target directory in your application's root directory instead of running grails clean. Then grails compile will pull in your plugin changes without having to increment the plugin version.

From offical doc:
Configuration Changing dependencies Typically, dependencies are
constant. That is, for a given combination of group, name and version
the jar (or plugin) that it refers to will never change. The Grails
dependency management system uses this fact to cache dependencies in
order to avoid having to download them from the source repository each
time. Sometimes this is not desirable. For example, many developers
use the convention of a snapshot (i.e. a dependency with a version
number ending in “-SNAPSHOTâ€) that can change from time to time
while still retaining the same version number. We call this a
"changing dependency".
Whenever you have a changing dependency, Grails will always check the
remote repository for a new version. More specifically, when a
changing dependency is encountered during dependency resolution its
last modified timestamp in the local cache is compared against the
last modified timestamp in the dependency repositories. If the version
on the remote server is deemed to be newer than the version in the
local cache, the new version will be downloaded and used.
Then if I use ** - ** SNAPSHOT on my lib , every compile and maven-install will give me a updated lib.

Related

Error installing Grails plugin to local maven repository

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"
}

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 make Grails get latest local jars from Maven repository?

In my Maven repo (.m2). there is one my local jar like sub_app-0.1.jar.
I have same copy of the it in ivy-cache.
I run maven install on sub_app then new sub_app-0.1.jar file created.
After, I run grails clean and it not getting my new sub_app-0.1.jar from .m2.
But, if I remove (delete) sub_app-0.1.jar file from ivy-cache and run the grails clean then it is getting new sub_app-0.1.jar file into ivy-cache.
If I change the version in sub-app pom and grails pom and Grails is taking latest one. install again it not taking.
I tried by adding SNAPSHOT to sup-app jar even. Same result, first time it is taking, after not.
ie. Grails considering only jar name and version in ivy-cache, if having - it not take. If not having - it taking from .m2.
But it not considering new/old build.
How can I get the same behavior (step 5) in step 4 also?
UPDATED
You can try adding changing=true to your dependency in the BuildConfig.groovy, as specified in the Grails Guide
compile ('YOUR_GROUP_ID:YOUR_SUB_AP:0.1') {
changing = true
}
Not sure if this is the same problem as you, but I use Spring Source Tool Suite (STS) with a 'grails' project having a dependency on an 'interfaces' project (which just contains interfaces, beans, pojos, etc).
If I run a maven install on interfaces in STS, then maven correctly updated with latest jar (I use '-1.0-SNAPSHOT' as my version number).
If I then run a grails clean on my 'grails' project in STS, Grails correctly identifies the change of the interfaces jar (I have {changing=true} in BuildConfig.groovy), downloads the pom, but fails to download the jar as it cannot delete the jar from the ivy-cache. Looks like STS has a handle on the ivy-cache which prevents this.
As I inherited this project from another developer who informed me it was a bug/feature of Grails and/or STS, I've bowed to his knowledge and workaround this by either:
maven package instead of install on 'interfaces' then copy the latest jar to the ivy-cache. It seems STS will let me replace the contents of the jar. Then grails clean uses the latest jar from ivy-cache (no attempt to download from maven).
maven install on 'interfaces', close down STS, delete jar from ivy-cache, re-open STS, grails clean which downloads latest jar from maven.
Both workarounds as a pain, so I'd be interested if anyone has any ideas?
Grails not supports to get latest of same (group-id, artifact-id, version) jar even SNAPSHOT jar also.
Solutions:
Every-time, delete the sub-app-version.jar from ivy-cache. or
Every-time, change the version to next value(should be greater than current value) of the sub-app jar in pom.xml.
4 Configuration - Reference Documentation
Please read:
4.7.6 Snapshots and Other Changing Dependencies

Grails wants to downgrade my plugins when I copy my app to a new machine

When I copy my app to a different machine and do 'grails run-app' grails seems to skip a step as far as updating its local plugins. (What I mean is the first computer has just done Downloading: plugins-list.xml, but when I run the app on the second machine, the new machine will not do that step.) I get this message:
Loading Grails 2.0.3
Configuring classpath
Environment set to development.....
Packaging Grails application
You currently already have a version of the plugin installed [resources-1.1.6]. Do you want to update to [resources-1.1.5]? [y,n] n
Plugin resources-1.1.5 install aborted
Compiling 92 source files
Am I diagnosing this correctly, and how do I force an update? Also, if I do accept the downgrade my app breaks. Not sure whats up with that as it was working with 1.1.5 for a while..
What I feel like is happening is that grails makes a note in the project when grails' plugin magic was last updated, so that when I move the project the other grails mistakenly thinks it just updated. Is this at all correct?
Are you specifying your plugins in your BuildConfig.groovy file or are you "installing" the plugins using the install-plugin command? My reading indicates usage of the install-plugin command isn't recommended anymore, you should instead specify the plugin as in your BuildConfig.groovy file then Grails will just handle it regardless of what machine you deploy on.
Example:
plugins {
/*
* build - dependency that is only needed by the build process
* compile - dependency that is needed at both compile-time and runtime. This is the most common case
* provided - dependency that is needed at compile-time but should not be packaged with the app (usually because it is provided by the container). An example is the Servlet API
* runtime - dependency that is needed to run the application, but not compile it e.g. JDBC implementation for specific database vendor. This would not typically be needed at compile-time because code depends only the JDBC API, rather than a specific implementation thereof
* test - dependency that is only needed by the tests
*/
runtime ":cached-resources:1.0"
runtime ":database-migration:1.1"
runtime ":hibernate:$grailsVersion"
runtime ":jquery:1.7.1"
runtime ":resources:1.1.6"
runtime ":yui-minify-resources:0.1.4"
runtime ":zipped-resources:1.0"
compile ":cache-headers:1.1.5"
compile ":commentable:0.8.1"
compile ":jquery-ui:1.8.15"
compile ":joda-time:1.4"
compile ":searchable:0.6.3"
compile ":spring-security-ldap:1.0.6" // Also installs spring-security-core
build ":tomcat:$grailsVersion"
}
Note too that some plugins also require a special entry in the dependencies section of your BuildConfig.groovy file. The JodaTime plugin is one such plugin.
dependencies {
compile "org.jadira.usertype:usertype.jodatime:1.9"
}
A plugin's docs should specify if any entry in the dependencies section is needed.

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

Resources