如何处理插件依赖

如何处理插件依赖

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

问题描述

限时删除!!

我正在创建一个 Grails 插件作为复杂产品的包装器.该产品与其他产品(如 hibernate)有很多依赖关系.问题是,grails 有一些相同的依赖项,但版本不同.例如.Grails -> 休眠 3.6.7其他产品 -> 休眠 3.5.6

Grails 如何处理插件依赖?Grails 是否为每个插件创建了一个单独的类加载器?可以配置吗?

提前致谢!

解决方案

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

  • Grails 自身
  • Grails 应用程序
  • 应用程序的插件
  • 插件依赖

只要确保您指定了插件依赖的内容,其余的让 Grails 的依赖项解析处理.Grails 过去使用 Ivy 进行依赖项解析,但从 Grails 2.3.0 开始,默认使用 Maven/Aether 并可选择使用 Ivy.

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

中完成所有这些

像往常一样,Grails 参考文档非常全面地介绍了该主题.

更新

对于您在下面的评论,如果您将 JAR 放在应用程序的 lib 目录中,它将被依赖项解析忽略并直接放置在您的类路径中.所以你通常不应该这样做.在 BuildConfig.groovydependencies 部分中指定 JAR 及其版本.

更新 2

指定 JAR 的语法是

<组>:<工件>:<版本>

组、工件和版本共同标识您要下载的内容 (JAR),而范围指定如何使用 JAR.查找特定 JAR 的组、工件和版本的最简单方法是搜索 Maven 存储库.>

阅读本文以了解您可以使用的不同范围.

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 如何处理插件依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 22:14