常春藤,什么是主配置,为什么它不拉jvyaml? [英] Ivy, what is the master configuration and why is it not pulling jvyaml?

查看:238
本文介绍了常春藤,什么是主配置,为什么它不拉jvyaml?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下ivy文件:


    

 <配置defaultconfmapping =联编>
    <的conf NAME =联编知名度=私人描述=只需要编译库/>
    <的conf NAME =运行描述=库只需在运行时/>
    <的conf NAME =测试描述=库仅用于测试/>
< /配置><依赖和GT;
  <依赖有机=net.java.devNAME =jvyamlREV =0.2.1的conf =运行/>
  <依赖有机=org.apache.solrNAME =Solr的核心REV =3.6.0的conf =运行/>< /依赖和GT;

和我有一只蚂蚁检索任务,看起来像这样:

 <目标名称=检索所有取决于=决心>
    <常春藤:检索模式=LIB / [设置] / [神器] - [修改] [转]。CONF =*/>
< /目标与GT;

奇怪的是,所有的Solr的依赖下载到的lib /运行作为我期望,但jvyaml模块没有!这是解决,但除非我改变依赖声明不会下载到lib /运行时目录:

 <依赖有机=net.java.devNAME =jvyamlREV =0.2.1的conf =runtime->掌握/>

这是什么主配置,以及为什么需要它拉jvyaml罐子,但不SOLR?

感谢


解决方案

我建议你调整配置如下:

 <常春藤模块版本=2.0>
    <信息组织=com.myspotontheweb模块=演示/>    <配置>
        <的conf NAME =编译描述=只为需要编译库/>
        <的conf NAME =运行描述=只需要在运行时库扩展=编译/>
        <的conf NAME =测试描述=库仅用于测试扩展=运行/>
    < /配置>    <依赖和GT;
        <依赖有机=net.java.devNAME =jvyamlREV =0.2.1的conf =runtime->默认/>
        <依赖有机=org.apache.solrNAME =Solr的核心REV =3.6.0的conf =runtime->默认/>
    < /依赖和GT;< /常春藤模块>

实施了一些重大的变化:


  1. 使用更标准的编译配置

  2. 配置继承用扩展属性。编译依赖关系可以被自动包含在运行时和测试配置。

  3. 使用配置映射,例如:CONF =runtime->默认。这使得它明显哪个本地配置与远程配置有关。

配置映射解释

配置是一个强大的常春藤功能。当常春藤下载Maven的模块其执行内部翻译,并指定一组标准的配置,在这个回答中列出:

在声明依赖这是一个好主意,总是利用一个配置映射,这样毫无疑问,其中的依赖性文物进行分配。

例如:

 <依赖有机=?? NAME =?? REV =?? CONF =runtime->默认/>

在这里,我们说,我们希望远程模块的默认依赖与我们当地的运行时配置相关联。

在实践中,只有两个你真正需要远程配置映射:


  • 默认:远程模块的神器和所有它的运行时间传递依赖

  • :远程模块的神器只(不传递依赖)

在最后,我认为你的问题是由一个事实,即远程Maven模块的运行范围不包括Maven的模块的神器,而不是你得到模块jvyaml的不存在的传递依赖:-(

一些其他建议

我还建议产生常春藤依赖管理报告,如下:

 <目标名称=初始化描述=解析相关性和填充lib目录>
    <常春藤:决心/>
    <常春藤:报告todir =$ {} build.dir /常春藤报告图=FALSE/>
    <常春藤:检索模式=LIB / [设置] / [神器] - [修改] [转]。/>
< /目标与GT;

该报告将有助于解释每个依赖于如何不同的配置结束。确定依赖如何传递被管理也非常有用。

最后,这里的地方配置继承不负有心人,创建常春藤管理ANT类路径:

 <目标名称=初始化描述=解析相关性,并设置类路径>
    <常春藤:决心/>
    <常春藤:报告todir =$ {} build.dir /常春藤报告图=FALSE/>    <常春藤:cachepath PATHID =compile.path的conf =编译/>
    <常春藤:cachepath PATHID =runtime.path的conf =运行/>
    <常春藤:cachepath PATHID =test.path的conf =测试/>
< /目标与GT;

I have the following ivy file:

<configurations defaultconfmapping="buildtime">
    <conf name="buildtime" visibility="private" description="Libraries needed only for compilation" />
    <conf name="runtime" description="Libraries only needed at runtime" />
    <conf name="test" description="Libraries only needed for testing" />
</configurations>

<dependencies>
  <dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime" />
  <dependency org="org.apache.solr" name="solr-core" rev="3.6.0" conf="runtime" />

</dependencies>

and I have an ant retrieve task that looks like this:

<target name="retrieve-all" depends="resolve">
    <ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]" conf="*" />
</target>

The weird thing is, that all the solr dependencies download into lib/runtime as I'd expect, but the jvyaml module does not! It 'resolves', but will not download into the lib/runtime directory unless I change the dependency declaration to:

<dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->master" />

What is this master configuration and why is it needed to pull the jvyaml jar, but not solr?

Thanks

解决方案

I would suggest restructuring your configurations as follows:

<ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations>
        <conf name="compile" description="Libraries needed only for compilation" />
        <conf name="runtime" description="Libraries only needed at runtime" extends="compile" />
        <conf name="test" description="Libraries only needed for testing" extends="runtime" />
    </configurations>

    <dependencies>
        <dependency org="net.java.dev" name="jvyaml" rev="0.2.1" conf="runtime->default" />
        <dependency org="org.apache.solr" name="solr-core" rev="3.6.0" conf="runtime->default" />
    </dependencies>

</ivy-module>

Important changes introduced:

  1. Use the more standard "compile" configuration
  2. Configuration inheritance using the "extends" attribute. Compile dependencies can then be automatically included in both the runtime and test configurations.
  3. Use configuration mappings, for example: conf="runtime->default". This makes it obvious which local configuration is associated with which remote configuration.

Configuration mappings explained

Configurations are a powerful ivy feature. When ivy downloads Maven modules it performs an internal translation and assigns a standard set of configurations, listed in this answer:

When declaring a dependency it's a good idea to always make use of a configuration mapping, so that there is no doubt where the dependencies artifacts are assigned.

For example:

<dependency org="??" name="??" rev="??" conf="runtime->default" />

Here we're saying we want the remote module's default dependencies associated with our local runtime configuration.

In practice, there are only two remote configuration mappings you'll actually need:

  • default: The remote module's artifact and all it's runtime transitive dependencies
  • master: The remote module's artifact only (No transitive dependencies)

In conclusion, I think your problem was caused by the fact that the remote Maven module's "runtime" scope does not include Maven module's artifact, instead you were getting the non-existant transitive dependencies of the module jvyaml :-(

Some additional advice

I'd also suggest generating an ivy dependency management report, as follows:

<target name="init" description="Resolve dependencies and populate lib dir">
    <ivy:resolve/>
    <ivy:report todir="${build.dir}/ivy-report" graph="false"/>
    <ivy:retrieve pattern="lib/[conf]/[artifact]-[revision].[ext]"/>
</target>

The report will help explain how each dependency ends up on different configurations. Also really useful for determining how transitive dependencies are being managed.

And finally, here's where the configuration inheritance pays off, creating ivy managed ANT classpaths:

<target name="init" description="Resolve dependencies and set classpaths">
    <ivy:resolve/>
    <ivy:report todir="${build.dir}/ivy-report" graph="false"/>

    <ivy:cachepath pathid="compile.path" conf="compile"/>
    <ivy:cachepath pathid="runtime.path" conf="runtime"/>
    <ivy:cachepath pathid="test.path"    conf="test"/>
</target>

这篇关于常春藤,什么是主配置,为什么它不拉jvyaml?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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