Is there a way of disabling a plugin on a Grails 3 project? I am using dependencies that have Grails plugins but I just want to keep the classes that are in the dependency.
Related
Is there any posibility to make it work a plugin created using grails 3 as a dependency of a grails 2 project? Both projects use the same groovy version.
Is there any posibility to make it work a plugin created using grails
3 as a dependency of a grails 2 project?
Not really. We re-wrote the plugin system in Grails 3 such that Grails 3 plugins are not compatible with Grails 2 and vice-versa.
That said, Grails 3 plugins are just .jar files. You could have a Grails 2 application which depends on a Grails 3 plugin (just express the dependency like a normal library dependency, not a plugin dependency) and then whatever classes are in the Grails 3 plugin jar will be available in the Grails 2 app, but you won't have any of the plugin specific behavior imposed, you would just have access to the classes in the jar. Depending on the particulars, that might or might not be helpful.
For the most part the answer to your question is "no".
Both projects use the same groovy version.
That doesn't sound right. I think the latest version of Grails 2 supports an earlier version of Groovy than the earliest version of Grails 3.
I'm writing a custom Grails 2 plugin to modularize my Grails applications. In the plugin I'm planning to define basic GSPs that can be overridden by the application that will utilize the plugin. I'm thinking of writing a Grails command script that copies those GSPs into the grails-app directory of the app the plugin is installed in. If in the plugin, I put those GSPs in grails-app/views, how do I refer to the actual Grails app directory in the Grails command script, which is also grails-app/views?
The solution to this is almost the same as this answer. The built-in properties basedir and <plugin_name>PluginBaseDir differentiate the target app and the plugin directories.
I am using Grails 2.3.8
I am using - org.yaml.snakeyaml.Yaml class.
Didn't have any issues with GGTS workspace finding the package during auto
complete in the source.
But when running the application I get
java.lang.ClassNotFoundException:org.yaml.snakeyaml.Yaml
My assumption was this is part of the core Grails and the jars will be
included automatically.
Do I have to configure and add the jar or dependency in the
BuildConfig.groovy ?
Grails 3 uses Yaml and includes it as a dependency but prior to 3.0 it didn't, so you need to configure it like any third-party dependency in BuildConfig.groovy, e.g.
dependencies {
...
compile 'org.yaml:snakeyaml:1.14'
}
I have found some code in grails plugins that can be use outside grails. Is there a way to use the code from the plugin as a dependency in a groovy project other than creating two projects?
For example I found the following project:
https://github.com/jeffellis/grails-yammer-metrics
Where they created some annotations for Groovy code that I would like to use outside a grails project.
As of grails 2.1, you can export a plugin as a binary plugin and then declare as a regular jar dependency (via grape in groovy). http://grails.org/doc/latest/guide/plugins.html#binaryPlugins
How reusable the code is would depend on how closely coupled the plugin is to the code, I guess.
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.