开发者

How to publish jars with different names to Ivy using Ant

I've just started using Ivy, and I'm really struggling as I've found the documentation and tutorials on the Apache site to be very confusing and not relevant to how I want to use it.

I want to publish some jar files to a local Ivy repository using Ant. The Ant script creates four jar files:

  • sed-ws-client.jar
  • sed-ws-client-src.jar
  • sed-enums.jar
  • sed-enums-src.jar

These jars should end up in two different directories in the Ivy repository (e.g. a sed-ws-client directory and a sed-enums directory). The repository currently contains 0.0.1 and 0.0.2 versions of these jars in the appropriate directories, with corresponding ivy-[version].xml files (this was done manually).

I'm having a lot of trouble figuring out how to construct the "publish" Ant target and the project's ivy.xml file. I'm forced to put a module name in the info tag of the ivy.xml file, but this would imply that I can only publish jars to one directory in the Ivy repository?

I've tried various things but the Ant build always fails. I just want a simple explanation of the steps I need to take to get it working. The repository structure can be changed if necessary.

Here's what I have so far:

ivy.xml file:

<ivy-module version="1.0">
<info organisation="myorg" module="SED" revision="1.0" status="dev"></info>

<publications>
    <!-- ws-client -->
    <artifact name="sed-ws-client"/>
    <artifact name="sed-ws-client" type="src"/>

    <!-- generated -->
    <artifact name="sed-enums"/>
    <artifact name="sed-enums" type="src"/>

</publications>

</ivy-module>

Ant target:

<target name="ivy-publish" description="Produce the ivy.xml file for the built jars">
    <ivy:settings file="d:/temp/ivy/iv开发者_开发知识库ysettings.xml" />
    <ivy:retrieve />
    <ivy:publish organisation="myorg" resolver="default" pubrevision="0.0.2" update="true">
        <artifacts pattern="${DEPLOY_DIR}/${sed.ws.client.jar}-[type].[ext]" />
        <artifacts pattern="${DEPLOY_DIR}/${sed.enums.jar}-[type].[ext]" />
    </ivy:publish>
</target>


I solved this with 2 ivy files, because my project publishes 2 module. And each module needs its own ivy.xml. This is my target for the second module, which has its own ivy file (ivy-SI.xml).

  <target name="ivy-publish-si">
    <ivy:settings file="${basedir}/../KS.build/ivysettings.xml" />
    <!--resolve ist need for publish -->
    <ivy:resolve
      file="ivy-SI.xml"
      revision="${project.version}"
      conf="compile"
    />
    <ivy:publish 
      srcivypattern="ivy-si.xml"
      resolver="jars.local" 
      conf="compile" 
      overwrite="true"
      revision="${project.version}">  
      <artifacts pattern="dist/[artifact]-[revision].[type]" />
    </ivy:publish>

The ivy-SI.xml is pretty standard:

<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info organisation="readybank" 
  module="KS.SessionInterface" 
  revision="${project.version}"
  status="integration"/>
<configurations>

    <conf name="compile" visibility="public"/>
    <conf name="run" visibility="public"/>
    <conf name="deploy" visibility="public"/>
</configurations>
<publications>
   <artifact name="KS.SessionInterface" type="jar" conf="compile" ext="jar"/>
</publications>
<dependencies>
</dependencies>

</ivy-module>


It's irrelevant how your artifacts stored in repository. Ivy looking for artifacts by module and artifact name. Usually you should think of one project as of one Ivy module. If your project produces two modules, the better way to divide this project in two. Module is logically consistent set of artifacts that changes together.

Your build fails because publish task could not find artifacts to publish.

For example, in this publish task:

<ivy:publish resolver="${ivy.repository}" update="true" overwrite="true">
  <artifacts pattern="${artifacts.dir}/[artifact].[ext]"/>
</ivy:publish>

we told Ivy to take artifacts with names and extensions as described in ivy.xml from ${artifacts.dir} folder and publish them. And ivy.xml in this case looks like this:

<ivy-module version="2.0">
<info organisation="apache" module="commons-cli" revision="1.2" status="release"/>
<configurations>
    <conf name="binary" description="provide only binary files"/>
    <conf name="development" extends="binary" description="provide binary files with javadoc and sources"/>
</configurations>
<publications>
    <artifact name="commons-cli" ext="jar" conf="binary" type="jar"/>
    <artifact name="commons-cli-javadoc" ext="jar" conf="development" type="javadoc"/>
    <artifact name="commons-cli-sources" ext="jar" conf="development" type="source"/>
</publications>

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜