简体   繁体   English

常春藤对外部JAR的依赖

[英]ivy dependency on external JAR

I am battling with Ivy (I tried maven but had an event more difficult time setting up the JBoss repository for Hibernate). 我正在与Ivy作战(我尝试过Maven,但在为Hibernate设置JBoss存储库时遇到了更困难的事件)。

Quick question - I am using this wonderful package: http://ooweb.sourceforge.net/index.html 快速问题-我正在使用这个很棒的程序包: 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 不幸的是,JAR只能通过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? 有没有办法让Ivy下载特定的JAR?

For that matter, is it possible to do with Maven? 因此,可以使用Maven吗?

Or for that matter, how about Gradle? 或就此而言,Gradle怎么样?

Thank you! 谢谢! Misha 米莎

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. 我不能代表Ivy,但是使用Maven,有时您必须手动将JAR安装到存储库中,例如本地存储库,以及可能在构建软件时使用的存储库。

Download the jar to your drive, and do something like this on command line: 将jar下载到驱动器上,并在命令行上执行以下操作:

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. 选择一个您想要的更复杂的groupId,这是定义依赖项时将在pom中使用的。

Was there some specific issue you ran into when setting up the JBoss repo? 设置JBoss存储库时,您是否遇到过某些特定问题? I did it a while ago by just adding this at the end of a pom: 我前一阵子只是在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>

You can use ivy's packager resolver to turn any downloadable package into an ivy module. 您可以使用ivy的打包程序解析器将所有可下载的程序包转换为ivy模块。

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 的ivy.xml

Normal ivy file declaring a dependency against the ooweb module: 声明对ooweb模块有依赖性的普通ivy文件:

<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 ivysettings.xml

The Maven central repository is setup as the default repository. Maven中央存储库已设置为默认存储库。 The special "packager" resolver is used to retrieve the ooweb module. 特殊的“打包程序”解析程序用于检索ooweb模块。

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 packager.xml

Here is the magic. 这是魔术。 The resource declaration gives the location of the tar package. 资源声明给出了tar包的位置。 The build section contains the ANT instructions on which files to move into the module's artifacts section. 构建部分包含ANT指令,有关将哪些文件移入模块的工件部分。

<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. 注意:在后台,ivy使用XSLT样式表从打包程序声明中生成ANT脚本。 This ANT script will then download the artifact and place it into the ivy cache. 然后,此ANT脚本将下载工件,并将其放入常春藤缓存中。

Update 更新

Gradle embeds ivy, so this packager solution should work for two build technologies. Gradle嵌入了常春藤,因此此打包程序解决方案应适用于两种构建技术。 See this answer . 看到这个答案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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