How does Grails handle plugin dependencies

↘锁芯ラ 提交于 2019-12-03 20:19:37

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/8837068/how-does-grails-handle-plugin-dependencies

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!