简体   繁体   English

将ivy.xml转换为pom.xml

[英]Convert ivy.xml to pom.xml

I have a ivy.xml - https://gist.github.com/1898060 I also have the jar file related to this ivy.xml. 我有一个ivy.xml - https://gist.github.com/1898060我也有与这个ivy.xml相关的jar文件。 What i need is a mechanism to import this project to my maven repo and use it in my maven project. 我需要的是一个机制,将这个项目导入我的maven仓库并在我的maven项目中使用它。 SO basically if i am able to convert the ivy.xml to pom.xml , i might be able to get it work. 所以基本上如果我能够将ivy.xml转换为pom.xml,我可能能够让它工作。 Is there some mechanism through which i can achieve this. 是否有一些机制可以实现这一目标。 I am looking for something like a maven plugin to accomplish this task. 我正在寻找像maven插件这样的东西来完成这项任务。 I know that there are ways we can edit the ivy.xml and build.xml to achieve this but then i dont want to do it , as the project is in a private repo. 我知道有一些方法可以编辑ivy.xml和build.xml来实现这一点,但后来我不想这样做,因为该项目是在一个私人仓库中。

What you really need to do is publish the jars built by ANT project into your Maven repository. 您真正需要做的是将ANT项目构建的jar发布到Maven存储库中。

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

I know you don't want to change the ANT build, but creating an extra "publish" target will properly integrate your ANT and Maven projects. 我知道您不想更改ANT版本,但创建额外的“发布”目标将正确集成您的ANT和Maven项目。

The two jar artifacts, published by your modified ANT build, could be consumed normally as follows: 由修改后的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>

Modifications to your ANT build 对ANT构建的修改

ivy.xml 的ivy.xml

Main changes are to your publications section: 主要变化是您的出版物部分:

<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> 

Notes: 笔记:

  • The ANT project will now publish 3 files, jar, sources jar and the Maven POM ANT项目现在将发布3个文件,jar,sources jar和Maven POM
  • In Maven source jars have a "classifier" attributes that is set to "sources" (Not source). 在Maven源jar中有一个“分类器”属性,设置为“sources”(非源代码)。 To facilitate this we're adding an ivy extra attribute . 为方便起见,我们添加了常春藤额外属性
  • No need for version and status information in the info tag header. 信息标记标题中不需要版本和状态信息。 This will be added by the publication step. 这将由发布步骤添加。

build.xml 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>

Notes: 笔记:

  • The deliver task is optional, but recommended in case your ivy file contains dynamic revisions, such as "latest.release" or "latest.integration". 传递任务是可选的,但建议您的常春藤文件包含动态修订,例如“latest.release”或“latest.integration”。
  • The makepoms task has powerful support for convert ivy configurations into Maven scopes. makepoms任务强大支持将常春藤配置转换为Maven范围。 Does not apply in your case, but an incentive to learn more about ivy :-) 不适用于您的情况,但有动力了解更多常春藤:-)
  • The publish task uses a specified pattern to find files specified in ivy's publications section. 发布任务使用指定的模式来查找常春藤出版物部分中指定的文件。

ivysettings.xml ivysettings.xml

This is where you configure the location of the repositories and credentials to be used by publish build target. 您可以在此配置发布构建目标使用的存储库和凭据的位置。

<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>

Notes: 笔记:

  • Ivy downloads use the configured default resolver nexus-central . 常春藤下载使用配置的默认解析器nexus-central
  • The ivy publish task pushes to the Nexus repository called nexus-deploy 常春藤发布任务推送到名为nexus-deploy的Nexus存储库
  • The security realm in this example matches Nexus Maven. 此示例中的安全领域与Nexus Maven相匹配。 Would be different for other repo managers. 其他回购经理会有所不同。

Apache Ant itself provides a task to do this - makepom . Apache Ant本身提供了执行此操作的任务 - makepom Always helps to consult the documentation! 始终有助于查阅文档!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM