我是一个完全的Ivy新手,并且已经非常简单地尝试了它,用于获取常用的库,如Guava和Gson,这些库可以在Maven中央存储库中获得:
<ivy-module version="2.0">
<info organisation="com.company" module="foobar"/>
<dependencies>
<dependency org="com.google.guava" name="guava" rev="10.0.1"/>
<dependency org="com.google.code.gson" name="gson" rev="2.0"/>
</dependencies>
</ivy-module>
在Windows上,默认情况下,Ivy将其文件存储在%USERPROFILE%.ivy2cache
;在Unix-y系统上,它们在$HOME/.ivy2/
下下载。
我想这是一个非常基本的问题:如何告诉Ivy下载二进制文件和源代码,并将二进制jar文件放在一个(任意)目录中,而将源jar文件放在另一个目录?
例如,我希望Ivy将所有下载的二进制jar文件放在[project_home]/WebContent/WEB-INF/lib
中。
请注意,我是通过Ant使用Ivy的,按照下面的行,而不是IDE插件。
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="ivy" default="resolve" >
<target name="resolve" description="retrieve dependencies with ivy">
<ivy:retrieve/>
</target>
<path id="ivy.lib.path">
<fileset dir="tools/buildlibs" includes="*.jar"/>
</path>
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant" classpathref="ivy.lib.path"/>
</project>
另一个SO答案描述了如何使用配置来保持依赖项组的分离。然而,这个问题可能需要多次声明依赖项,以适应不同的ivy配置。
尝试以下操作:
<标题>中<ivy-module version="2.0">
<info organisation="com.company" module="foobar"/>
<configurations>
<conf name="sources" description="Source jars"/>
<conf name="binaries" description="binary jars"/>
</configurations>
<dependencies>
<dependency org="com.google.guava" name="guava" rev="10.0.1" conf="sources->sources"/>
<dependency org="com.google.code.gson" name="gson" rev="2.0" conf="sources->sources"/>
<dependency org="com.google.guava" name="guava" rev="10.0.1" conf="binaries->default"/>
<dependency org="com.google.code.gson" name="gson" rev="2.0" conf="binaries->default"/>
</dependencies>
</ivy-module>
<标题> build . xml <project xmlns:ivy="antlib:org.apache.ivy.ant" name="hello-ivy" default="resolve">
<target name="resolve" description="retrieve dependencies with ivy">
<ivy:retrieve conf="sources" pattern="lib/[conf]/[artifact](-[classifier]).[ext]"/>
<ivy:retrieve conf="binaries" pattern="lib/[conf]/[artifact](-[classifier]).[ext]"/>
</target>
<target name="clean" description="Remove build directories">
<delete dir="lib"/>
</target>
<target name="clean-all" depends="clean" description="clean ivy cache">
<ivy:cleancache />
</target>
</project>
注:更新添加目标清除常春藤缓存
Build按如下方式运行,以确保工件是最新下载的:
$ ant clean-all resolve
<标题> 结果$ find . -type f
./build.xml
./ivy.xml
./lib/sources/gson-sources.jar
./lib/sources/guava-sources.jar
./lib/binaries/gson.jar
./lib/binaries/jsr305.jar
./lib/binaries/guava.jar
证明源工件包含java文件:
$ unzip -t ./lib/sources/gson-sources.jar
Archive: ./lib/sources/gson-sources.jar
testing: META-INF/ OK
testing: META-INF/MANIFEST.MF OK
testing: com/ OK
testing: com/google/ OK
testing: com/google/gson/ OK
testing: com/google/gson/annotations/ OK
testing: com/google/gson/internal/ OK
testing: com/google/gson/internal/bind/ OK
testing: com/google/gson/reflect/ OK
testing: com/google/gson/stream/ OK
testing: com/google/gson/annotations/Expose.java OK
testing: com/google/gson/annotations/package-info.java OK
testing: com/google/gson/annotations/SerializedName.java OK
testing: com/google/gson/annotations/Since.java OK
testing: com/google/gson/annotations/Until.java OK
testing: com/google/gson/AnonymousAndLocalClassExclusionStrategy.java OK
testing: com/google/gson/Cache.java OK
testing: com/google/gson/CamelCaseSeparatorNamingPolicy.java OK
testing: com/google/gson/CompositionFieldNamingPolicy.java OK
testing: com/google/gson/DefaultTypeAdapters.java OK
testing: com/google/gson/DisjunctionExclusionStrategy.java OK
testing: com/google/gson/ExclusionStrategy.java OK
testing: com/google/gson/ExposeAnnotationDeserializationExclusionStrategy.java OK
testing: com/google/gson/ExposeAnnotationSerializationExclusionStrategy.java OK
testing: com/google/gson/FieldAttributes.java OK
testing: com/google/gson/FieldNamingPolicy.java OK
testing: com/google/gson/FieldNamingStrategy.java OK
testing: com/google/gson/FieldNamingStrategy2.java OK
testing: com/google/gson/FieldNamingStrategy2Adapter.java OK
testing: com/google/gson/Gson.java OK
testing: com/google/gson/GsonBuilder.java OK
testing: com/google/gson/GsonToMiniGsonTypeAdapterFactory.java OK
testing: com/google/gson/InnerClassExclusionStrategy.java OK
testing: com/google/gson/InstanceCreator.java OK
testing: com/google/gson/internal/$Gson$Preconditions.java OK
testing: com/google/gson/internal/$Gson$Types.java OK
testing: com/google/gson/internal/bind/ArrayTypeAdapter.java OK
testing: com/google/gson/internal/bind/BigDecimalTypeAdapter.java OK
testing: com/google/gson/internal/bind/BigIntegerTypeAdapter.java OK
testing: com/google/gson/internal/bind/CollectionTypeAdapterFactory.java OK
testing: com/google/gson/internal/bind/DateTypeAdapter.java OK
testing: com/google/gson/internal/bind/ExcludedTypeAdapterFactory.java OK
testing: com/google/gson/internal/bind/JsonElementReader.java OK
testing: com/google/gson/internal/bind/JsonElementWriter.java OK
testing: com/google/gson/internal/bind/MapTypeAdapterFactory.java OK
testing: com/google/gson/internal/bind/MiniGson.java OK
testing: com/google/gson/internal/bind/ObjectTypeAdapter.java OK
testing: com/google/gson/internal/bind/Reflection.java OK
testing: com/google/gson/internal/bind/ReflectiveTypeAdapterFactory.java OK
testing: com/google/gson/internal/bind/SqlDateTypeAdapter.java OK
testing: com/google/gson/internal/bind/StringToValueMapTypeAdapterFactory.java OK
testing: com/google/gson/internal/bind/TimeTypeAdapter.java OK
testing: com/google/gson/internal/bind/TypeAdapter.java OK
testing: com/google/gson/internal/bind/TypeAdapterRuntimeTypeWrapper.java OK
testing: com/google/gson/internal/bind/TypeAdapters.java OK
testing: com/google/gson/internal/ConstructorConstructor.java OK
testing: com/google/gson/internal/LazilyParsedNumber.java OK
testing: com/google/gson/internal/ObjectConstructor.java OK
testing: com/google/gson/internal/package-info.java OK
testing: com/google/gson/internal/Pair.java OK
testing: com/google/gson/internal/ParameterizedTypeHandlerMap.java OK
testing: com/google/gson/internal/Primitives.java OK
testing: com/google/gson/internal/Streams.java OK
testing: com/google/gson/internal/UnsafeAllocator.java OK
testing: com/google/gson/JavaFieldNamingPolicy.java OK
testing: com/google/gson/JsonArray.java OK
testing: com/google/gson/JsonDeserializationContext.java OK
testing: com/google/gson/JsonDeserializer.java OK
testing: com/google/gson/JsonDeserializerExceptionWrapper.java OK
testing: com/google/gson/JsonElement.java OK
testing: com/google/gson/JsonElementVisitor.java OK
testing: com/google/gson/JsonIOException.java OK
testing: com/google/gson/JsonNull.java OK
testing: com/google/gson/JsonObject.java OK
testing: com/google/gson/JsonParseException.java OK
testing: com/google/gson/JsonParser.java OK
testing: com/google/gson/JsonPrimitive.java OK
testing: com/google/gson/JsonSerializationContext.java OK
testing: com/google/gson/JsonSerializer.java OK
testing: com/google/gson/JsonStreamParser.java OK
testing: com/google/gson/JsonSyntaxException.java OK
testing: com/google/gson/LongSerializationPolicy.java OK
testing: com/google/gson/LowerCamelCaseSeparatorNamingPolicy.java OK
testing: com/google/gson/LowerCaseNamingPolicy.java OK
testing: com/google/gson/LruCache.java OK
testing: com/google/gson/ModifierBasedExclusionStrategy.java OK
testing: com/google/gson/ModifyFirstLetterNamingPolicy.java OK
testing: com/google/gson/package-info.java OK
testing: com/google/gson/RecursiveFieldNamingPolicy.java OK
testing: com/google/gson/reflect/package-info.java OK
testing: com/google/gson/reflect/TypeToken.java OK
testing: com/google/gson/SerializedNameAnnotationInterceptingNamingPolicy.java OK
testing: com/google/gson/stream/JsonReader.java OK
testing: com/google/gson/stream/JsonScope.java OK
testing: com/google/gson/stream/JsonToken.java OK
testing: com/google/gson/stream/JsonWriter.java OK
testing: com/google/gson/stream/MalformedJsonException.java OK
testing: com/google/gson/stream/StringPool.java OK
testing: com/google/gson/SyntheticFieldExclusionStrategy.java OK
testing: com/google/gson/UpperCamelCaseSeparatorNamingPolicy.java OK
testing: com/google/gson/UpperCaseNamingPolicy.java OK
testing: com/google/gson/VersionConstants.java OK
testing: com/google/gson/VersionExclusionStrategy.java OK
No errors detected in compressed data of ./lib/sources/gson-sources.jar.
标题>标题>标题>
~/。Ivy2只是ivy缓存
您必须为ivy retrieve
设置一个模式。这将定义在哪里下载依赖项。
<ivy:retrieve pattern="${project_home}/WebContent/WEB-INF/lib/[artifact].[ext]" conf="jars"/>
也许是第二次检索的来源:
<ivy:retrieve pattern="${project_home}/sources/[artifact].[ext]" conf="sources"/>
这也可以工作,并将源和jar的依赖关系放在不同的目录中:
<ivy:retrieve pattern="${project_home}/[conf]/[artifact].[ext]" conf="sources, jars"/>
这取决于在你的存储库中如何指定源/jar。
另外: taskdef必须在使用任务之前出现。
您应该将解析器定义为m2compatible:
<ibiblio name="maven2" m2compatible="true"/>
我也遇到过类似的问题,但是有一个更棘手的情况,所提供的解决方案不起作用。我有一个主ivy.xml
文件,没有定义配置,所以继承了默认的配置,你甚至没有注意到它(见文档)。在所有依赖项上应用新创建的"main"conf只会破坏构建。我别无选择,只能在另一个文件中定义一个新模块,比如ivy_extra.xml
,并将其加载到一个新的目标中,就这么简单!
示例文件:
<!-- ivy_extra.xml -->
<ivy-module version="2.0">
<info organisation="com.myorg" module="mymodule"/>
<configurations>
<conf name="download" visibility="private" />
</configurations>
<dependencies>
<dependency org="com.google.guava" name="guava" rev="10.0.1" conf="download->default"/>
</dependencies>
</ivy-module>
像这样载入你的build.xml
:
<target name="download-guava" description="Retrieve guava">
<echo>Retrieving guava</echo>
<ivy:resolve file="ivy_agent.xml"/>
<ivy:retrieve conf="download" type="jar" pattern="guava/[artifact]-[revision].jar"/>
</target>