Grails如何处理插件依赖关系 [英] How does Grails handle plugin dependencies

查看:101
本文介绍了Grails如何处理插件依赖关系的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Grails插件作为复杂产品的包装。该产品对诸如hibernate等其他产品具有很多依赖性。问题是,该grails有一些相同的依赖关系,但版本不同。
例如Grails - > hibernate 3.6.7
其他产品 - > hibernate 3.5.6



Grails如何处理插件依赖关系? Grails会为每个插件创建一个单独的ClassLoader吗?是否可配置?



感谢您的提前! 解决方案

一个依赖解决机制,可以解决以下依赖关系之间的冲突:


  • Grails本身

  • Grails应用程序

  • 应用程序的插件

  • 插件依赖项



  • 只要确定你指定了你的插件所依赖的内容,并让Grails的依赖关系解决其余的问题。 Grails历来使用Ivy来解决依赖问题,但是从Grails 2.3.0开始,默认情况下是Maven / Aether,可以选择使用Ivy。



    偶尔在应用程序中,我想要覆盖依赖关系解析所做的选择,例如排除传递依赖或强制使用特定的库版本,您可以在 BuildConfig.groovy



    像往常一样,Grails参考文档提供了非常全面的该主题

    更新



    继续下面的评论,如果您将JAR放入您的lib目录中应用程序将被依赖性解析忽略并直接放置在类路径中。所以你通常不应该这样做。请在 BuildConfig.groovy 依赖关系部分中指定JAR及其版本。



    更新2



    指定JAR的语法是

     <范围> <组>:其中伪影>:其中版本> 

    组,工件和版本共同确定您想要的下载,而scope则指定了你想如何使用JAR。查找特定JAR的组,工件和版本的最简单方法是搜索Maven存储库



    请阅读以了解您可以使用的不同范围。 / p>

    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!

    解决方案

    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.

    这篇关于Grails如何处理插件依赖关系的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆