우선 Ivy 작업을 가리 키도록 <taskdef>
을 정의해야합니다.
<property environment="env"/>
<property name="ivy.home" value="${env_IVY_HOME}"/>
<taskdef resource="org/apache/ivy/ant/antlib.xml">
<classpath>
<fileset dir="${ivy.home}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
이렇게하면 아이비 작업에 액세스 할 수 있습니다. 이러한 작업을 다음과 같이 사용하십시오.
<cachepath pathid="main.classpath" conf="compile"/>
문제는 아이비 작업 이름이 다른 앤트 작업과 충돌 할 수 있다는 것입니다. 예를 들어, 아이비 작업 <report>
이 있습니다. 이를 해결하기 위해 아이비 네임 스페이스를 생성 할 수 있습니다. 이를 위해이 같은 <project>
엔티티에 네임 스페이스에 대한 참조를 넣어 : 당신은 아이비 작업을 정의 할 때
<project name="my.proj" default="package" basedir="."
xmlns:ivy="antlib:org.apache.ivy.ant"/>
지금, 당신은 당신의 ivy
네임 스페이스에 그 antlib:org.apache.ivy.ant
참조를 사용할 수 있습니다. 같은 taskdef 이전,하지만 uri
필드 :
<property environment="env"/>
<property name="ivy.home" value="${env_IVY_HOME}"/>
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="antlib:org.apache.ivy.ant">
<classpath>
<fileset dir="${ivy.home}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
그런데, 그 uri
특별한 것이 없다. 나는이 일을 할 수 :
<project name="my.proj" default="package" basename="."
xmlns:ivy="pastrami:with.mustard">
[...]
<taskdef resource="org/apache/ivy/ant/antlib.xml"
uri="pastrami:with.mustard">
<classpath>
<fileset dir="${ivy.home}">
<include name="*.jar"/>
</fileset>
</classpath>
</taskdef>
요점은 당신이 ivy:
으로 작업 이름을 접두사 수 있습니다 지금이다. 대신이의 :
<cachepath pathid="main.classpath" conf="compile"/>
이제이 작업을 수행 할 수 있습니다
<ivy:cachepath pathid="main.classpath" conf="compile"/>
그리고 그것은 당신이 당신의 아이비 개미 작업에 액세스하는 방법입니다.
<ivy:settings file="${ivy.home}/ivysettings.xml"/>
가 가리 킵니다 아이비에 포함 된 기본 ivysettings.xml
파일이 있습니다 :
지금, 당신은 당신이 ivysettings.xml
파일을 정의하고이 점에 <ivy:settings/>
작업을 사용할 필요가, 당신의 아이비 개미 작업에 액세스 할 수 당신은 월드 와이드 Maven 저장소 시스템으로갑니다. 아주 간단
<ivy:settings/>
: 당신은 회사 전체 메이븐 저장소가없는 경우에, 당신은 기본 ivysettings.xml
파일을 사용할 수 있습니다.
작업을 마치면 보통 build.xml
파일과 같은 디렉토리에있는 프로젝트의 루트에있는 ivy.xml
파일을 읽고 resolve 개의 파일을 읽어 들여야합니다.
기본적으로 ivy.xml
파일에는 프로젝트로 가져올 타사 jar에 대한 참조가 포함되어 있습니다. 예를 들어 :
<dependencies>
<dependency org="log4j" name="log4j" rev="1.2.17" conf="compile->default"/>
<dependency org="junit" name="junit" rev="4.10" conf="test->default"/>
</dependencies>
이것이 말하는 것은 내가 컴파일 (너무 테스트를 컴파일 할 경우) log4j.jar
(버전 1.2.17)를 필요가 있습니다 만 내 테스트 코드의 컴파일 junit.jar
(revision.4.10)가 필요합니다 .
compile->default
가 난 그냥 항아리가 의존 할 수있는 다른 단지를 원하는 말한다 Maven의
default
구성에 내
compile
구성 (의 매핑입니다.의 내
compile
구성에서 온 않습니다
? 나는 그것을 정의 .. 내 ivy.xml
에 열 개 표준 구성이 있습니다이 또한 ivy.xml
파일로 전환 :
<configurations>
<conf name="default" visibility="public" description="runtime dependencies and master artifact can be used with this conf" extends="runtime,master"/>
<conf name="master" visibility="public" description="contains only the artifact published by this module itself, with no transitive dependencies"/>
<conf name="compile" visibility="public" description="this is the default scope, used if none is specified. Compile dependencies are available in all classpaths."/>
<conf name="provided" visibility="public" description="this is much like compile, but indicates you expect the JDK or a container to provide it. It is only available on the compilation classpath, and is not transitive."/>
<conf name="runtime" visibility="public" description="this scope indicates that the dependency is not required for compilation, but is for execution. It is in the runtime and test classpaths, but not the compile classpath." extends="compile"/>
<conf name="test" visibility="private" description="this scope indicates that the dependency is not required for normal use of the application, and is only available for the test compilation and execution phases." extends="runtime"/>
<conf name="system" visibility="public" description="this scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository."/>
<conf name="sources" visibility="public" description="this configuration contains the source artifact of this module, if any."/>
<conf name="javadoc" visibility="public" description="this configuration contains the javadoc artifact of this module, if any."/>
<conf name="optional" visibility="public" description="contains all optional dependencies">
</configurations>
당신은 당신이 원하는 구성 이름을 사용할 수 있지만 기본 메이븐 구성 이러한지도 d가 널리 사용됩니다. 당신이 당신의 ivy.xml
파일을 정의하면
, 당신이 당신의 의존성 해결하기 위해 <ivy.resolve>
을 사용할 수 있습니다 : 그래서
<ivy:resolve/>
을, 우리는 다음과 같은 한 :
- 방법에
<taskdef>
을 사용하도록 build.xml
을 사용하여 빌드에 Ivy Ant 작업을 통합하십시오.
- Ivy Ant 작업
<ivy:settings>
을 사용하여 Ivy를 구성하는 방법.
<ivy:resolve/>
을 사용하여 ivy.xml
파일을 읽고 타사 jar 종속성을 해결하십시오.
이제 실제로 이러한 jar 파일을 사용하려고합니다. 이 작업을 수행하는 세 가지 방법이 있습니다 :
<ivy:cachepath pathid="main.classpath" conf="compile"/>
당신이 당신의 ivy.xml
파일의 compile
구성에있는 항아리를 가리키는 (main.classpath이라는 경우) 클래스 경로를 만들 것입니다 <ivy:cachepath/>
작업. 이것은 대부분의 시간에 사용됩니다. 당신이 파일 세트가 필요한 경우
, 당신은이를 사용할 수 있습니다이 경우
<ivy:cachefileset setid="compile.fileset" conf="compile"/>
, 그것은 compile.fileset
의 REFID와 파일 세트를 생성합니다.
때로는 프로젝트에 병을 가져와야합니다. 예를 들어, 전쟁 또는 귀 파일을 만드는 경우 항아리를 묶으려는 경우입니다.이 경우, 당신은이를 사용할 수 있습니다 : 당신은 전쟁이나 귀에 포함 할 수 있습니다
<property name="lib.dir" value="${target.dir}/lib"/>
<ivy:retrieve pattern="${lib.dir}/[artifact].[ext]"
conf="runtime"/>
의 ${lib.dir}
디렉토리로 항아리를 가져올 것이다.
죄송합니다. 긴 답변을 드리지 못하지만 많은 조치가 필요합니다. Ivy 전체 장을 가지고있는 Manning의 책 Ant in Action을 강력히 추천합니다.
건너편에, 나는 그것을 더 upvote 수 있었으면 좋겠다. 날 도와 줘서 고마워. 완벽 했어. 한 가지 빠른 후속 질문 (내가 할 수있는 경우) : 아마도 Artifactory에서 관리하는 자체 호스팅 저장소를 가질 계획입니다. 아이비와 함께 일할 때마다, 동료들은'conf' 속성을'conf = "* -> *"'또는'conf = compile-> default'로 정의 했습니다만, 아무도 명확하지 않은 것 같습니다 이러한 것들이 무엇인지에 대한 이해, 그리고 왜 ... – IAmYourFaja
당신은 로컬 아이비 설정 ('ivy.xml')과 리포지토리 사이의 매핑에 대해 언급하고 있습니다. 그리고 당신은'컴파일 ' config는 ('test '설정과 비교하여) 보일 것입니다. 하지만 저장소 측 ("화살표"연산자의 오른쪽)은 어떨까요? "'* *> *'"는 (으)로 매핑되는 것은 무엇입니까? "디폴트"는 어떻습니까? 아이비 문서를 여러 번 읽었을지라도 머리를 감쌀 수없는 것 같아서 궁금합니다. 모든 도움을 주셔서 다시 한 번 감사드립니다! – IAmYourFaja
Ivy에는 표준 구성이 없습니다. 'ivy.xml' 파일에 설정을 정의해야합니다. 내 게시물에 언급 된 표준 것들은 Maven _scopes_에 매핑됩니다. 내 'ivy.xml'에 하나의 설정을 정의 할 수도 있고, 위에서 언급하지 않은 설정을 추가 할 수도 있습니다. 예를 들어, 어떤 사람들은 ivy.xml에 axis2 및 WSDL 파일과 같은 것들에 대해'generated-sources' 설정을 추가했습니다. 것은 당신의 설정을 repos 'config에 매핑해야합니다. 나는 한번도'* -> *'을 시도하지 않았다. 나는 당신의 모든 설정을'ivy.xml '에 모든 저장소 설정으로 매핑 해 놓았다고 생각한다. 나는 그것을 시도해야 할 것이다. –