【问题标题】:Can I use properties in an ivy.xml file to avoid repeating version numbers of dependencies?我可以在 ivy.xml 文件中使用属性来避免重复依赖项的版本号吗?
【发布时间】:2011-03-01 01:50:53
【问题描述】:

这是我的 ivy.xml 部分现在的样子:

<dependency org="org.springframework" name="org.springframework.core" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.context" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.jdbc" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.beans" rev="3.0.2.RELEASE" />
<dependency org="org.springframework" name="org.springframework.jms" rev="3.0.2.RELEASE" />

这是我想要的样子:

<dependency org="org.springframework" name="org.springframework.core" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.context" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.jdbc" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.beans" rev="${spring.version}" />
<dependency org="org.springframework" name="org.springframework.jms" rev="${spring.version}" />

这可能吗?语法是什么?

【问题讨论】:

    标签: apache dependencies ivy


    【解决方案1】:

    我最终使用 XML 实体进行替换。这会将所有内容保存在同一个文件中,这对我的用例很重要。

    <?xml version="1.0"?>
    <!DOCTYPE ivy-module [
        <!ENTITY spring.version "3.0.2.RELEASE">
    ]>
    <ivy-module version="2.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="http://incubator.apache.org/ivy/schemas/ivy.xsd">
    
        <info organisation="org" module="mod"/>
    
        <dependencies>
            <dependency org="org.springframework" name="org.springframework.core" rev="&spring.version;" />
            <dependency org="org.springframework" name="org.springframework.context" rev="&spring.version;" />
            <dependency org="org.springframework" name="org.springframework.jdbc" rev="&spring.version;" />
            <dependency org="org.springframework" name="org.springframework.beans" rev="&spring.version;" />
            <dependency org="org.springframework" name="org.springframework.jms" rev="&spring.version;" />
        </dependencies>
    </ivy-module>
    

    【讨论】:

    • 很好地使用了 XML 实体。确实很有帮助。
    【解决方案2】:

    语法正确。您需要做的就是在某处设置 ANT 属性。

    例如

    ant -Dspring.version=3.0.2.RELEASE
    

    另一种选择是将属性声明添加到 ivysettings.xml 文件中

    <ivysettings>
    
        <property name="spring.version" value="3.0.2.RELEASE"/>
    
        <settings defaultResolver="maven2"/>
        <resolvers>
            <ibiblio name="maven2" m2compatible="true"/>
        </resolvers>
    </ivysettings>
    

    【讨论】:

    • 酷!是否可以在ivy.xml 内设置属性?这样所有的依赖信息都会在一起。
    • 将属性声明放在​​ ivy 设置文件中实现了将依赖关系信息保存在一起的相同目标
    • 感谢您的回答,但我选择了我的解决方案 (stackoverflow.com/questions/2996048/…),因为我想将版本声明保留在同一个文件中。
    • 这在命令行上效果很好,但似乎与 IntelliJ 的 IvyIdea 插件不兼容。有什么建议吗?
    • 听起来 ivy 插件没有获取设置文件。我对那个插件不熟悉,所以不能提供权威的建议。
    【解决方案3】:

    您可以按照此处的说明使用属性文件:http://apache-ivy.996301.n3.nabble.com/ivyde-properties-on-ivy-xml-td7484.html

    <properties file="${ivy.project.dir}/build.properties" />
    

    insite ivysettings.xml

    【讨论】:

      猜你喜欢
      • 2010-10-13
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-04-18
      • 2012-05-11
      • 2017-05-24
      • 2011-01-22
      相关资源
      最近更新 更多