0
votes

I am using Ant+Ivy+Artifactory in my project, I try to publish my own repository, and my build.xml is like this:

<?xml version="1.0" encoding="UTF-8"?>
<project name="hello-world-ant" basedir="." default="main" xmlns:ivy="antlib:org.apache.ivy.ant">
<!-- Ant properties -->
<property name="src.dir"     value="src"/>
<property name="lib.dir"     value="lib"/>
<property name="build.dir"   value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir"     value="${build.dir}/jar"/>
<property name="main-class"  value="com.eureka.HelloWorld"/>

<ivy:settings file="./ivysettings.xml" />

<target name="clean">
  <delete dir="${build.dir}"/>
  <delete dir="${lib.dir}"/>
</target>

<target name="resolve">
  <ivy:retrieve/>
</target>    

<target name="report" depends="resolve">
  <ivy:report todir="${build.dir}"/>
</target>

<target name="compile" depends="report">
  <mkdir dir="${classes.dir}"/>
  <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>

<target name="jar" depends="compile">
  <mkdir dir="${jar.dir}"/>
  <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
    <manifest>
      <attribute name="Main-Class" value="${main-class}"/>
    </manifest>
  </jar>
</target>

<target name="run" depends="jar">
  <java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>

<target name="ivy">
      <ivy:resolve />

      <!-- Possible ivy:report, ivy:retrieve and other
      elements for managing your dependencies go here -->

      <ivy:deliver conf="*(public)"/> 
  </target>

   <target name="publish" depends="jar">
    <ivy:retrieve/>
      <ivy:publish resolver="publish" overwrite="true"    artifactspattern="${jar.dir}/[artifact].[ext]" />
    </target>

  <target name="clean-build" depends="clean,jar"/>

  <target name="main" depends="clean,run"/>

</project>

and my ivysettings.xml is like this:

<credentials host="localhost" realm="Artifactory Realm" username="admin" passwd="password" />

<resolvers>
<chain name="main">
  <ibiblio name="artifactory" m2compatible="true" root="http://localhost:8081/artifactory/libs-releases" />
  <url name="publish">
    <!-- You can use  m2compatible="true" instead of specifying your own pattern -->
    <ivy pattern="http://localhost:8081/artifactory/test-snapshot-local/[organization]/[module]/[revision]/ivy-[revision].xml" />
    <artifact pattern="http://localhost:8081/artifactory/test-snapshot-local/[organization]/[module]/[revision]/[artifact].[ext]"/>
  </url>
</chain>

when I do ant there is no problem, but when I do ant publish it shows the problem:

BUILD FAILED
/Users/stage/Documents/workspace/test_ivy/build.xml:56: impossible to publish artifacts for org.apache#hello-ivy;[email protected]: java.io.IOException: missing artifact org.apache#hello-ivy;20140401102841!hello-ivy.jar

I am new in using these tools, I want to know what happens here...thanks a lot~

1

1 Answers

3
votes

Assuming you are using the hello-ivy example mentioned in the Ivy quick start tutorial, the module defined in ivy.xml is hello-ivy while the project name you are using is hello-world-ant.
The artifactspattern used for publishing is ${jar.dir}/[artifact].[ext] which means Ivy will look for hello-ivy.jar while your build is creating a jar named hello-world-ant.jar (${ant.project.name}.jar).
Changing the module in ivy.xml to "hello-world-ant" will solve this issue.