groovy - 安装grape依赖项时如何排除本地maven存储库

标签 groovy 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

...

最佳答案

您的本地 Maven 存储库可能位于 grapeConfig.xml 的解析器部分 (~/.groovy/grapeConfig.xml):

<?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 存储库包含在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)

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

> 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:根据我的评论进行编辑:

如果您无法在 ~/.groovy 中创建 grapeConfig.xml,但可以在其他路径中创建它,则可以这样做

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

关于groovy - 安装grape依赖项时如何排除本地maven存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15784791/

相关文章:

groovy - 抓取葡萄时出错... Unresolved 依赖关系...未找到

groovy - protected Nexus 存储库的 Grape 配置

intellij-idea - 如何获取依赖项并使其与 IntelliJ 项目一起使用?

groovy - 是否可以创建一个无需编译即可在脚本中使用的 Groovy 包?

javascript - Groovy Grails 发送/接收变量

java - 这是在 Geb 中使用 "at"闭包的正确方法吗

intellij-idea - @Grab 不能在用于 groovy 的 intellij IDE 中工作

intellij-idea - Jenkinsfile DSL 源代码

groovy - 是否可以随机化 Spock 测试的执行顺序?

groovy - 如何使用 GrabResolver 在 groovysh 中使用远程存储库