将ivy.xml转换为pom.xml

时间:2012-02-24 05:46:02

标签: java maven ivy

我有一个ivy.xml - https://gist.github.com/1898060 我还有与此ivy.xml相关的jar文件。 我需要的是一个机制,将这个项目导入我的maven仓库并在我的maven项目中使用它。 所以基本上如果我能够将ivy.xml转换为pom.xml,我可能能够让它工作。 是否有一些机制可以实现这一目标。 我正在寻找像maven插件这样的东西来完成这项任务。 我知道有一些方法可以编辑ivy.xml和build.xml来实现这一点,但后来我不想这样做,因为该项目是在私人仓库中。

2 个答案:

答案 0 :(得分:17)

您真正需要做的是将ANT项目构建的jar发布到您的Maven存储库中。

ant -Dproject.version=0.9.0-local-20120211095554 clean publish

我知道您不想更改ANT版本,但创建额外的“发布”目标将正确集成您的ANT和Maven项目。

由修改后的ANT版本发布的两个jar工件可以正常使用,如下所示:

<dependency>
    <groupId>com.opengamma</groupId>
    <artifactId>og-analytics</artifactId>
    <version>0.9.0-local-20120211095554</version>
</dependency>

<dependency>
    <groupId>com.opengamma</groupId>
    <artifactId>og-analytics</artifactId>
    <version>0.9.0-local-20120211095554</version>
    <classifier>sources</classifier>
</dependency>

对ANT构建的修改

的ivy.xml

主要更改是您的出版物部分:

<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    <info organisation="com.opengamma" module="og-analytics"/>

    <publications>
      <artifact name="og-analytics" type="jar"/>
      <artifact name="og-analytics" type="pom"/>
      <artifact name="og-analytics" type="jar" e:classifier="sources"/>
    </publications>

    <dependencies>
      <dependency name="og-util" rev="0.9.0-local-20120211095525" revConstraint="latest.integration"/>

      <dependency org="org.jfree" name="jfreechart" rev="1.0.13"/>
      <dependency org="cern" name="colt" rev="1.2.0"/>
      <dependency org="cern" name="parallelcolt" rev="0.9.1"/>
      <dependency org="latexlet" name="latexlet" rev="1.11"/>
      <dependency org="org.apache.commons" name="commons-math" rev="2.1"/>

      <dependency org="it.dexy" name="json-doclet" rev="0.3.1"/>
      <dependency org="org.json" name="simple" rev="1.1"/>
      <exclude org="org.junit"/>
    </dependencies>
</ivy-module> 

注意:

  • ANT项目现在将发布3个文件,jar,sources jar和Maven POM
  • 在Maven源jar中有一个“分类器”属性,设置为“sources”(非源代码)。为方便起见,我们添加了ivy extra attribute
  • info 标记标题中不需要版本和状态信息。这将由出版步骤添加。

的build.xml

<target name="prepare" description="Generate POM">
    <fail message="Unset property: project.version" unless="project.version"/>

    <ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${project.version}" status="release"/>

    <ivy:makepom ivyfile="${build.dir}/ivy.xml" pomfile="${build.dir}/${ivy.module}.pom"/>
</target>

<target name="publish" depends="build,prepare" description="Upload to Nexus">
    <ivy:publish resolver="nexus-deploy" pubrevision="${project.version}" overwrite="true" publishivy="false" >
        <artifacts pattern="${build.dir}/[artifact](-[classifier]).[ext]"/>
    </ivy:publish>
</target>

注意:

  • deliver任务是可选的,但建议您的常春藤文件包含动态修订,例如“latest.release”或“latest.integration”。
  • makepoms任务强大支持将常春藤配置转换为Maven范围。不适用于您的情况,但有动机了解更多关于常春藤: - )
  • publish任务使用指定的模式查找常春藤出版物部分中指定的文件。

ivysettings.xml

您可以在此处配置发布构建目标使用的存储库和凭据的位置。

<ivysettings>
    <settings defaultResolver="nexus-central"/>
    <credentials host="somehost" realm="Sonatype Nexus Repository Manager" username="????" passwd="????"/>
    <resolvers>
        <ibiblio name="nexus-central" root="http://somehost/nexus/content/repositories/central/" m2compatible="true"/>
        <ibiblio name="nexus-deploy" root="http://somehost/nexus/content/repositories/repo" m2compatible="true"/>
    </resolvers>
</ivysettings>

注意:

  • 常春藤下载使用配置的默认解析器 nexus-central
  • 常春藤发布任务推送到名为 nexus-deploy 的Nexus存储库
  • 此示例中的安全领域与Nexus Maven相匹配。其他回购经理会有所不同。

答案 1 :(得分:3)

Apache Ant本身提供了执行此操作的任务 - makepom。总是有助于查阅文档!