简体   繁体   中英

Ivy Dependency (pull in directory of files)

Extreme edit to question to have it make more sense:

Let's assume that I need to use a local version of httpclient rather than one that I can just pull from an online repo (due to signing reasons). The way that I want to handle this is like so...

ivy.xml


<dependencies>  
    ...Other dependencies here
    <dependency org="com.apache" name="httpclient" rev="4.2.2" conf="compile->default" ext="jar" />
</dependencies>

ivysettings.xml


<settings defaultResolver="central"/>

<resolvers>
<url name="repo">
    <ivy pattern="http://myServer:8080/Repo/[organisation]/[artifact]/[revision]/ivy.xml" />
    <artifact pattern="http://myServer:8080/Repo/[organisation]/[artifact]/[revision]/[artifact].[ext]"/>
</url>

<url name="httpclient">
    <artifact pattern="http://myServer:8080/Repo/com.apache/httpclient/4.2.2/[artifact].[ext]"/>
</url>



<modules>
    <module organisation="com.apache" resolver="repo" />
    <module organisation="com.httpclient" resolver="httpclient" />
</modules>

Now what I'm hoping for here (and haven't been having much luck with) is the com.apache resolver looking for myServer:8080/Repo/com.apache/httpclient/4.2.2/ivy.xml and reading that, here's the contents of that file:

ivy.xml (in myServer:8080/repo/... directory)


    <dependency org="com.httpclient" name="commons-codec" rev="1.6" />
    <dependency org="com.httpclient" name="commons-logging" rev="1.1.1" />
    <dependency org="com.httpclient" name="fluent-hc" rev="4.2.2" />
    <dependency org="com.httpclient" name="httpclient" rev="4.2.2" />
    <dependency org="com.httpclient" name="httpclient-cache" rev="4.2.2" />
    <dependency org="com.httpclient" name="httpcore" rev="4.2.2" />
    <dependency org="com.httpclient" name="httpmime" rev="4.2.2"/>

The reasoning behind wanting to read the second xml file rather than including the markup in my first file is pretty obvious when you consider how many LOC that would add to something that we include frequently. It also makes all future includes easier as well.

Right now the error that I'm getting is:

Some projects fail to be resolved Impossible to resolve dependencies of com.myCompany#myProgramt;working@CompName unresolved dependency: com.apache#httpclient;4.2.2: not found


Thanks for your help on this matter.

When you configure your build to use the following resolver

 <ibiblio name="central" m2compatible="true"/>

You are telling ivy to download its dependencis from Maven Central

What is your objective here? To create a local ivy repo that functionally works like Maven Central? In that case the simplest solution would be to setup a Maven repository manager like: Nexus , Artifactory or Archiva . A maven repository manager can act like a smart cache and "proxy" jars stored in the Central Maven repo.

Configuring your build to use a local Maven Repository is easy:

 <ibiblio name="central" m2compatible="true" root="http://hostname:portnum/MavenRepo/>

Ivy expects to find all the dependencies of a given artifact in the same resolver. So, it finds the artifacts for com.apache in your repo resolver, and expects to find com.httpclient in there as well.

Ivy also will roll through your <ivy pattern.../> and <artifact pattern.../> statements in order within the same resolver declaration. You can use this to your advantage to create a single resolver which hits both repositories in the order you want:

<url name="amalgamation">
    <ivy pattern="http://myServer:8080/Repo/[organisation]/[artifact]/[revision]/ivy.xml" />
    <artifact pattern="http://myServer:8080/Repo/[organisation]/[artifact]/[revision]/[artifact].[ext]"/>
    <artifact pattern="http://myServer:8080/Repo/com.apache/httpclient/4.2.2/[artifact].[ext]"/>
</url>

What server are you using for your remote JAR repository?

Both Nexus and Artifactory can be setup to pull jars stored locally on themselves before puling ones from the remote repository. This way, you don't have to munge your ivysettings.xml . Instead, you simply download your preferred versions of the jars on Artifactory/Nexus. And, both are free, open source, downloads. It's way easier to do what you want with Artifactory/Nexus than futzing with your Ivy settings.

By the way, I have a Ivy project in Github you might want to look at. You simply attach this project to your Ant project, and it has everything automatically configured for Ivy. This way, an entire site can use Ivy for all of their projects, and everything is centrally controlled.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM