2


I've read all the tutorials and examples, and still cannot publish a set of custom jars in my local Ivy repository.
Edit: Basically I want the same behavior as maven-install-plugin.
Here's my setup. I have an Ant task which produces the jars in a given folder. The folder name is not fixed but rather passed as a property in file. I want to get all the jars in this folder and install them in my local Ivy repo so that I can use them on a next step.
Here is my Ant from where I call the ivy:publish:

<project name="Install Ivy Dependencies" xmlns:ivy="antlib:org.apache.ivy.ant" basedir="." default="publish">

    <loadproperties srcFile="path_to_folder.properties"/>

 <property name="file_pattern" value="${path_to_folder}/[artifact].[ext]" />
 <property name="pub_revision" value="1.0.0" />

   <target name="resolve">
        <ivy:configure file="ivysettings.xml" />
        <ivy:resolve file="ivy.xml" />
  </target>

 <target name="retrieve-all" depends="resolve">
        <ivy:retrieve pattern="${file_pattern}" conf="*" />
 </target>

 <target name="publish"  depends="retrieve-all">
        <ivy:publish resolver="local" organisation="myOrg" update="true" overwrite="true" pubrevision="${pub_revision}">
           <artifacts pattern="${file_pattern}"/>
        </ivy:publish>
 </target>
</project>


Here's my ivysettings.xml:

<ivysettings>
  <resolvers>
      <filesystem name="local" local="true"/>
    </resolvers>
</ivysettings>


And the ivy.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<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="myOrg" module="myModule" revision="1.0.0"/>
  <publications>
    <artifact name="my-custom-jar" ext="jar" type="jar"/>
    <artifact name="my-custom-jar-source" ext="jar" type="source"/>
  </publications>
</ivy-module>

The error that I am getting when I call the ant task is:
impossible to publish artifacts for myOrg#myModule;1.0.0: java.lang.IllegalStateException: impossible to publish myOrg#myModule;1.0.0!my-custom-jar.jar using local: no artifact pattern defined

Boyan
  • 589
  • 5
  • 19

2 Answers2

2

I've managed to run my scenario and to resolve my issues using this tutorial There were two major issues in my code/integration.
First one is that you cannot tell Ivy to publish the artifacts in its repository without providing a path to it. I did this with the filesystem resolver:

<filesystem name="local" local="true" transactional="local">
      <ivy pattern="${ivy.default.ivy.user.dir}/local/[module]/ivy-[revision].xml" />
      <artifact pattern="${ivy.default.ivy.user.dir}/local/[module]/[artifact]-[revision].[ext]" />
</filesystem>

The stupid think about it is this should be build in. If you copy it as is, then everything works. If the config is different, or pointing to a different location - nothing works and you are not told why. I read tons of docs about Apache Ivy and it was nowhere mentioned that these patterns should point to the local Ivy repository. I thought these were the paths from where the jars should be taken. I actually complained about this, but the Ivy documentation is very confusing. Also I think the examples there are wrong. Who would like to publish the artifacts in their ivy.settings.dir. In my case this directory was in my repository!

There was a second issue. It is a smaller one and again very hard to see and fix. There's something wrong the revision param and again the documentation is messed up. If you specify one and the same string for the revision and pub revision the artifacts aren't publish without any explanation why. I fixed it by removing the revision from ivy.xml file.

Last, but not least, I didn't manage to run successfully the "thing" as Ant task, but with java -jar $IVY_JAR ... Maybe the issue was because of the versions, but I was too tired to try it with the fix. P.S.@cantSleepNow thanks for the help.

Community
  • 1
  • 1
Boyan
  • 589
  • 5
  • 19
0

You need to add artifact pattern to resolver in ivysettings.xml, something like (example from ivy documentation):

<ivysettings>
  <resolvers>
      <filesystem name="local" local="true">
          <ivy pattern="${ivy.settings.dir}/1/[organisation]/[module]/ivys/ivy-[revision].xml"/>
        <artifact pattern="${ivy.settings.dir}/1/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
        </filesystem>
    </resolvers>
</ivysettings>
cantSleepNow
  • 9,691
  • 5
  • 31
  • 42
  • Ok, after fixing several small bugs in my ivysettings.xml this was able to run. Anyway it didn't publish the artifacts where I wanted to. It says this: [ivy:publish] published my-custom-jar.jar to /my-custom-jar.jar. What I want is Ivy to take the artifacts from /my-custom-jar.jar and publish them in the local cache/repository - just like maven-install-plugin – Boyan Oct 26 '16 at 16:22
  • @Boyan I just wrote an example resolver. Obviously you have to change the artifact pattern and ivy pattern in order to set the location. I have added a link in the answer – cantSleepNow Oct 26 '16 at 16:28
  • @canSleepNow, I know that your code is an example. My issue is that I don't fully understand Ivy publish. I have already read the Ivy documentation incl. the link you sent, but I am still not able to understand what should I put where. Should I specify the path to the local repo? This doesn't make sense since it is different for every system. Also where should I specify the path from where the local artifacts are taken and installed in the local repository? Regarding my ivy.xml file - it is static and I don't generate it. – Boyan Oct 27 '16 at 12:00