动态更新常春藤额外的属性 [英] Dynamically updating Ivy extra attributes

查看:170
本文介绍了动态更新常春藤额外的属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我打算使用的文件的ivy.xml额外的属性,试图能够获得访问该版本号的部分,这是我需要做的,这样我可以再使用这些值在ivysettings解析器模式.xml文件:

I plan on using extra attributes in the ivy.xml files in an attempt to be able to get access to the revision number parts, which I need to do so that I can then use those values for the resolver pattern in the ivysettings.xml file:

<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:e="http://ant.apache.org/ivy/extra" xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
    <info organisation="MyCompany" module="MyModule" revision="1.2.3.4" e:shortrev="1.2.3" e:buildnum="4" publication="20120207140052" />
    ...
</ivy-module>

我要动态更新的 shortrev buildnum 在生成过程中的额外属性,所以,当这个模块被发表了他们的价值将随之被保存,也让我可以在解析器模式ivysettings.xml文件中使用这些额外的属性。

I want to dynamically update the shortrev and buildnum extra attribute during the build so that when this module gets published their values will be saved with it and also so that I can use those extra attributes in the ivysettings.xml file for the resolver pattern.

<resolvers>
    <filesystem name="fs.resolver">
        <ivy pattern="${my.dir}/[organisation]/[module]/[shortrev]/[buildnum]/ivy.xml" />
        <artifact pattern="${my.dir}/[organisation]/[module]/[shortrev]/[buildnum]/[artifact].[ext]" />
    </filesystem>
</resolvers>

这是建议,我可以尝试动态地设置其值常青藤文件中使用属性,但我米不清楚如何去这样做。

It was suggested that I could try to use properties within the Ivy file to dynamically set their values, but I'm not clear on how to go about doing that.

推荐答案

本例使用标准的从ANT buildnumber 任务。不幸的是,常春藤buildnumber 任务不会为模块妥善解决在解析器定义额外的属性: - (

This example uses the standard buildnumber task from ANT. Unfortunately the ivy buildnumber task will not resolve properly for modules with extra attributes in the resolver definition :-(

$ tree
.
|-- build.xml
|-- ivysettings.xml
|-- ivy.xml
`-- src
    `-- main
        `-- HelloWorld.java

的ivy.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<ivy-module version="2.0" xmlns:e="http://ant.apache.org/ivy/extra">
    <info organisation="MyCompany" module="MyModule" e:shortrev="${publish.target.revision}" e:buildnum="${publish.buildnumber}"/>

    <configurations defaultconfmapping="compile->default">
        <conf name="compile" description="Required to compile application"/>
        <conf name="runtime" description="Shared library needed at runtime" extends="compile"/>
        <conf name="test"    description="Required for test only" extends="runtime"/>
    </configurations>

    <publications>
        <artifact name="MyModule" type="jar" e:shortrev="${publish.target.revision}" e:buildnum="${publish.buildnumber}"/>
    </publications>

    <dependencies>
        <dependency org="commons-lang" name="commons-lang" rev="2.6"/>
        <dependency org="junit" name="junit" rev="4.8.2" conf="test->default"/>
    </dependencies>

</ivy-module>

注:


  • 额外的属性是两个的信息和工件的定义有关。

  • The extra attributes are associated with both the info and artifact definitions.
<project xmlns:ivy="antlib:org.apache.ivy.ant" name="publish-example" default="build">

    <!--
    ==========
    Properties
    ==========
    -->
    <property name="src.dir"     location="src/main"/>
    <property name="build.dir"   location="build"/>
    <property name="classes.dir" location="${build.dir}/classes"/>
    <property name="reports.dir" location="${build.dir}/reports"/>

    <property name="publish.target.revision" value="1.2.3"/>
    <property name="publish.status"   value="release"/>
    <property name="publish.resolver" value="custom.repository"/>

    <!--
    =======
    Targets
    =======
    -->
    <target name='init' description='Resolve project dependencies and set classpaths'>
        <ivy:resolve/>
        <ivy:report todir='${reports.dir}' graph='false' xml='false'/>

        <ivy:cachepath pathid="compile.path"  conf="compile"/>
        <ivy:cachepath pathid="runtime.path"  conf="runtime"/>
        <ivy:cachepath pathid="test.path"     conf="test"/>

        <mkdir dir="${classes.dir}"/>
    </target>

    <target name="compile" depends="init">
        <javac srcdir="${src.dir}" destdir="${classes.dir}" includeantruntime="false" classpathref="compile.path"/>
    </target>

    <target name="build" depends="compile">
        <ivy:info/>
        <jar destfile="${build.dir}/${ivy.module}.jar" basedir="${classes.dir}"/>
    </target>

    <target name="publish-revision" description="Determine the new published revision">
        <buildnumber/>

        <property name="publish.revision" value="${publish.target.revision}.${build.number}"/>
        <property name="publish.buildnumber" value="${build.number}"/>
    </target>

    <target name="publish" depends="build,publish-revision" description="Publish artifacts into repository">
        <ivy:deliver deliverpattern="${build.dir}/ivy.xml" pubrevision="${publish.revision}" status="${publish.status}"/>

        <ivy:publish resolver="${publish.resolver}" pubrevision="${publish.revision}" overwrite="true">
            <artifacts pattern="${build.dir}/[artifact].[ext]"/>
        </ivy:publish>
    </target>

    <target name="clean" description="--> clean project files">
        <delete dir="${build.dir}"/>
    </target>

    <target name="clean-all" depends="clean" description="--> clean ivy cache">
        <ivy:cleancache />
    </target>

</project>

注:


  • 常春藤提供任务确保公布常青藤文件正确填充。

  • The ivy deliver task ensures that the published ivy file is properly populated.
<ivysettings>
    <settings defaultResolver="central"/>
    <resolvers>
        <ibiblio name="central" m2compatible="true"/>
        <filesystem name="custom.repository">
            <ivy pattern="${ivy.settings.dir}/repository/[organisation]/[module]/[shortrev]/[buildnum]/ivy.xml" />
            <artifact pattern="${ivy.settings.dir}/repository/[organisation]/[module]/[shortrev]/[buildnum]/[artifact].[ext]" />
        </filesystem>
    </resolvers>
</ivysettings>

注:


  • 我总是设置Maven的中央作为我的默认的解析器,以获取第三方的依赖像公地郎和JUnit。

  • custom.repository 解析器是构建文件属性publish.resolver中配置

  • I always setup Maven Central as my default resolver, in order to retrieve 3rd party dependencies like commons-lang and junit.
  • The custom.repository resolver is configured within the build file as the property "publish.resolver"

这篇关于动态更新常春藤额外的属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆