5

I'm creating a Grails Plugin as a wrapper for a complex product. This product has a lot of dependencies to other products like hibernate. The issue is, that grails has some same dependencies but with different Versions. E.g. Grails -> hibernate 3.6.7 other product -> hibernate 3.5.6

How does Grails handle the plugin dependencies? Does Grails create an separate ClassLoader for each Plugin? Is it configurable?

Thanks in advance!

Waldemar
  • 700
  • 7
  • 19

1 Answers1

7

Grails has a dependency resolution mechanism that resolves conflicts among the dependencies of:

  • Grails itself
  • The Grails application
  • The application's plugins
  • The plugins dependencies

Just make sure that you specify what your plugin depends on, and let Grails' dependency resolution take care of the rest. Grails historically used Ivy for dependency resolution, but starting with Grails 2.3.0 the default is Maven/Aether with the option to use Ivy.

Occasionally in an application, you'll want to override the choices made by the dependency resolution, e.g. exclude a transitive dependency or force a particular library version to be used, you can do all this in BuildConfig.groovy

As usual, the Grails reference document provides very comprehensive coverage of this topic.

Update

Further to your comment below, if you put a JAR in the lib directory of your application it will be ignored by the dependency resolution and placed on your classpath directly. So you shouldn't normally do this. Specify the JAR and it's version in the dependencies section of BuildConfig.groovy instead.

Update 2

The syntax for specifying a JAR is

<scope> <group>:<artifact>:<version>

group, artifact, and version collectively identify what (JAR) you want to download, whereas scope specifies how you want to use the JAR. The easiest way to find the group, artifact, and version of a particular JAR is to search a Maven repository.

Read this to learn about the different scopes you can use.

Community
  • 1
  • 1
Dónal
  • 185,044
  • 174
  • 569
  • 824
  • 1
    Thanks for the reply. If I put a jar file in the lib directory of my grails application/plugin, then the application doesn't starts due to confilicts in the versions. – Waldemar Jan 12 '12 at 15:46
  • In the dependencies desction, there is a dummy entry `runtime 'mysql:mysql-connector-java:5.1.18'` - doesn't look like the name of a jar. Can you give a hint how to specify a jar? The documentation is great, but I've got the feeling that without maven knowledge, I am still lost... – rdmueller Jan 12 '12 at 20:02
  • thanx for the update. I have still some open questions - do you mind to take a look at them? http://stackoverflow.com/questions/8847804/use-local-flat-file-repository-instead-of-remote-maven-repository – rdmueller Jan 13 '12 at 08:34
  • I'm confused, are Waldemar and Ralf the same person? – Dónal Jan 13 '12 at 09:58
  • Hi Don, Ralf is my colleague. So we have often same Problems – Waldemar Jan 17 '12 at 14:28