我可以在ivy.xml文件中使用属性来避免重复依赖项的版本号吗?

Edw*_*ale 21 apache dependencies ivy

这是我的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" />
Run Code Online (Sandbox Code Playgroud)

这是我希望它看起来像:

<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}" />
Run Code Online (Sandbox Code Playgroud)

这可能吗?语法是什么?

Edw*_*ale 29

我最终使用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>
Run Code Online (Sandbox Code Playgroud)


Mar*_*nor 14

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

例如

ant -Dspring.version=3.0.2.RELEASE
Run Code Online (Sandbox Code Playgroud)

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

<ivysettings>

    <property name="spring.version" value="3.0.2.RELEASE"/>

    <settings defaultResolver="maven2"/>
    <resolvers>
        <ibiblio name="maven2" m2compatible="true"/>
    </resolvers>
</ivysettings>
Run Code Online (Sandbox Code Playgroud)

  • 凉!是否可以在`ivy.xml`中设置属性?这样,所有依赖信息都将在一起. (2认同)
  • 谢谢你的答案,但我选择了我的解决方案(http://stackoverflow.com/questions/2996048/can-i-use-properties-in-an-ivy-xml-file-to-avoid-repeating-version- numbers-of-dep/3091114#3091114)因为我想将版本声明保留在同一个文件中. (2认同)