22

Here's what part of my ivy.xml looks like right now:

<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" />

Here's what I'd like it to look like:

<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}" />

Is this possible? What's the syntax?

Edward Dale
  • 29,597
  • 13
  • 90
  • 129

3 Answers3

32

I ended up using XML entities to do the substitution. This keeps everything in the same file, which is important for my use case.

<?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>
Edward Dale
  • 29,597
  • 13
  • 90
  • 129
14

Syntax is correct. All you need to do is set the ANT property somewhere.

For example

ant -Dspring.version=3.0.2.RELEASE

Another alternative is to add the property declaration into the ivysettings.xml file

<ivysettings>

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

    <settings defaultResolver="maven2"/>
    <resolvers>
        <ibiblio name="maven2" m2compatible="true"/>
    </resolvers>
</ivysettings>
Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185
  • 2
    Cool! Is it possible to set the property inside of `ivy.xml`? That way all of the dependency information would be together. – Edward Dale Jun 21 '10 at 12:56
  • Putting the property declaration in the ivy settings file achieves the same objective of keeping the dependency information together – Mark O'Connor Jun 21 '10 at 17:03
  • 2
    Thanks for the answer, but I went with my solution (http://stackoverflow.com/questions/2996048/can-i-use-properties-in-an-ivy-xml-file-to-avoid-repeating-version-numbers-of-dep/3091114#3091114) because I wanted to keep the version declarations in the same file. – Edward Dale Jun 22 '10 at 07:30
  • This works great on the command line, but doesn't seem compatible with IvyIdea plugin for IntelliJ. Any suggestions? – Rich Ashworth Feb 02 '15 at 10:49
  • Sounds like the ivy plugin is not picking up the settings file. I'm not familiar with that plugin, so can't provide an authoritative suggestion. – Mark O'Connor Feb 02 '15 at 22:28
0

You can use property files as explained here: http://apache-ivy.996301.n3.nabble.com/ivyde-properties-on-ivy-xml-td7484.html

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

insite ivysettings.xml

tkruse
  • 10,222
  • 7
  • 53
  • 80