有人可以解释 ivy.xml 依赖项的 conf 属性吗? [英] Can someone explain the ivy.xml dependency's conf attribute?

查看:28
本文介绍了有人可以解释 ivy.xml 依赖项的 conf 属性吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找不到对 Ivy 依赖项标签的 conf 属性的任何详尽解释:

看到那个 conf 属性了吗?我找不到关于 -> 符号右侧的任何解释(我能理解).请记住,我不知道关于 Maven 的第一件事,所以请考虑到这一点来解释这个属性.

是的,我已经看过这个:http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html

谢谢,

解决方案

首先,Ivy不是 Maven ;)
Maven2是一个软件项目管理和理解工具,而Ivy只是一个依赖管理工具.

Ivy 在很大程度上依赖于一种称为配置的独特概念.
在 Ivy 中,模块配置是一种使用或查看模块的方式.
例如,您可以在模块中进行测试和运行时配置.但是你也可以有一个 MySQL 和一个 Oracle 配置.或者一个 Hibernate 和一个 JDBC 配置.

在每个配置中,您可以声明:

  • 需要哪些工件(jar、war、...).
  • 你对其他模块的依赖,并描述你需要的依赖配置.这称为配置映射.

所以 conf 属性确切地说:描述依赖项的配置映射.
映射的子元素 是您的右手边-> 符号",表示映射的依赖配置的名称.'*' 通配符可用于指定该模块的所有配置.

请参阅Ivy 配置的最简单说明" 来自 Charlie Hubbard

<块引用>

其中重要的部分是 Ivy 下载依赖项并组织它们.

一个 ivy 模块(即 ivy.xml 文件)有两个主要部分:

  • 您需要哪些依赖项?
  • 您希望它们如何组织?

第一部分在 元素下配置.
第二个由 元素

控制

当 Ivy 下载这些依赖项时,它需要知道在拉取这些可传递依赖项时使用什么范围(我们拉取它是为了测试、运行时、编译等吗?).我们必须告诉 Ivy 如何将我们的配置映射到 Maven 范围,以便它知道要拉什么.

<小时>

Maven2 有一个叫做范围的东西.
您可以将依赖项声明为测试范围或构建时范围的一部分.
然后根据此范围,您将获得依赖项(maven2 中每个模块只有一个工件),其依赖项取决于其范围.作用域是在 maven2 中预定义的,你不能改变它.

这意味着:

<块引用>

为许多库下载了很多不必要的依赖项.
例如,Hibernate 下载一堆 JBoss JAR,而 Display Tag 下载所有各种 Web 框架 JAR.我发现自己排除了几乎与添加的一样多的依赖项.

问题在于,hibernate 可以与多个缓存实现、多个连接池实现一起使用……而这无法通过作用域进行管理,而 Ivy 配置为此类问题提供了一个优雅的解决方案.
例如,在 Ivy 中,假设 hibernate 有一个像这样的 Ivy 文件,那么你可以像这样声明一个依赖项:

使用它的 proxool 和 oscache 实现进入休眠状态,就像这样:

使用 dbcp 和 swarmcache 进入休眠状态.

通过将您的默认 master 配置映射到proxool,oscache"或dbcp,swarmcache",您可以指定您需要的内容完全来自模块hibernate".

<小时>

您可以通过列出为与库关联的每个模块定义的 Ivy 配置来找到那些proxool,..."参数.例如:

<信息组织=ssn-src"模块=pc"/><configurations defaultconfmapping="default->default"><conf name="default"/><conf name="provided" description="它们由环境提供."/><conf name="compile" extends="default,provided"/><conf name="war" extends="default"/></配置><依赖项>

norelrefern示例:

<块引用>

假设 modA 有两个配置,default 和 test.
实际上,想要省略依赖元素的 conf 属性是非常不寻常的.
modAivy.xml 可能有一个依赖:

<块引用>

您从默认开始,而不是从默认和测试开始.

上面的例子使 modA 的默认值依赖于 modB 的 conf1、conf2 和 conf3.
或者你可能想说 modA 的默认值只取决于 modB 的 conf1:

I can't find any thorough explanation of the Ivy dependency tag's conf attribute:

<dependency org="hibernate" name="hibernate" rev="3.1.3" conf="runtime, standalone -> runtime(*)"/>

See that conf attribute? I can't find any explanation (that I can understand) about the right hand side of the -> symbol. PLEASE keep in mind I don't know the first thing about Maven so please explain this attribute with that consideration.

Yes, I've already looked at this: http://ant.apache.org/ivy/history/latest-milestone/ivyfile/dependency.html

Thanks,
Dan

解决方案

First of all, Ivy is not Maven ;)
Maven2 is a software project management and comprehension tool, whereas Ivy is only a dependency management tool.

Ivy heavily relies on a unique concept called configuration.
In Ivy, a module configuration is a way to use or to see the module.
For instance, you can have a test and runtime configuration in your module. But you can also have a MySQL and an Oracle configuration. Or an Hibernate and a JDBC configuration.

In each configuration, you can declare:

  • what artifacts (jar, war, ...) are required.
  • your dependencies on other modules, and describe which configuration of the dependency you need. This is called configuration mapping.

So the conf attribute does precisely that: Describes a configuration mapping for a dependency.
The mapped child element is your "right hand side of the -> symbol" and represents the name of the dependency configuration mapped. '*' wildcard can be used to designate all configurations of this module.

See more at "Simplest Explanation of Ivy Configuration" from Charlie Hubbard

The important part of that is Ivy downloads dependencies and organizes them.

An ivy-module (ie ivy.xml file) has two main parts:

  • What dependencies do you need?
  • How do you want them organized?

The first part is configured under the <dependencies> element.
The 2nd is controlled by the <configurations> element

When Ivy is downloading these dependencies it needs to know what scopes to use when pulling these transitive dependencies (are we pulling this for testing, runtime, compilation, etc?). We have to tell Ivy how to map our configurations to Maven scopes so it knows what to pull.


Maven2 on its side has something called the scope.
You can declare a dependency as being part of the test scope, or the buildtime scope.
Then depending on this scope you will get the dependency artifact (only one artifact per module in maven2) with its dependencies depending on their scope. Scopes are predefined in maven2 and you can't change that.

That means :

There are a lot of unnecessary dependencies downloaded for many libraries.
For example, Hibernate downloads a bunch of JBoss JARs and the Display Tag downloads all the various web framework JARs. I found myself excluding almost as many dependencies as I added.

The problem is that hibernate can be used with several cache implementations, several connection pool implementation, ... And this can't be managed with scopes, wheres Ivy configurations offers an elegant solution to this kind of problem.
For instance, in Ivy, assuming hibernate has an Ivy file like this one, then you can declare a dependency like that:

<dependency org="hibernate" name="hibernate" rev="2.1.8" conf="default->proxool,oscache"/>

to get hibernate with its proxool and oscache implementations, and like that:

<dependency org="hibernate" name="hibernate" rev="2.1.8" conf="default->dbcp,swarmcache"/>

to get hibernate with dbcp and swarmcache.

By mapping your default master configuration to "proxool,oscache" or to "dbcp,swarmcache", you specify what you need exactly from the module "hibernate".


You can find those "proxool,..." arguments by listing the Ivy configuration defined for each modules associate with the library. For instance:

<ivy-module version="2.0">
<info organisation="ssn-src" module="pc"/>
<configurations defaultconfmapping="default->default">
    <conf name="default" />
    <conf name="provided" description="they are provided by the env." />
    <conf name="compile" extends="default,provided" />
    <conf name="war" extends="default"/>
</configurations>
<dependencies>

Example:

let's suppose modA has two configurations, default and test.
As a practical matter, it's going to be highly unusual to want to leave out the conf attribute of the dependency element.
The ivy.xml for modA might have a dependency:

<dependency org="theteam" name="modB" rev="1.0" conf="default->*" />

You're starting from default, rather than from both default and test.

The above example makes modA's default depend on modB's conf1, conf2, and conf3.
Or you might want to say that modA's default only depends on modB's conf1:

<dependency org="theteam" name="modB" rev="1.0" conf="default->*conf1*" />

这篇关于有人可以解释 ivy.xml 依赖项的 conf 属性吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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