Reputation: 2376
I'm trying to use Ivy to automatically download the JAR files needed to run PMD and Findbugs. For the most part I have no problem downloading the dependencies, setting up a cachepath
, and so on. The thing is, if I'm using Ant to run PMD I only want to download the PMD dependencies, and similar for Findbugs. So I made two different XML files defining the dependencies, conf/ivy/pmd.xml
and conf/ivy/findbugs.xml
, and my PMD task I have something like:
<ivy:retrieve file="conf/ivy/pmd.xml"/>
<ivy:cachepath pathid="pmd.path"/>
This works fine if in a single Ant invocation I only use PMD or only use Findbugs. However, if I try to use both in a single invocation then the second ivy:cachepath
task to run acts exactly the same as the first one to run, even though they have different file
attributes.
Upvotes: 3
Views: 539
Reputation: 5234
Each time you call retrieve Ivy will set some ant properties. Ant properties are immutable, so this means you can only call retrieve once.
However, you can workaround this by using AntCall. Each time you use the AntCall task you start with a clean slate in regards to ant properties. Beware that AntCall also clears the slate in regards to what targets have already run, so all targets in depends will be run again.
<target name="resolve" description="">
<antcall target="resolve.ivyfile1"/>
<antcall target="resolve.ivyfile2"/>
</target>
<target name="resolve.ivyfile1" description="">
<ivy:retrieve file="ivy1.xml"/>
</target>
<target name="resolve.ivyfile2" description="">
<ivy:retrieve file="ivy2.xml"/>
</target>
This will also have effects on ivy Publishes and Reports, but those aspects will vary based on your exact usage scenario so they're best elaborated on in a new question.
Upvotes: 0
Reputation: 2376
The problem is that the Ivy retrieve
task is a post resolve taks and automatically/implicitly runs the resolve
task if it hasn't been run yet, so the first retrieve
task is the only one to cause a resolve.
The solution is to put all dependencies into a single Ivy module configuration file, make the different dependencies part of different configurations, and then use the conf
attribute when invoking the retrive
tasks. For instance, I set up "findbugs" conf and a "pmd" conf in the single file conf/ivy/ivy.xml
:
<ivy-module version="2.0">
<info organisation="com.nightrealms" module="JavaLike"/>
<configurations>
<conf name="findbugs" description="findbugs JAR files"/>
<conf name="pmd" description="PMD JAR files"/>
</configurations>
<dependencies>
<dependency org="net.sourceforge.pmd" name="pmd-core" rev="5.3.2"
conf="pmd->default"/>
<dependency org="net.sourceforge.pmd" name="pmd-java" rev="5.3.2"
conf="pmd->default"/>
<dependency org="com.google.code.findbugs" name="findbugs"
rev="3.0.1" conf="findbugs->default"/>
</dependencies>
</ivy-module>
Then in build.xml
:
<ivy:retrieve file="conf/ivy/ivy.xml" conf="findbugs"/>
Upvotes: 3