如何在安装葡萄依赖项时排除本地maven存储库

时间:2013-04-03 10:23:39

标签: groovy grape

我想在我的项目中安装一些葡萄依赖项:

grape install org.codehaus.groovy.modules.http-builder http-builder 0.6

如何从maven本地存储库中排除下载?默认情况下,它看起来像是从我的本地仓库下载

found org.codehaus.groovy.modules.http-builder#http-builder;0.6 in localm2
found org.apache.httpcomponents#httpclient;4.2.1 in localm2
found org.apache.httpcomponents#httpcore;4.2.1 in localm2
found commons-logging#commons-logging;1.1.1 in localm2
found commons-codec#commons-codec;1.6 in localm2

...

1 个答案:

答案 0 :(得分:2)

您可能在grapeConfig.xml~/.groovy/grapeConfig.xml)的解析器部分中拥有本地maven repo:

<?xml version="1.0"?>
<ivysettings>
    <settings defaultResolver="downloadGrapes"/>
    <resolvers>
        <chain name="downloadGrapes">
            <!-- todo add 'endorsed groovy extensions' resolver here -->
            <ibiblio name="local" root="file:${user.home}/.m2/repository/" m2compatible="true"/>
            <filesystem name="cachedGrapes">
                <ivy pattern="${user.home}/.groovy/grapes/[organisation]/[module]/ivy-[revision].xml"/>
                <artifact pattern="${user.home}/.groovy/grapes/[organisation]/[module]/[type]s/[artifact]-[revision].[ext]"/>
            </filesystem>
            <ibiblio name="codehaus" root="http://repository.codehaus.org/" m2compatible="true"/>
            <ibiblio name="ibiblio" m2compatible="true"/>
            <ibiblio name="java.net2" root="http://download.java.net/maven/2/" m2compatible="true"/>
        </chain>
    </resolvers>
</ivysettings>

如果resolvers部分内部的行显示为grape,则会从本地maven仓库中获取工件:

<ibiblio name="local" root="file:${user.home}/.m2/repository/" m2compatible="true"/>

注释下载配置的回购中的工件。

编辑:刚刚使用joda-time

进行本地测试

首先,我的本地maven repo包含在grapeConfig.xml

> grape install joda-time joda-time 2.1
:: loading settings :: url = jar:file:/C:/Software/groovy-2.1.1/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysettings.xml
:: resolving dependencies :: caller#all-caller;working16
        confs: [default]
        found joda-time#joda-time;2.1 in local
downloading file:C:/Users/jalopaba/.m2/repository/joda-time/joda-time/2.1/joda-time-2.1.jar ...
        [SUCCESSFUL ] joda-time#joda-time;2.1!joda-time.jar (90ms)

手动删除joda-time中的~/.groovy/grapes文件夹并注释掉上述行后:

> grape install joda-time joda-time 2.1
:: loading settings :: url = jar:file:/C:/Software/groovy-2.1.1/lib/ivy-2.2.0.jar!/org/apache/ivy/core/settings/ivysetti    ngs.xml
:: resolving dependencies :: caller#all-caller;working09
        confs: [default]
        found joda-time#joda-time;2.1 in ibiblio
downloading http://repo1.maven.org/maven2/joda-time/joda-time/2.1/joda-time-2.1.jar ...
        [SUCCESSFUL ] joda-time#joda-time;2.1!joda-time.jar (2460ms)

编辑2 :根据我的评论编辑:

如果您无法在grapeConfig.xml中创建~/.groovy,但可以在其他路径中创建<{1}},则可以

grape -Dgrape.config=<pathTo_grapeConfig.xml> install joda-time joda-time 2.1