A grails application I work with has two ways to include plugins:
first in the application.properties file:
plugins.cache-headers=1.0.4
plugins.cached-resources=1.1
plugins.database-migration=1.1
plugins.export=1.5
plugins.font-awesome-resources=3.2.1.2
and in the BuildConfig.groovy file:
runtime ":resources:1.1.6"
compile ":database-migration:1.3.6"
compile ":quartz:0.4.2"
compile ":export:1.5"
compile ":font-awesome-resources:3.2.1.2"
It seems confusing that the database migration plugin is version 1.1 in application resources and 1.3.6 in BuildConfig.
Why are there two ways to configure plugins for grails?
Yes there are two ways of installing plugins.
The old way of declaring dependencies, using the command install-plugin. This will work with application.properties.
In Grails 2.x the preferred way is to use BuildConfig.groovy since this is more flexible, you can exclude jars/dependencies, define the scope and config the dependency to not be exported.
plugins {
test() //test scoped plugin
compile("group:name:version") {
excludes "some-dependency" //install the plugin, but not his dependency
}
compile("...") {
export = false //use this dependency, but not export.
}
}
With install-plugin, all your dependencies will be compile scoped.
More about in this discussion.
Related
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 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 a project where I want to include the console plugin for certain environments but not for others - it should go in the (custom) deployTest environment, but not for Production.
If I build the app using grails, I have a BuildConfig.groovy that looks like:
grails.project.dependency.resolution = {
/// some stuff
plugins {
/// more dependencies
if (Environment.current != Environment.PRODUCTION){
compile ":console:1.5.1"
}
}
}
Dependency resolution for Grails when using Gradle to build it is based on the build.gradle file, not the BuildConfig.groovy.
How do I achieve this please?
It seems more to me like you want to INCLUDE a dependency based upon the environment. However, the approach will be the same either way. In your build.gradle file you have a 'dependencies' section. Since this is Groovy, it is code. The -PgrailsEnv value is used by gradle to specify the environment. Just use that:
dependencies {
// if no property, then gradle will be default to prod. So test
// for that or having it explicitly provided
if (!project.hasProperty('grailsEnv') || project.grailsEnv.equals('prod')) {
compile ':console:1.5.1'
}
}
I'm totally confused how and where to specify my own plugin dependencies in Grails 2.2.X The documentation (Understanding Plugin Load Order) says that you can specify the dependencies in plugin descriptor class MyGrailsPlugin.groovy. Whereas, the "Upgrading from" chapter says that only pom dependencies will be taken into account. As I understand this unclear statement, only if I would specify the dependency in BuildConfig as a compile dependency that it would be used.
Using dependsOn brought me some problems in my main application (could not resolve a dependency in plugin even if it exists - I think some wild card problem "def dependsOn =['jquery-ui': "* > 1.8.24"]").
The only way how the plugin dependency works for me is specifying it in BuildConfig (MyPlugin):
grails.project.work.dir = 'target'
grails.project.dependency.resolution = {
inherits 'global'
log 'warn'
repositories {
grailsCentral()
mavenLocal()
mavenCentral()
}
plugins {
build(':release:2.2.1', ':rest-client-builder:1.0.3') {
export = false
}
compile ":resources:1.1.6"
compile ":jquery:1.8.3"
compile ":jquery-ui:1.8.24"
}
}
But my application uses resources plugin of version 1.2. When I run the app it always asks me if I'd like to upgrade to 1.1.6.
So the question is, how and where should I specify my dependencies.
Thanks,
Mateo
Actually, I am using grails 2.1.0. In that i replace resource with 1.2( runtime ":resources:1.2") in BuildConfig.groovy.
And then refresh dependencies. It is worked fine.
After reading more about Grails plug-in I realized that this behavior makes sense. If the plugin specify certain version of its dependency and your project specifies a different one, you're in conflict. You need to use following in order to exclude dependecy from the plugin and use yours:
runtime ":resources:1.2"
compile ':my-plugin:2.0.8', {
exclude 'resources'
}
In this case the plugin creator cannot assure that his plugin will run properly with newer version of dependency.
Regarding the resources plugin dependency. In my opinion it is better to use following
compile ":resources:1.1.6" {
export = false
}
which won't include the dependency for your plugin. This should be used just when you defines some ApplicationResources.groovy. If you use something from this plugin in your plugin you should not exclude resource plugin...
In my opinion you should specify your plugin dependencies in BuildConfig.groovy
Hope these things will be improved in further Grails versions.
Further reading from Burt:
http://www.slideshare.net/burtbeckwith/plugins-21828912
What's the difference between build, runtime, and compile, in BuildConfig.groovy (1.3.7)
grails.project.dependency.resolution = {
plugins {
build "acme:acme-cache:latest.integration"
}
dependencies {
build "com.foo.bar:foobar:1.0.5"
runtime "org.apache.httpcomponents:httpclient:4.0.3"
compile("com.thoughtworks.xstream:xstream:1.3.1")
}
}
build - dependency that is only needed by the build process
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
compile - dependency that is needed at both compile-time and runtime. This is the most common case
There are a couple of other dependency scopes:
test - dependency that is only needed by the tests, e.g. a mocking/testing library
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
It seems the 2 previous answers conflict on the distinction between compile and build. I believe that build is the scope that includes grails compile and grails run-app, while compile is just the former.
Starting from Grails 3, dependencies are managed by Gradle. The grails-app/conf/BuildConfig.groovy file has been replaced by the build.gradle file in the project's root.
The Grails user guide explain how to set grails depencies with gradle. See also the related Gradle documentation for further details on managing dependencies using it.
A couple grails commands help illustrate the difference. Consider grails run-app and grails compile. grails compile is the compile step and will include compile-time dependencies. grails run-app is the run step and will include runtime dependencies. Build dependencies are anything that you might need to run any of these commands, for example, a custom script that hooks into some build events.
So you would pick the one that best fits when you need to be certain the dependency is included.