有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java从ivy检索中排除本地项目

我有一个多模块蚂蚁+常春藤项目。项目之间的依赖关系记录在常春藤中。xml文件

调用<ivy:retrieve>时,它将尝试下载所有依赖项,包括本地项目

如何从检索中排除本地项目

或者,也许可以以某种方式使用文件系统解析器,这样它将解析为${projects.dir}/*/ivy.xml,就像IvyDE使用工作区解析器一样

更新

我只想排除本地项目,但仍然要检索它们的可传递依赖项。 我需要在eclipse之外复制IvyDE工作区解析器的行为

示例

给定项目结构:

  • 计划/
    • 本地的。模块1/
      • bin/
      • lib/
      • 建造。xml
      • 常春藤。xml
        • <dependency org="local" name="local.module2" />
    • 本地的。模块2/
      • bin/
      • lib/
      • 建造。xml
      • 常春藤。xml
        • <dependency org="external" name="library1" />
    • 普通的。xml
    • 建造。xml

我希望local.module1能够检索除本地项目(local.module2,external.library1)之外的所有它的可传递依赖项(local.module2),因此实际上这会留下external.library1

基于此,我想构造构建类路径,该类路径由对本地项目的直接引用和对外部库的jar引用组成。对于模块1:

  • /地方的模块2/箱
  • lib/external。图书馆1-1.0。罐子

万一有人想知道为什么——我正试图用最小的改动将常春藤融入现有的构建系统


共 (2) 个答案

  1. # 1 楼答案

    ivy.xml文件中,添加exclude实体

    <dependency org="com.vegicorp"   name="flubaster"    
        conf="compile->default"   rev="3.3">
        <exclude org="com.local"/>
    </dependency
    

    这将阻止您从“com”下载任何内容。“本地”或您在存储本地JAR时所称的任何组织

    (除非您谈论的是这个特定项目的JAR,如果是这样的话,那么它们根本不应该出现在您的ivy.xml文件中)

  2. # 2 楼答案

    我最近也遇到了同样的问题,将部分常春藤集成到遗留项目中只是为了从maven世界获取一些可传递的依赖项,同时保留现有的ant构建过程。还必须通过使用伪本地文件系统解析器解析到伪jar来避免使用ivy发布项目模块

    ivysettings。xml

    <ivysettings>
        <settings defaultResolver="default">
            <property name="local.maven2.dir" value="${user.home}/.m2/repository/" override="false"/>
            <property name="local-project.cache.dir" value="${ivy.settings.dir}/cache" override="false"/>
        </settings>
        <caches resolutionCacheDir="${local-project.cache.dir}" lockStrategy="artifact-lock" useOrigin="true">
            <cache name="local-project" basedir="${local-project.cache.dir}" useOrigin="true"/>
        </caches>
        <resolvers>
            <chain name="default">
                <filesystem name="local-maven-2" m2compatible="true" checkmodified="true" changingPattern=".*SNAPSHOT">
                    <artifact pattern="${local.maven2.dir}/[organisation]/[module]/[revision]/[module]-[revision].[ext]"/>
                    <ivy pattern="${local.maven2.dir}/[organisation]/[module]/[revision]/[module]-[revision].pom"/>
                </filesystem>
                <ibiblio name="central" m2compatible="true"
                         root="http://repo1.maven.org/maven2/"/>
            </chain>
            <filesystem name="local-project" force="true" checkmodified="true" changingPattern=".*" cache="local-project">
                <artifact pattern="${ivy.settings.dir}/dummy.jar"/>
                <ivy pattern="${ivy.settings.dir}/[module]-ivy.xml"/>
            </filesystem>
        </resolvers>
        <modules>
            <module organisation="example.com" resolver="local-project"/>
        </modules>
    </ivysettings>
    

    由于未能找到更好的常春藤方法,不得不从ant中排除假罐子:

        <ivy:retrieve pattern="${dependency.export.dir}/[conf]/[artifact](-[revision]).[ext]" type="jar,bundle"/>
        <delete>
            <fileset dir="${dependency.export.dir}">
                <include name="**/*@local-project.jar"/>
            </fileset>
        </delete>
    

    仍然在努力寻找一种方便的方式去exclude provided dependencies with ivy

    如果有人对示例项目源代码感兴趣,可以在IVY-1443bug附件中找到