【问题标题】:Getting a jar along with its sources and javadoc获取一个 jar 及其源代码和 javadoc
【发布时间】:2013-06-20 01:55:15
【问题描述】:

ivy.xml:

<dependency org="com.amazonaws" name="aws-java-sdk" rev="1.4.5">
     <artifact name="aws-java-sdk" ext="jar"/>
</dependency>

它会下载 aws-java-sdk-1.4.5.jar,这是 AWS 开发工具包,类。

没关系,但我也想获取 Javadoc 和源代码。

根据Ivy: Fetching Javadocs and Sources 的建议,我将以下内容放入ivy.xml

<configurations>
    <conf name="default" />
    <conf name="compile" visibility="public"/>
    <conf name="sources" visibility="public"/>
    <conf name="javadoc" visibility="public"/>
</configurations>

<dependency org="com.amazonaws" name="aws-java-sdk" 
rev="1.4.5" transitive="true" 
conf="javadoc->javadoc;sources->sources;compile->default"/>

它只下载aws-java-sdk-1.4.5.jar,它是Javadoc(没有类或源文件)。

更新:可能有用的文件片段

build.xml

<project name="aws-project" basedir="." xmlns:ivy="antlib:org.apache.ivy.ant">

<target name="build" depends="clean,configure-ivy-settings,artifactory-retrieve">

ivy-config.xml

<project name="artifactory-bootstrap" xmlns:ac="http://ant-contrib.sourceforge.net" xmlns:ivy="antlib:org.apache.ivy.ant" default="configure-ivy-settings">

<target name="configure-ivy-settings" unless="skip.artifact.retrieve">

    <echoproperties prefix="ivy" />

    <!-- Change this to point to the branch in artifactory -->

    <property name="artifactory.branch" value="20.0" />

    <!-- Change this to the SRCROOT of your build -->
    <property name="build.srcroot" value="${bootstrap.basedir}" />

    <!-- Configure IVY Settings -->

    <ivy:settings url="https://artifactory.mycompany.com/artifactory/simple/bootstrap/${artifactory.branch}/ivysetting-artifactory.xml" id="artifactory.ivy.settings" host="artifactory.mycompany.com" realm="Artifactory Realm" username="${artifactory.user}" passwd="${artifactory.password}" />
</target>

<target name="artifactory-retrieve" unless="skip.artifact.retrieve">

    <property name="download.dir" value="${bootstrap.basedir}/extlib" />
    <delete dir="${download.dir}" />
    <mkdir dir="${download.dir}" />

    <ivy:resolve settingsRef="artifactory.ivy.settings" file="${ivy.file}" />
    <ivy:cachefileset settingsRef="artifactory.ivy.settings" setid="latest.downloads" />

    <echo message="Artifacts are available at : ${download.dir}" />

    <copy flatten="true" todir="${download.dir}">
        <fileset refid="latest.downloads" />
    </copy>

    <fileset id="ivy.fileset" dir="${download.dir}">
        <include name="*.jar" />
    </fileset>

    <property name="ivy.downloads.fileset" refid="ivy.fileset" />

    <!-- Construct classpath to downloads //-->

    <path id="ivy.classpath">
        <fileset dir="${download.dir}">
            <include name="*.jar" />
        </fileset>
    </path>

    <property name="ivy.downloads.classpath" refid="ivy.classpath" />
    <echo message="ivy.downloads.classpath=${ivy.downloads.classpath}"/>


    <echo message="Artifacts are available at : ${download.dir}" />
    <echo message="They can be referenced using fileset refid ivy.downloads.fileset or ivy.downloads.classpath" />
</target>

【问题讨论】:

    标签: amazon-web-services ant javadoc ivy artifactory


    【解决方案1】:

    示例

    ├── build
    │   └── lib
    │       ├── compile
    │       │   ├── aws-java-sdk-1.4.5.jar
    │       │   ├── commons-codec-1.3.jar
    │       │   ├── commons-logging-1.1.1.jar
    │       │   ├── httpclient-4.1.jar
    │       │   ├── httpcore-4.1.jar
    │       │   ├── jackson-core-asl-1.8.9.jar
    │       │   └── jackson-mapper-asl-1.8.9.jar
    │       ├── javadoc
    │       │   └── aws-java-sdk-1.4.5-javadoc.jar
    │       └── sources
    │           └── aws-java-sdk-1.4.5-sources.jar
    ├── build.xml
    └── ivy.xml
    

    build.xml

    <project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
    
        <target name="build" description="Compile code">
            <ivy:retrieve pattern="build/lib/[conf]/[artifact]-[revision](-[classifier]).[ext]"/>
        </target>
    
        <target name="clean" description="Additionally purge ivy cache">
            <delete dir="build"/>
            <ivy:cleancache/>
        </target>
    
    </project>
    

    注意:

    • Ivy 检索任务使用一种特殊模式,根据配置将文件放入不同的目录。
    • 分类器属性是可选的,因此用括号括起来。

    ivy.xml

    <ivy-module version="2.0">
        <info organisation="com.myspotontheweb" module="demo"/>
    
        <configurations>
            <conf name="compile" description="Required to compile application"/>
            <conf name="sources" description="Source code"/>
            <conf name="javadoc" description="Javadocs"/>
        </configurations>
    
        <dependencies>
            <dependency org="com.amazonaws" name="aws-java-sdk" rev="1.4.5" conf="compile->default;sources;javadoc"/>
        </dependencies>
    
    </ivy-module>
    

    注意:

    • 配置映射由 3 部分组成:“compile->default”、“sources”、“javadoc”。

    更新 - 第二个示例

    这次的替代目录布局:

    ├── build
    │   ├── doc
    │   │   └── aws-java-sdk-1.4.5-javadoc.jar
    │   ├── lib
    │   │   ├── aws-java-sdk-1.4.5.jar
    │   │   ├── commons-codec-1.3.jar
    │   │   ├── commons-logging-1.1.1.jar
    │   │   ├── httpclient-4.1.jar
    │   │   ├── httpcore-4.1.jar
    │   │   ├── jackson-core-asl-1.8.9.jar
    │   │   └── jackson-mapper-asl-1.8.9.jar
    │   └── src
    │       └── aws-java-sdk-1.4.5-sources.jar
    ├── build.xml
    └── ivy.xml
    

    build.xml

    <project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">
    
        <target name="build" description="Compile code">
            <ivy:retrieve pattern="build/lib/[artifact]-[revision].[ext]" conf="compile"/>
            <ivy:retrieve pattern="build/src/[artifact]-[revision](-[classifier]).[ext]" conf="sources"/>
            <ivy:retrieve pattern="build/doc/[artifact]-[revision](-[classifier]).[ext]" conf="javadoc"/>
        </target>
    
        <target name="clean" description="Additionally purge ivy cache">
            <delete dir="build"/>
            <ivy:cleancache/>
        </target>
    
    </project>
    

    注意事项:

    • 观察如何自定义每个检索任务以将文件放置在特定目录中。配置用于确定使用的文件。配置是一种分组机制。
    • 再次查看 ivy 文件中依赖项的“配置映射”。这就是决定 ivy 如何对下载的文件进行分类的魔力。
    • 有关配置映射的更多详细信息,请参阅:How are maven scopes mapped to ivy configurations by ivy

    【讨论】:

    • 感谢您的全面回答,但我认为我不能使用它,因为我使用的是
    • @PatrickKiernan Artifactory 检索???我不知道 artifactory 有它自己的 ANT 插件。您是否在 build.xml 的顶部声明了以下命名空间:“xmlns:artifactory="antlib:org.apache.ivy.ant"?如果是,那么您仍在使用 ivy,只是使用不同的 XML 命名空间。
    • @PatrickKiernan 您缺少的关键点是常春藤配置的使用。常春藤“检索”任务用于将文件放在文件系统中的某个位置。您的示例以更复杂的方式执行此操作。
    • @PatrickKiernan 我提供了第二个使用 ivy 检索任务的示例。显式使用配置来确定文件在文件系统上的放置位置。
    猜你喜欢
    • 2014-07-07
    • 2023-03-20
    • 1970-01-01
    • 2011-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多