I am trying to upgrade my application from Grails 2.4.4 to Grails 3.2.0. I am having problems installing plugins used in previous version. Following Questions did gave me some clarification :
1) First one
2) Second one
Now I have few plugins like tomcat, jquery,etc which are not available at https://bintray.com/grails/plugins as described in First one question.
So can you tell me how do I add plugins which are not in this directory on plugins at bintray.
There is some problem as well I am using database-migration plugin. There is listing available at bintray and says to use it as
compile 'org.grails.plugins:database-migration:3.0.0'
as I added same in build.gradle file in my project under dependencies section. Project gets compiled successfully but does not run. Shows long exception but starting is as follows :
org.gradle.api.tasks.TaskExecutionException: Execution failed for task
':bootRun'.
Please help to resolve this errors while installing plugin in Grails 3.2.0
You need an extra configuration for that plugin as its doc says.
Add in build.gradle
buildscript {
dependencies {
...
classpath 'org.grails.plugins:database-migration:3.0.0'
}
}
dependencies {
...
compile 'org.grails.plugins:database-migration:3.0.0'
}
It is also recommended to add a direct dependency to liquibase because Spring Boot overrides the one provided by this plugin
dependencies {
...
compile 'org.liquibase:liquibase-core:3.5.3'
}
You should also tell Gradle about the migrations folder
sourceSets {
main {
resources {
srcDir 'grails-app/migrations'
}
}
}
Maybe plugins are no longer necessary and don't have direct replacements. The tomcat plugin is not needed because Grails 3 is built on Spring Boot and the dependency:
compile "org.springframework.boot:spring-boot-starter-tomcat"
Provides tomcat already. The jQuery plugin is not needed either because you can simply declare a dependency on the jquery.js file directly using asset pipeline which is just as simple. See How to Use jQuery in Grails 3.0
I have created a plugin which has other plugins as plugin dependencies in BuildConfig.groovy:
grails.project.dependency.resolution = {
....
plugins {
build(":release:3.0.0",
":rest-client-builder:1.0.3") {
export = false
}
// my dependencies
compile ':spring-security-core:1.2.7.2'
compile ":spring-security-ldap:1.0.6"
}
}
How can I make sure that when someone installs my plugin they don't have to install spring-security-core and spring-security-ldap manually? I want dependency management to do it for them.
Grails 2.3.0
You've already configured it correctly. The release and rest-client-builder builder plugins won't be installed because they're correctly configured to not be exported, but the security plugins are exported since all dependencies are exported by default.
You can see this by running grails generate-pom and viewing the generated pom.xml file. The jar and plugin dependencies are in the <dependencies> block, and there should be entries in <dependency> blocks for the "org.grails.plugins" groupId for any transitive plugin dependencies.
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.
I have a plugin project which I created as grails create-plugin myPlugin. I also created a 'normal' grails project as grails create-app myPluginDemo. I'm trying to install myPlugin plugin in myPluginDemo but don't understand how to use grails.plugin.location.
Where do I put grails.plugin.location inside BuildConfig.groovy? Inside plugins section? Inside repositories section?
What should I append to grails.plugin.location? Should it be grails.plugin.location.myPlugin? Or grails.plugin.location.grails-my-plugin? Something else?
grails.plugin.location is not a dependency resolution, so it goes outside grails.project.dependency.resolution.
It should be like below, if both myPluginDemo and myPlugin are in the same directory. Moreover, this will not install the plugin into the app, but the application will refer to the file system for the plugin which is convenient in development mode. In order to use the packaged plugin it has to be referred in plugins inside grails.project.dependency.resolution
grails.plugin.location.myPlugin = "../myPlugin"
grails.project.dependency.resolution = {
repositories {
}
dependencies {
}
plugins {
}
}
When using the grails plugin dsl in BuildConfig.groovy, such as
plugins {
build "org.grails.plugins:db-util:0.4"
}
Is there a way to specify to use a plugin from a zip file like you can do with grails install-plugin?
Not directly, but of you put the zip file in a directory and name it without the grails- prefix, then declare that directory as a flatDir repository then Grails will be able to resolve the plugin from there.
repositories {
flatDir name:'localPlugins', dirs:'../local-plugins'
}
// copy plugin zip to ../local-plugins/my-plugin-1.2.zip
plugins {
compile ':my-plugin:1.2'
}
Or if it's a locally built plugin you could install it into your local maven cache using grails maven-install and just use mavenLocal() instead of the flatDir.