问题
I have an artifact A installed in a local Maven repository.
Artifact A has a number of dependencies - properly specified in its pom.
If I set A as a dependency in a Maven project everything is ok - both A and its dependencies are correctly downloaded. This tells me that A is properly installed in the local Maven repo, and that its dependencies have been properly specified.
I also have a Ant/Ivy project. I have configured ivysettings.xml in the following way (following advice taken from another answer):
<ivysettings>
<settings defaultResolver="default"/>
<property name="m2-pattern" value="${user.home}/.m2/repository/[organisation]/[module]/[revision]/[module]-[revision](-[classifier]).[ext]" override="false" />
<resolvers>
<chain name="default">
<filesystem name="local-maven2" m2compatible="true" >
<artifact pattern="${m2-pattern}"/>
<ivy pattern="${m2-pattern}"/>
</filesystem>
<ibiblio name="central" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>
With this configuration, Ivy correctly downloads A, but not its dependencies (seems to completely ignore its pom file).
How should I have to change my setup in such a way dependencies as well will be downloaded?
回答1:
Maven and ivy repositories have different formats. Simplistically put Maven uses POM files, whereas ivy uses ivy files.
The good news is that ivy has a special iniblio resolver which is designed to understand the format of a Maven respository. The bad news is that it does assume such a repository is running remotely, for example using software like Nexus, Artifactory or Achiva.
For example:
<ivysettings>
<settings defaultResolver="repos" />
<resolvers>
<chain name="repos">
<ibiblio name="central" m2compatible="true"/>
<ibiblio name="my-releases" m2compatible="true" root="https://myhost/releases"/>
</chain>
</resolvers>
</ivysettings>
Demonstrates how to pull dependencies from both Maven central and a Maven repository running locally
In conclusion running a Maven repository locally is not hard and the very best way to share artifacts between all kinds of build technologies: Maven, ANT/ivy, Gradle, SBT, etc.
回答2:
Although Mark O'Connor answer is a proper answer and a reasonable way to solve the problem, I managed to find a different solution which implies imo a lesser overhead in terms of setup.
So, I converted the POM of artifact A to an Ivy file - via the Ant task ivy:convertpom
. Note that, contrary to the POM standard, the Ivy file should be named as follows: ivy-<your lib revision>.xml
.
Then, I just configured a local Ivy repository pointing to the folder where the artifact A and its Ivy file are located, such as:
<ivysettings>
<property name="my-local-ivy-dependencies-jars.repository" value="${user.dir}\..\my-local-ivy-dependencies-jars/lib"/>
<property name="my-local-ivy-dependencies-jars.pattern" value="${my-local-ivy-dependencies-jars.repository}/[organisation]/jars/[artifact]-[ revision].[ext]"/>
<settings defaultResolver="default"/>
<resolvers>
<chain name="default">
<filesystem name="my-local-ivy-dependencies-jars">
<ivy pattern="${my-local-ivy-dependencies-jars.pattern}" />
<artifact pattern="${my-local-ivy-dependencies-jars.pattern}" />
</filesystem>
<ibiblio name="central" m2compatible="true"/>
</chain>
</resolvers>
</ivysettings>
回答3:
To complement on Mark O'Connor's answer, you actually can use a local URL with the file://
scheme. The following works for me on Windows (note the triple slash after the scheme):
<ivysettings>
<settings defaultResolver="local-maven" />
<resolvers>
<ibiblio name="local-maven" m2compatible="true"
root="file:///c:/path/to/maven/repo"
pattern="[orgPath]/[module]/[revision]/[artifact]-[revision].[type]"/>
</resolvers>
</ivysettings>
My use of this was retrieving android sdk dependencies in an ant build with ivy.
来源:https://stackoverflow.com/questions/34766159/ivy-cannot-download-dependencies-of-artifact-located-in-a-local-maven-repostiory