2010-06-08 8 views
19

Oto co część mojego ivy.xml wygląda teraz:Czy mogę używać właściwości w pliku ivy.xml, aby uniknąć powtarzania numerów wersji zależności?

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

Oto co chciałbym to wyglądać:

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

Czy to możliwe? Jaka jest składnia?

Odpowiedz

26

I skończył przy użyciu podmioty XML zrobić podstawienie. Dzięki temu wszystko znajduje się w tym samym pliku, co jest ważne dla mojego przypadku użycia.

<?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> 
+8

+1 Nicea boczne myślenia – skaffman

+1

świetny użytek podmiotów XML. Bardzo pomocne naprawdę. – Vikas

13

składnia jest poprawna. Wszystko, co musisz zrobić, to ustawić właściwość ANT gdzieś.

Na przykład

ant -Dspring.version=3.0.2.RELEASE 

Inną alternatywą jest dodanie deklarację właściwości do ivysettings.xml pliku

<ivysettings> 

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

    <settings defaultResolver="maven2"/> 
    <resolvers> 
     <ibiblio name="maven2" m2compatible="true"/> 
    </resolvers> 
</ivysettings> 
+2

Cool! Czy jest możliwe ustawienie właściwości wewnątrz 'ivy.xml'? W ten sposób wszystkie informacje o zależnościach będą razem. –

+0

Umieszczenie deklarację właściwości w pliku ustawień bluszcz osiąga ten sam cel utrzymanie informacje o zależnościach razem –

+2

Dzięki za odpowiedź, ale poszedłem z moim roztworze (http://stackoverflow.com/questions/2996048/can-i-use -properties-in-a-bluszczem pliku xml do unikać powtarzających-wersja-numbers-of-dep/3091114 # 3091114) ponieważ chciałem zachować deklaracje wersji w tym samym pliku. –

Powiązane problemy