gpt4 book ai didi

ivy - 解释如何使用文件系统解析器的示例示例

转载 作者:行者123 更新时间:2023-12-03 23:30:33 25 4
gpt4 key购买 nike

任何人都可以通过考虑来解释我如何在 Ivy 中使用文件系统解析器和示例。

  • 我有 ivy.xml 文件,我在其中定义了所有依赖项,但我希望我的文件系统中的 jars 不是来自 maven 存储库..?
  • 我在哪里放置 ivysettings.xml 文件。
  • build.xml 应该包含什么才能使用 ivysettings.xml 以便我可以使用来自文件系统而不是来自 maven 的 jar ..
  • 最佳答案

    ivysettings.xml 文件默认位于与 相同的目录中。 Ivy .xml 文件。

    可以使用 ivy settings task 指定替代位置

    项目结构

    位于 中的第 3 方依赖项库 目录。

    $ tree
    .
    |-- build.xml
    |-- ivysettings.xml
    |-- ivy.xml
    |-- lib
    | |-- junit-4.10.jar
    | |-- slf4j-api-1.6.4.jar
    | `-- slf4j-simple-1.6.4.jar
    `-- src
    |-- main
    | `-- java
    | `-- org
    | `-- demo
    | `-- App.java
    `-- test
    `-- java
    `-- org
    `-- demo
    `-- AppTest.java

    10 directories, 8 files

    Ivy .xml

    这个 ivy 文件使用配置来管理 3 种依赖项:
  • 编译
  • 运行时间
  • 测试

  • 这些将对应于 ANT 构建使用的类路径。
    <ivy-module version="2.0">
    <info organisation="com.myspotontheweb" module="demo"/>

    <configurations defaultconfmapping="compile->default">
    <conf name="compile" description="Required to compile application"/>
    <conf name="runtime" description="Additional run-time dependencies" extends="compile"/>
    <conf name="test" description="Required for test only" extends="runtime"/>
    </configurations>

    <dependencies>
    <!-- compile dependencies -->
    <dependency org="org.slf4j" name="slf4j-api" rev="1.6.4"/>

    <!-- runtime dependencies -->
    <dependency org="org.slf4j" name="slf4j-simple" rev="1.6.4" conf="runtime->default"/>

    <!-- test dependencies -->
    <dependency org="junit" name="junit" rev="4.10" conf="test->default"/>
    </dependencies>

    </ivy-module>

    Ivy 设置.xml

    没有什么花哨。简单映射到位于 中的 jar 库 目录:
    <ivysettings>
    <settings defaultResolver="local"/>
    <resolvers>
    <filesystem name="local">
    <artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/>
    </filesystem>
    </resolvers>
    </ivysettings>

    或者.....我将始终包含非本地 jar 的 Maven 中央存储库,如下所示:
    <ivysettings>
    <settings defaultResolver="central"/>
    <resolvers>
    <ibiblio name="central" m2compatible="true"/>
    <filesystem name="local">
    <artifact pattern="${ivy.settings.dir}/lib/[artifact]-[revision].[ext]"/>
    </filesystem>
    </resolvers>
    <modules>
    <module organisation="org.slf4j" resolver="local"/>
    <module organisation="junit" name="junit" resolver="local"/>
    </modules>
    </ivysettings>

    模块 部分指定应在本地检索哪些 jar。

    构建.xml

    最后是使用 ivy 管理类路径的构建逻辑。
    <project name="demo" default="build" xmlns:ivy="antlib:org.apache.ivy.ant">

    <!--
    ================
    Build properties
    ================
    -->
    <property name="src.dir" location="src/main/java"/>
    <property name="test.src.dir" location="src/test/java"/>
    <property name="build.dir" location="build"/>
    <property name="classes.dir" location="${build.dir}/classes"/>
    <property name="test.classes.dir" location="${build.dir}/test-classes"/>
    <property name="ivy.reports.dir" location="${build.dir}/ivy-reports"/>
    <property name="test.reports.dir" location="${build.dir}/test-reports"/>

    <!--
    ===========
    Build setup
    ===========
    -->
    <target name="init">
    <ivy:resolve/>

    <ivy:report todir='${ivy.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}"/>
    <mkdir dir="${test.classes.dir}"/>
    <mkdir dir="${test.reports.dir}"/>
    </target>

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

    <target name="compile-tests" depends="compile">
    <javac srcdir="${test.src.dir}" destdir="${test.classes.dir}" includeantruntime="false" debug="true">
    <classpath>
    <path refid="test.path"/>
    <pathelement path="${classes.dir}"/>
    </classpath>
    </javac>
    </target>

    <!--
    ============
    Test targets
    ============
    -->
    <target name="test" depends="compile-tests">
    <junit printsummary="yes" haltonfailure="yes">
    <classpath>
    <path refid="test.path"/>
    <pathelement path="${classes.dir}"/>
    <pathelement path="${test.classes.dir}"/>
    </classpath>
    <formatter type="xml"/>
    <batchtest fork="yes" todir="${test.reports.dir}">
    <fileset dir="${test.src.dir}">
    <include name="**/*Test*.java"/>
    <exclude name="**/AllTests.java"/>
    </fileset>
    </batchtest>
    </junit>
    </target>

    <!--
    =====================
    Build and run targets
    =====================
    -->
    <target name="build" depends="test"/>

    <target name="run" depends="build">
    <java classname="org.demo.App">
    <classpath>
    <path refid="runtime.path"/>
    <pathelement location="${classes.dir}"/>
    </classpath>
    </java>
    </target>

    <!--
    =============
    Clean targets
    =============
    -->
    <target name="clean">
    <delete dir="${build.dir}"/>
    </target>

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

    </project>

    关于ivy - 解释如何使用文件系统解析器的示例示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10175000/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com