While resolving Spring dependencies using ANT + Apache Ivy, the build fails during ivy:retrieve with the following error:
impossible to ivy retrieve: java.lang.RuntimeException: problem during retrieve of demo#spring-ant-broadcom-demo: java.lang.RuntimeException: Multiple artifacts of the module org.springframework#spring-context;5.3.34 are retrieved to the same file! Update the retrieve pattern to fix this error.
at org.apache.ivy.core.retrieve.RetrieveEngine.retrieve(RetrieveEngine.java:238)
at org.apache.ivy.Ivy.retrieve(Ivy.java:561)
at org.apache.ivy.ant.IvyRetrieve.doExecute(IvyRetrieve.java:113)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:259)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
This typically happens when downloading artifacts from an enterprise repository (e.g., Broadcom Spring Enterprise repo) and retrieving them into a local lib/ folder.
The ivy:retrieve pattern in build.xml maps different artifacts from the same module to the same destination filename.
For example, Ivy may retrieve:
If the retrieve pattern does not include the classifier, Ivy tries to save both artifacts with the same name (e.g., spring-context-5.3.34.jar), causing a collision and the runtime exception.
Update the ivy:retrieve pattern to include the classifier so that different artifacts are written to different filenames. Example, below is an ivy retrieve pattern to download different artifacts separated by module folder.
<ivy:retrieve
pattern="${lib.dir}/[organisation]/[module]/[artifact]-[revision](-[classifier]).[ext]"/>