问题
I am battling with Ivy (I tried maven but had an event more difficult time setting up the JBoss repository for Hibernate).
Quick question - I am using this wonderful package: http://ooweb.sourceforge.net/index.html
Unfortunately, the JAR is only available through Sourceforge: http://sourceforge.net/projects/ooweb/files/ooweb/0.8.0/ooweb-0.8.0-bin.tar.gz/download
Is there a way to get Ivy to download a specific JAR?
For that matter, is it possible to do with Maven?
Or for that matter, how about Gradle?
Thank you! Misha
回答1:
Let's see if I understood you correctly ..
I can't speak for Ivy, but with Maven, you will sometimes have to install JARs manually to a repository, such as your local and possibly the one used when building your software.
Download the jar to your drive, and do something like this on command line:
mvn install:install-file -Dfile=ooweb.jar -DgroupId=ooweb -DartifactId=ooweb -Dversion=0.8.0 -Dpackaging=jar
Pick a more sophisticated groupId is you want, these are what you'll use in your pom when defining the dependency.
Was there some specific issue you ran into when setting up the JBoss repo? I did it a while ago by just adding this at the end of a pom:
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jboss-snapshot</id>
<url>http://snapshots.jboss.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
回答2:
You can use ivy's packager resolver to turn any downloadable package into an ivy module.
See also the ivy roundup repository
My example project consists of the following files:
$ find . -type f
./build.xml
./ivy.xml
./ivysettings.xml
./repository/net.sourceforge/ooweb/0.8.0/packager.xml
ivy.xml
Normal ivy file declaring a dependency against the ooweb module:
<ivy-module version="2.0">
<info organisation="com.myspotontheweb" module="packager_demo"/>
<dependencies>
<dependency org="net.sourceforge" name="ooweb" rev="0.8.0"/>
</dependencies>
</ivy-module>
ivysettings.xml
The Maven central repository is setup as the default repository. The special "packager" resolver is used to retrieve the ooweb module.
The artifact pattern points at the packager file containing the instructions on how to download the module artifacts.
<ivysettings>
<settings defaultResolver="central"/>
<resolvers>
<ibiblio name="central" m2compatible="true"/>
<packager name="packager" buildRoot="${user.home}/.ivy2/packager/build" resourceCache="${user.home}/.ivy2/packager/cache" preserveBuildDirectories="false">
<ivy pattern="file:///${ivy.settings.dir}/repository/[organisation]/[module]/[revision]/ivy.xml"/>
<artifact pattern="file:///${ivy.settings.dir}/repository/[organisation]/[module]/[revision]/packager.xml"/>
</packager>
</resolvers>
<modules>
<module organisation="net.sourceforge" name="ooweb" resolver="packager"/>
</modules>
</ivysettings>
packager.xml
Here is the magic. The resource declaration gives the location of the tar package. The build section contains the ANT instructions on which files to move into the module's artifacts section.
<packager-module version="1.0">
<property name="name" value="${ivy.packager.module}"/>
<property name="version" value="${ivy.packager.revision}"/>
<property name="packagename" value="${name}-${version}"/>
<resource dest="archive" url="http://sourceforge.net/projects/ooweb/files/ooweb/0.8.0/ooweb-0.8.0-bin.tar.gz/download" sha1="d886a3d48bf4380cbec3e6f7de029f01e5c55315" type="tar.gz"/>
<build>
<move file="archive/${packagename}/lib/${packagename}.jar" tofile="artifacts/jars/${name}.jar"/>
</build>
</packager-module>
Note: Under the hood ivy uses an XSLT stylesheet to generate an ANT script from the packager declaration. This ANT script will then download the artifact and place it into the ivy cache.
Update
Gradle embeds ivy, so this packager solution should work for two build technologies. See this answer.
来源:https://stackoverflow.com/questions/2987108/ivy-dependency-on-external-jar