【问题标题】:How to avoid google-collections jar to be downloaded from maven (POM), Exclude is also not working如何避免从 maven (POM) 下载 google-collections jar,Exclude 也不起作用
【发布时间】:2019-02-08 09:32:40
【问题描述】:

我想排除 google-collection jar,即使使用了 exclude 标签,它也会被下载。因此,每当我执行“mvn clean install”时,不应下载 google-collections.jar。

每当我执行 mvn clean install google-collection jar 下载时,我仍然尝试在所有依赖项中添加排除。

我还尝试从 m2 repo 中手动删除 jar 文件,然后运行 ​​mvn clean install。它再次下载。

 <dependencies>
        <dependency>
            <groupId>net.rcarz</groupId>
            <artifactId>jira-client</artifactId>
            <version>0.5</version>
            <scope>compile</scope>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.37</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>

        <dependency>
            <groupId>org.twitter4j</groupId>
            <artifactId>twitter4j-core</artifactId>
            <version>[4.0,)</version>
        </dependency>
        <dependency>
            <groupId>net.sf.opencsv</groupId>
            <artifactId>opencsv</artifactId>
            <version>2.3</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-report-plugin</artifactId>
            <version>[2,)</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>


    <dependency>
            <groupId>org.apache.httpcomponents</groupId>
            <artifactId>httpclient</artifactId>
            <version>[4,)</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.1.3</version>
            <exclusions>
             <exclusion>
                <groupId>com.google.collections</groupId>
                <artifactId>google-collections</artifactId>
            </exclusion>
            </exclusions>
        </dependency>

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.8.5</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.uncommons</groupId>
            <artifactId>reportng</artifactId>
            <version>1.1.4</version>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.testng</groupId>
                    <artifactId>testng</artifactId>
                </exclusion>

            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>

            </exclusions>
        </dependency>
        <dependency>
            <groupId>com.google.inject</groupId>
            <artifactId>guice</artifactId>
            <version>3.0</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>velocity</groupId>
            <artifactId>velocity</artifactId>
            <version>1.4</version>
            <scope>test</scope>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jsoup</groupId>
            <artifactId>jsoup</artifactId>
            <version>1.8.1</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi-ooxml</artifactId>
            <version>3.9</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.11.0</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-firefox-driver</artifactId>
            <version>3.11.0</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-server</artifactId>
            <version>3.11.0</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>

        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>htmlunit-driver</artifactId>
            <version>2.29.0</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>xml-apis</groupId>
            <artifactId>xml-apis</artifactId>
            <version>1.4.01</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1.1</version>
            <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
        </dependency>
        <dependency>
            <groupId>org.apache.poi</groupId>
            <artifactId>poi</artifactId>
            <version>3.11</version>
        </dependency>
        <dependency>
            <groupId>joda-time</groupId>
            <artifactId>joda-time</artifactId>
            <version>2.3</version>
        </dependency>

        <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>23.0</version>
        <exclusions>
            <exclusion>
                    <groupId>com.google.collections</groupId>
                    <artifactId>google-collections</artifactId>
             </exclusion>
        </exclusions>
    </dependency>
    </dependencies>
    <profiles>

有了这个,因为我已经排除了 google-Collection 它的 Jar 不应该下载。

但它会下载 google-collection jar 。

我对尝试所有组合一无所知并且感到沮丧。如果有人也能解释为什么这不起作用以及哪个依赖项正在下载 google-collection jar,那就太好了。

我注释掉了番石榴依赖并执行 mvn clean install。它会下载 google collection jar。

【问题讨论】:

  • 首先你做了几个无用的排除,因为一些部门没有 google-collections 作为依赖项。此外下载依赖项并不意味着您正在使用它...它可以是插件或另一个模块此外,我看不到您的项目是否有可能继承某些东西的父项..您应该检查命令行mvn dependency:tree如果您发现 google-collections 的迹象,请在您自己的项目中。如果不是你很好......比插件使用它作为依赖......

标签: maven selenium-webdriver dependencies guava


【解决方案1】:

我检查了您的依赖项,但您没有 google-collections 作为依赖项

但是,您拥有guava,它是google-collections 的继承者。但是您明确要求该依赖项作为您的最后一个依赖项。

但是...如果我删除了您在 pom.xml 文件中添加的所有排除项,则确实存在一个依赖于 google-collections 的依赖项:它是 maven-surefire-report-plugin(它是一个插件,不应该是一个依赖项),但是...您准确地将google-collections 从它自己的依赖项中排除了!所以google-collections 完全不存在。

您可以通过进入项目文件夹并输入以下内容来检查:

mvn dependency:tree

这样的结果如下:

[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ tmp ---
[INFO] com.example:tmp:jar:1.0-SNAPSHOT
[INFO] +- net.rcarz:jira-client:jar:0.5:compile
[INFO] |  +- org.apache.httpcomponents:httpmime:jar:4.2.5:compile
[INFO] |  +- net.sf.json-lib:json-lib:jar:jdk15:2.4:compile
[INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] |  |  +- commons-collections:commons-collections:jar:3.2.1:compile
[INFO] |  |  \- net.sf.ezmorph:ezmorph:jar:1.0.6:compile
[INFO] |  +- junit:junit:jar:4.8.2:compile
[INFO] |  +- org.mockito:mockito-all:jar:1.9.0:compile
[INFO] |  \- commons-httpclient:commons-httpclient:jar:3.1:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.37:compile
[INFO] +- org.twitter4j:twitter4j-core:jar:4.0.7:compile
[INFO] +- net.sf.opencsv:opencsv:jar:2.3:compile
[INFO] +- org.apache.maven.plugins:maven-surefire-report-plugin:jar:3.0.0-M3:compile
[INFO] |  +- org.apache.maven.surefire:surefire-report-parser:jar:3.0.0-M3:compile
[INFO] |  |  +- org.apache.maven.surefire:surefire-logger-api:jar:3.0.0-M3:compile
[INFO] |  |  \- org.apache.maven.reporting:maven-reporting-api:jar:3.0:compile
[INFO] |  +- org.apache.maven:maven-plugin-api:jar:3.0:compile
[INFO] |  |  +- org.apache.maven:maven-model:jar:3.0:compile
[INFO] |  |  +- org.apache.maven:maven-artifact:jar:3.0:compile
[INFO] |  |  \- org.sonatype.sisu:sisu-inject-plexus:jar:1.4.2:compile
[INFO] |  |     +- org.codehaus.plexus:plexus-classworlds:jar:2.2.3:compile
[INFO] |  |     \- org.sonatype.sisu:sisu-inject-bean:jar:1.4.2:compile
[INFO] |  |        \- org.sonatype.sisu:sisu-guice:jar:noaop:2.1.7:compile
[INFO] |  +- org.apache.maven.reporting:maven-reporting-impl:jar:3.0.0:compile
[INFO] |  |  +- org.apache.maven:maven-core:jar:3.0:compile
[INFO] |  |  |  +- org.apache.maven:maven-settings:jar:3.0:compile
[INFO] |  |  |  +- org.apache.maven:maven-settings-builder:jar:3.0:compile
[INFO] |  |  |  +- org.apache.maven:maven-repository-metadata:jar:3.0:compile
[INFO] |  |  |  +- org.apache.maven:maven-model-builder:jar:3.0:compile
[INFO] |  |  |  +- org.apache.maven:maven-aether-provider:jar:3.0:runtime
[INFO] |  |  |  +- org.sonatype.aether:aether-impl:jar:1.7:compile
[INFO] |  |  |  |  \- org.sonatype.aether:aether-spi:jar:1.7:compile
[INFO] |  |  |  +- org.sonatype.aether:aether-api:jar:1.7:compile
[INFO] |  |  |  +- org.sonatype.aether:aether-util:jar:1.7:compile
[INFO] |  |  |  +- org.codehaus.plexus:plexus-interpolation:jar:1.14:compile
[INFO] |  |  |  \- org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[INFO] |  |  |     \- org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[INFO] |  |  +- org.apache.maven.shared:maven-shared-utils:jar:3.2.0:compile
[INFO] |  |  \- org.codehaus.plexus:plexus-utils:jar:3.0.24:compile
[INFO] |  +- org.apache.maven.doxia:doxia-sink-api:jar:1.8:compile
[INFO] |  |  \- org.apache.maven.doxia:doxia-logging-api:jar:1.8:compile
[INFO] |  +- org.apache.maven.doxia:doxia-decoration-model:jar:1.8.1:compile
[INFO] |  |  \- org.codehaus.plexus:plexus-component-annotations:jar:1.6:compile
[INFO] |  +- org.apache.maven.doxia:doxia-core:jar:1.8:compile
[INFO] |  |  \- org.codehaus.plexus:plexus-container-default:jar:1.7.1:compile
[INFO] |  |     \- org.apache.xbean:xbean-reflect:jar:3.7:compile
[INFO] |  +- org.apache.maven.doxia:doxia-site-renderer:jar:1.8.1:compile
[INFO] |  |  +- org.apache.maven.doxia:doxia-skin-model:jar:1.8.1:compile
[INFO] |  |  +- org.apache.maven.doxia:doxia-module-xhtml:jar:1.8:compile
[INFO] |  |  +- org.codehaus.plexus:plexus-i18n:jar:1.0-beta-7:compile
[INFO] |  |  +- org.codehaus.plexus:plexus-velocity:jar:1.2:compile
[INFO] |  |  +- org.apache.velocity:velocity:jar:1.7:compile
[INFO] |  |  \- org.apache.velocity:velocity-tools:jar:2.0:compile
[INFO] |  |     +- commons-digester:commons-digester:jar:1.8:compile
[INFO] |  |     +- commons-chain:commons-chain:jar:1.1:compile
[INFO] |  |     +- commons-validator:commons-validator:jar:1.3.1:compile
[INFO] |  |     +- oro:oro:jar:2.0.8:compile
[INFO] |  |     +- sslext:sslext:jar:1.2-0:compile
[INFO] |  |     +- org.apache.struts:struts-core:jar:1.3.8:compile
[INFO] |  |     |  \- antlr:antlr:jar:2.7.2:compile
[INFO] |  |     +- org.apache.struts:struts-taglib:jar:1.3.8:compile
[INFO] |  |     \- org.apache.struts:struts-tiles:jar:1.3.8:compile
[INFO] |  \- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.7:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.4.11:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.11:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- org.testng:testng:jar:6.8.5:compile
[INFO] |  +- org.beanshell:bsh:jar:2.0b4:compile
[INFO] |  +- com.beust:jcommander:jar:1.27:compile
[INFO] |  \- org.yaml:snakeyaml:jar:1.6:compile
[INFO] +- org.uncommons:reportng:jar:1.1.4:test
[INFO] +- com.google.inject:guice:jar:3.0:test
[INFO] |  +- javax.inject:javax.inject:jar:1:test
[INFO] |  \- aopalliance:aopalliance:jar:1.0:test
[INFO] +- velocity:velocity:jar:1.4:test
[INFO] |  \- velocity:velocity-dep:jar:1.4:test
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.jsoup:jsoup:jar:1.8.1:compile
[INFO] +- org.apache.poi:poi-ooxml:jar:3.9:compile
[INFO] |  +- org.apache.poi:poi-ooxml-schemas:jar:3.9:compile
[INFO] |  |  \- org.apache.xmlbeans:xmlbeans:jar:2.3.0:compile
[INFO] |  |     \- stax:stax-api:jar:1.0.1:compile
[INFO] |  \- dom4j:dom4j:jar:1.6.1:compile
[INFO] +- org.seleniumhq.selenium:selenium-java:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-api:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-chrome-driver:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-edge-driver:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-ie-driver:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-opera-driver:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-remote-driver:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-safari-driver:jar:3.11.0:compile
[INFO] |  +- org.seleniumhq.selenium:selenium-support:jar:3.11.0:compile
[INFO] |  +- net.bytebuddy:byte-buddy:jar:1.7.9:compile
[INFO] |  +- org.apache.commons:commons-exec:jar:1.3:compile
[INFO] |  +- com.google.code.gson:gson:jar:2.8.2:compile
[INFO] |  +- com.squareup.okhttp3:okhttp:jar:3.9.1:compile
[INFO] |  \- com.squareup.okio:okio:jar:1.13.0:compile
[INFO] +- org.seleniumhq.selenium:selenium-firefox-driver:jar:3.11.0:compile
[INFO] +- org.seleniumhq.selenium:selenium-server:jar:3.11.0:compile
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.7:compile
[INFO] |  +- org.apache.commons:commons-text:jar:1.1:compile
[INFO] |  +- commons-io:commons-io:jar:2.6:compile
[INFO] |  +- commons-net:commons-net:jar:3.6:compile
[INFO] |  +- org.w3c.css:sac:jar:1.3:compile
[INFO] |  +- net.sourceforge.cssparser:cssparser:jar:0.9.24:compile
[INFO] |  +- net.sourceforge.htmlunit:htmlunit:jar:2.29:compile
[INFO] |  +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.28:compile
[INFO] |  +- net.sourceforge.htmlunit:neko-htmlunit:jar:2.28:compile
[INFO] |  +- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] |  +- org.seleniumhq.selenium:jetty-repacked:jar:9.4.7.v20171121:compile
[INFO] |  +- org.eclipse.jetty:jetty-client:jar:9.4.7.v20170914:compile
[INFO] |  +- org.eclipse.jetty:jetty-http:jar:9.4.8.v20171121:compile
[INFO] |  +- org.eclipse.jetty:jetty-io:jar:9.4.8.v20171121:compile
[INFO] |  +- org.eclipse.jetty:jetty-util:jar:9.4.8.v20171121:compile
[INFO] |  +- org.eclipse.jetty:jetty-xml:jar:9.4.7.v20170914:compile
[INFO] |  +- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] |  +- org.eclipse.jetty.websocket:websocket-api:jar:9.4.7.v20170914:compile
[INFO] |  +- org.eclipse.jetty.websocket:websocket-client:jar:9.4.7.v20170914:compile
[INFO] |  +- org.eclipse.jetty.websocket:websocket-common:jar:9.4.7.v20170914:compile
[INFO] |  +- xalan:serializer:jar:2.7.2:compile
[INFO] |  +- xalan:xalan:jar:2.7.2:compile
[INFO] |  \- xerces:xercesImpl:jar:2.11.0:compile
[INFO] +- org.seleniumhq.selenium:htmlunit-driver:jar:2.29.0:compile
[INFO] +- xml-apis:xml-apis:jar:1.4.01:compile
[INFO] +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] +- org.apache.poi:poi:jar:3.11:compile
[INFO] +- joda-time:joda-time:jar:2.3:compile
[INFO] \- com.google.guava:guava:jar:23.0:compile
[INFO]    +- com.google.code.findbugs:jsr305:jar:1.3.9:compile
[INFO]    +- com.google.errorprone:error_prone_annotations:jar:2.0.18:compile
[INFO]    +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO]    \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:compile

如您所见,没有间接依赖名称google-collections

所以你很可能会想到另一个问题,这让你认为google-collections 存在,我非常希望你说出为什么你认为google-collections 存在,即使它不存在,因为它确实存在, 没有问题

【讨论】:

    【解决方案2】:

    第一次,当您执行mvn clean install 时,它会下载 pom.xml 中存在的所有依赖项并将其存储在 .m2 存储库中。因此,现在当您使用 exclude 标签时,它不会有任何更改,因为提到的依赖项已经存在于您的 m2 存储库中。

    因此,您需要从 m2 存储库中删除 jar,为此您需要转到 m2 存储库并手动删除该 jar,现在如果您使用排除标签并执行 mvn clean install,它将不会再次下载.

    要找到m2 repo的路径,可以查看:How to get the Maven local repo location?

    【讨论】:

    • 感谢 Sameer 的回复。我已经试过了。即使从 m2 repo 中删除它,当我执行 mvn clean install 时它会再次下载。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 2016-12-11
    • 2017-07-21
    • 2018-02-09
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多