如何避免从maven(POM)下载谷歌收藏jar,Exclude也不起作用



我想排除谷歌收藏jar,即使使用了exclude标记,它也会被下载。这样,每当我执行"mvn-clean-install"时,就不应该下载google-collections.jar。

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

我还尝试从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>

由于我已经排除了谷歌收藏,它的Jar不应该下载。

但它下载谷歌收藏罐。

我对尝试所有组合毫无头绪,也很沮丧。如果有人能解释为什么这不起作用,以及下载谷歌收藏罐的依赖关系,那就太好了。

我注释掉了对guava的依赖,并执行mvn干净安装。它下载谷歌收藏罐。

我检查了您的依赖项,并且您没有将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存在,尽管它不存在,因为事实上,不存在任何问题。

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

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

要找到m2回购的路径,您可以查看:如何获取Maven本地回购位置?