Java 有人可以解释 ivy.xml 依赖项的 conf 属性吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/652555/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 17:25:10  来源:igfitidea点击:

Can someone explain the ivy.xml dependency's conf attribute?

javaapacheantivy

提问by Daniel Kaplan

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

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

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

See that confattribute? 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.

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

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

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

Thanks,
Dan

谢谢,

采纳答案by VonC

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 不是 Maven;)
Maven2 是一个软件项目管理和理解工具,而 Ivy 只是一个依赖项管理工具。

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.

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

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.
  • 需要哪些工件(jar、war 等)。
  • 您对其他模块的依赖,并描述您需要的依赖配置。这称为配置映射。

So the confattribute does precisely that: Describes a configuration mapping for a dependency.
The mapped child elementis 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.

因此conf属性正是这样做的:描述依赖项的配置映射。
映射的子元素是你的“右手边->符号”,并表示映射的依赖配置的名称。'*'通配符可用于指定该模块的所有配置。

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.xmlfile) 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.

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

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

  • 你需要什么依赖?
  • 你希望它们如何组织?

第一部分在<dependencies>元素下配置。
2nd 由<configurations>元素控制

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



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.

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

That means :

这意味着:

There are a lotof 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.

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

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:

问题是 hibernate 可以与几个缓存实现、几个连接池实现一起使用……而这不能用范围来管理,而 Ivy 配置为此类问题提供了一个优雅的解决方案。
例如,在 Ivy 中,假设 hibernate 有一个像这样的 Ivy 文件,那么您可以声明一个这样的依赖项:

<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:

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

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

to get hibernate with dbcp and swarmcache.

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

By mapping your default masterconfiguration to "proxool,oscache" or to "dbcp,swarmcache", you specify what you need exactlyfrom the module "hibernate".

通过将您的默认master配置映射到“ proxool,oscache”或“ dbcp,swarmcache”,您可以从模块“hibernate”中准确指定您需要的内容。



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

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

<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 modAhas two configurations, default and test.
As a practical matter, it's going to be highly unusual to want to leave out the confattribute of the dependency element.
The ivy.xmlfor modAmight have a dependency:

让我们假设modA有两个配置,默认和测试。
实际上,想要省略conf依赖元素的属性是非常不寻常的。
ivy.xmlmodA可能有依赖性:

<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:

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

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

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

回答by Espen

Thanks VonC!

感谢 VonC!

It helped me alot further.

它进一步帮助了我。

When it comes to options (configurations) tieTYT, you can find them in the ivy-[revision number].xml file in your Ivy repository under: organization name --> module name.

当涉及到选项(配置)tieTYT 时,您可以在 Ivy 存储库中的 ivy-[revision number].xml 文件中找到它们:组织名称 --> 模块名称。

An example configurations element from the JUnit 4.6 revision downloaded from http://www.springsource.com/repository/app/.

http://www.springsource.com/repository/app/下载的 JUnit 4.6 修订版中的示例配置元素。

<configurations>
    <conf name="compile" visibility="public" description="Compile dependencies"/>
    <conf name="optional" visibility="public" extends="compile" description="Optional dependencies"/>
    <conf name="provided" visibility="public" description="Provided dependencies"/>
    <conf name="runtime" visibility="public" extends="compile" description="Runtime dependencies"/>
</configurations>

In my project's ivy.xml file, I have a configuration compile-test. In the dependencies element I have the following dependency:

在我项目的 ivy.xml 文件中,我有一个配置编译测试。在依赖项元素中,我有以下依赖项:

<dependency org="org.junit" name="com.springsource.org.junit"
        rev="4.6.0" conf="compile-test->compile" />

As you can see, my compile-test configuration depends on the compile configuration in the JUnit's ivy.xml file.

如您所见,我的编译测试配置依赖于 JUnit 的 ivy.xml 文件中的编译配置。

回答by Archie

It helped me once to understand things this way:

它曾经帮助我以这种方式理解事物:

  1. An ivy configuration is simply a name for some subset of the module's artifacts.
  2. Dependencies between modules are specified in terms of configuration names.
  1. 常春藤配置只是模块工件某些子集的名称。
  2. 模块之间的依赖关系是根据配置名称指定的。

回答by chubbsondubs

I've read these answers and quite frankly I don't find them very helpful. I think they could be improved so I wrote down how I use and understand configurations by showing a practical example:

我已经阅读了这些答案,坦率地说,我认为它们没有太大帮助。我认为它们可以改进,所以我通过展示一个实际例子来写下我如何使用和理解配置:

http://wrongnotes.blogspot.com/2014/02/simplest-explanation-of-ivy.html

http://wrongnotes.blogspot.com/2014/02/simplest-explanation-of-ivy.html

Unfortunately, you have to understand a little about maven, and its dependencies because Ivy is using Maven repositories to download those jar files. Therefore, Ivy has to understand Maven and it passes that back to you. But, I think I kept it real simple without going into too much detail about maven.

不幸的是,您必须对 Maven 及其依赖项有所了解,因为 Ivy 使用 Maven 存储库来下载这些 jar 文件。因此,Ivy 必须了解 Maven 并将其传递给您。但是,我认为我保持了非常简单的方式,而没有过多地介绍 maven。