home.


Tagged: ivy


apache-ivy-fetching

If your repository isn’t local or isn’t on the default maven reposistory on the internet, you’ll need to specify it in ivysettings.xml. Apache Ivy calls these ‘resolvers’:

<ivysettings>
  <settings defaultResolver="chain"/>
  <resolvers>
    <chain name="chain">
      <ibiblio name="central" m2compatible="true"/>
       <url name="denevell">
          <ivy      pattern="http://ivy.denevell.org/[organisation]/[module]/[revision]/ivy-[revision].xml" />
          <artifact pattern="http://ivy.denevell.org/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
        </url>
    </chain>
  </resolvers>
</ivysettings>

Note we’ve kept the ‘central’ ibiblio resolver. This is the one at mvnrespository.com.

The pattern matches how we published using ssh.

Then in ivy.xml you’ll say what you want to grab from that repository:

<ivy-module version="2.0">
  <info organisation="denevell" module="bws"/>
  <dependencies>
    <dependency org="denevell" name="BriefWebServer" rev="0.1"/>
  </dependencies>
</ivy-module>

So we’re looking at http://ivy.denevell.org/denevell/BriefWebServer/0.1/ivy-0.1.xml next to find the files to get back down. That file was generated when ivy published the module.

Then you can run ant to do the retrieving.

<project xmlns:ivy="antlib:org.apache.ivy.ant" name="SampleApp" default="resolve">
 <target name="resolve">
     <ivy:retrieve type="jar" pattern="libs/[artifact]-[revision].[ext]"/>
     <ivy:retrieve type="source" pattern="libs-non-dex/[artifact]-[revision]-[type].[ext]"/>
 </target>
</project>

These two retrieve lines get different tpyes, jar and source, and put them into different directories, libs and libs-non-dex, specifying their filename pattern.

The files will be in lib/ by default.

ant ivy ivy-fetching

apache-ivy-publishing-local-ssh

Apache Ivy can publish a set a files to a machine somewhere and then someone else can fetch them down with a command in an Apache Ant build script.

For example, Developer A publishes a jar and javadoc of Project Z at version 1.0. Developer B pull that down to use. Meanwhile, Developer A adds new features to Project Z as version 1.1. Developer B can take down those changes whenever ready.

Create a ivy.xml pointing at the files you want in the repo, say HELLO.txt.

<ivy-module version="2.0">
  <info organisation="denevell" module="ivytest"/>
  <publications>
    <artifact name="HELLO" ext="txt" type="doc"/>
  </publications>
</ivy-module>

The module name above is what you’ll call to grab these files down.

Then create the build.xml file that publishes it to the local repository.

<project name="ivytest" default="publish" xmlns:ivy="antlib:org.apache.ivy.ant">
  <target name="publish" description="Publishing">
      <ivy:resolve/>
      <ivy:publish pubrevision="1.1" status="release" resolver="local"  overwrite="true" update="true">
          <artifacts pattern="[artifact].[ext]"/>
      </ivy:publish>
  </target>
</project>

Now running ant will publish this to ~.ivy2/.

Or you can create an ivysettings.xml to specify that this should go in a ssh site. Change ‘resolver’ in your build.xml to the ‘name’ attribute in ssh.

<ivysettings> 
  <resolvers>
    <ssh name="ssh" publishPermission="0644"
      <artifact pattern="ssh://remoteusername@example.org:1234/your/remote/path/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
      <ivy      pattern="ssh://remoteusername@example.org:1234/your/remote/oath/[organisation]/[module]/[revision]/ivy-[revision].[ext]" />
      </ssh>
    </resolvers>
</ivysettings>

The [module]/[revision]/[artifact]-[revision].[ext] pattern is where we’re storing the files on the server.

The publishPermissions is to give everyone on the net read access.

ant ivy ivy-publishing

Page 1 of 1