获取 jar 及其源代码和 javadoc [英] Getting a jar along with its sources and javadoc

查看:23
本文介绍了获取 jar 及其源代码和 javadoc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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 SDK,类.

It downloads aws-java-sdk-1.4.5.jar and this is the AWS SDK, i.e. classes.

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

That's fine but I'd also like to get the Javadoc and sources.

遵循 Ivy:获取 Javadocs 和源的建议,我将以下内容放在 <代码>ivy.xml

Following advice from Ivy: Fetching Javadocs and Sources I put the following in 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(没有类或源文件).

It downloads aws-java-sdk-1.4.5.jar only and it is the Javadoc (no class or source files).

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

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

推荐答案

示例

├── 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-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 如何对下载的文件进行分类的魔法.
  • 有关配置映射的更多详细信息,请参阅:如何通过 ivy 将 Maven 范围映射到 ivy 配置

这篇关于获取 jar 及其源代码和 javadoc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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