How to publish custom jars to local Apache Ivy repository

心不动则不痛 提交于 2019-12-25 08:15:39

问题



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


回答1:


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.




回答2:


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>


来源:https://stackoverflow.com/questions/40247052/how-to-publish-custom-jars-to-local-apache-ivy-repository

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!