Getting a jar along with its sources and javadoc

天大地大妈咪最大 提交于 2019-12-22 10:58:52

问题


With the following in ivy.xml:

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

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

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

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

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

Update: Snippets from files that might be useful

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>

回答1:


Example

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

Note:

  • Ivy retrieve task uses a special pattern that puts files into different directories based on configuration.
  • The classifier attribute is optional therefore enclosed within brackets.

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>

Note:

  • The configuration mapping is comprised of 3 parts: "compile->default", "sources", "javadoc".

Update - Second example

Alternative directory layout this time:

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

Notes:

  • Observe how each retrieve task is customized to place files in a particular directory. The configuration is used to determine the files used. Configurations are a grouping mechanism.
  • Review again the "configuration mapping" on the dependency in the ivy file. This is the magic that determines how ivy classifies the downloaded files.
  • For more details on configuration mappings, see: How are maven scopes mapped to ivy configurations by ivy


来源:https://stackoverflow.com/questions/17260570/getting-a-jar-along-with-its-sources-and-javadoc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!