Hi i am trying to build an ant script that copies a certain lib file based on a if condition. however it doesnt seem to work as i get this error:
build.xml:20: fileset doesn’t support the nested “if” element.
this is the part where it fails:
<target name="resolve">
<delete dir="${lib.dir}">
<include name="*" />
</delete>
<copy todir="${lib.dir}">
<fileset dir="ext-libs" >
<if name="${release}" value="true">
<include name="hello-client-[^DEBUG]*.jar" />
</if>
<else>
<include name="hello-client-*DEBUG.*.jar" />
</else>
</fileset>
</copy>
</target>
@JoseK is right. ANT filesets do not support nested “if” statements. In fact the “if” statement is not part of core ANT the recommended approach is to use conditional targets (See example)
@slipset is on the right track. Ivy configurations can be used to selectively choose your dependencies.
Example
This example is designed to be invoked in one of two ways
Or
build.xml
Notes:
ivy.xml
Note:
Appendix
How to use ivy configurations
Ivy configurations can be used to emulate Maven scopes, but in fact an ivy configuration can represent any logical grouping of dependencies.
Here are the 3 standard classpaths required in any Java build:
Note the “extends” syntax that enables you to create larger sets. For example, the runtime set of jars also includes anything needed to compile the code your code.
Ivy configurations are difficult to understand until you realise that they can be used to selectively populate an ANT path:
Or used to selectively populate a directory
Configuration mappings
Mappings are used to decide how groups of jars in your project relate to groups of jars in other projects.
This normally happens as follows:
Here our compile configuration is populate by the remote default configuration (normally the other modules compile dependencies)