簡體   English   中英

排除傳遞依賴超過一級

[英]Excluding transitive dependency more than one level

我有這個pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.springframework</groupId>
    <artifactId>gs-maven</artifactId>
    <packaging>jar</packaging>
    <version>0.1.0</version>


    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>2.1</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>hello.HelloWorld</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
        <dependencies>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
                <version>4.1.4.Final</version>
                <exclusions>
                    <exclusion>
                        <groupId>javassist</groupId>
                        <artifactId>javassist</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
        <dependency>
            <groupId>ch.simas.qlrm</groupId>
            <artifactId>qlrm</artifactId>
            <version>1.5.1</version>
            <exclusions>
                <exclusion>
                    <groupId>org.eclipse.persistence</groupId>
                    <artifactId>javax.persistence</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

    </dependencies>
</project>

依賴項:樹是

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-maven 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ gs-maven ---
[INFO] org.springframework:gs-maven:jar:0.1.0
[INFO] +- org.hibernate:hibernate-core:jar:4.1.4.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] \- ch.simas.qlrm:qlrm:jar:1.5.1:compile
[INFO]    +- org.eclipse.persistence:eclipselink:jar:2.5.1:compile
[INFO]    |  +- org.eclipse.persistence:javax.persistence:jar:2.1.0:compile
[INFO]    |  \- org.eclipse.persistence:commonj.sdo:jar:2.1.1:compile
[INFO]    \- com.h2database:h2:jar:1.3.170:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.142 s
[INFO] Finished at: 2015-01-23T15:43:19+05:30
[INFO] Final Memory: 8M/81M
[INFO] ------------------------------------------------------------------------

即使我排除了javax.persistence,在構建時也會收到以下警告

[WARNING] javax.persistence-2.1.0.jar, hibernate-jpa-2.0-api-1.0.1.Final.jar define 92 overlappping classes:
[WARNING]   - javax.persistence.SecondaryTable
[WARNING]   - javax.persistence.TableGenerator
[WARNING]   - javax.persistence.NamedNativeQueries
[WARNING]   - javax.persistence.TransactionRequiredException
[WARNING]   - javax.persistence.SecondaryTables
[WARNING]   - javax.persistence.JoinTable
[WARNING]   - javax.persistence.Id
[WARNING]   - javax.persistence.Embedded
[WARNING]   - javax.persistence.EntityResult
[WARNING]   - javax.persistence.EntityManager
[WARNING]   - 82 more...
[WARNING] javax.persistence-2.1.0.jar, eclipselink-2.5.1.jar define 24 overlappping classes:
[WARNING]   - javax.persistence.NamedStoredProcedureQuery
[WARNING]   - javax.persistence.ConstructorResult
[WARNING]   - javax.persistence.ParameterMode
[WARNING]   - javax.persistence.Index
[WARNING]   - javax.persistence.AttributeConverter
[WARNING]   - javax.persistence.NamedStoredProcedureQueries
[WARNING]   - javax.persistence.Subgraph
[WARNING]   - javax.persistence.ConstraintMode
[WARNING]   - javax.persistence.Converts
[WARNING]   - javax.persistence.criteria.CriteriaUpdate
[WARNING]   - 14 more...
[WARNING] javax.persistence-2.1.0.jar, eclipselink-2.5.1.jar, hibernate-jpa-2.0-api-1.0.1.Final.jar define 80 overlappping classes:
[WARNING]   - javax.persistence.criteria.SetJoin
[WARNING]   - javax.persistence.criteria.Predicate
[WARNING]   - javax.persistence.CacheRetrieveMode
[WARNING]   - javax.persistence.TupleElement
[WARNING]   - javax.persistence.metamodel.PluralAttribute
[WARNING]   - javax.persistence.AccessType
[WARNING]   - javax.persistence.Access
[WARNING]   - javax.persistence.metamodel.ManagedType
[WARNING]   - javax.persistence.metamodel.ListAttribute
[WARNING]   - javax.persistence.criteria.CriteriaBuilder$Trimspec
[WARNING]   - 70 more...
[WARNING] maven-shade-plugin has detected that some .class files
[WARNING] are present in two or more JARs. When this happens, only
[WARNING] one single version of the class is copied in the uberjar.
[WARNING] Usually this is not harmful and you can skeep these
[WARNING] warnings, otherwise try to manually exclude artifacts
[WARNING] based on mvn dependency:tree -Ddetail=true and the above
[WARNING] output
[WARNING] See http://docs.codehaus.org/display/MAVENUSER/Shade+Plugin
[INFO] Replacing original artifact with shaded artifact.
[INFO] Replacing /Users/sivakr/Documents/java/maven_1/target/gs-maven-0.1.0.jar with /Users/sivakr/Documents/java/maven_1/target/gs-maven-0.1.0-shaded.jar
[INFO] Dependency-reduced POM written at: /Users/sivakr/Documents/java/maven_1/dependency-reduced-pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.214 s
[INFO] Finished at: 2015-01-23T15:43:11+05:30
[INFO] Final Memory: 7M/81M
[INFO] ------------------------------------------------------------------------

如何排除重復的罐子? 並消除警告

更新依賴項:樹

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building gs-maven 0.1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ gs-maven ---
[INFO] org.springframework:gs-maven:jar:0.1.0
[INFO] +- org.hibernate:hibernate-core:jar:4.1.4.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
[INFO] |  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
[INFO] |  +- org.javassist:javassist:jar:3.15.0-GA:compile
[INFO] |  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
[INFO] \- ch.simas.qlrm:qlrm:jar:1.5.1:compile
[INFO]    +- org.eclipse.persistence:eclipselink:jar:2.5.1:compile
[INFO]    |  \- org.eclipse.persistence:commonj.sdo:jar:2.1.1:compile
[INFO]    \- com.h2database:h2:jar:1.3.170:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.138 s
[INFO] Finished at: 2015-01-23T18:11:06+05:30
[INFO] Final Memory: 8M/81M
[INFO] ------------------------------------------------------------------------

POM更改要排除一個級別以上的依賴關系與排除一個級別上的依賴關系相同。

根據文檔,如果依賴關系圖如下

Project-A
   -> Project-B
        -> Project-D 
              -> Project-E <!-- Exclude this dependency -->
              -> Project-F
   -> Project C

在項目A POM中排除項目E

<project>
  <modelVersion>4.0.0</modelVersion>
  <groupId>sample.ProjectA</groupId>
  <artifactId>Project-A</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  ...
  <dependencies>
    <dependency>
      <groupId>sample.ProjectB</groupId>
      <artifactId>Project-B</artifactId>
      <version>1.0-SNAPSHOT</version>
      <exclusions>
        <exclusion>
          <groupId>sample.ProjectE</groupId> <!-- Exclude Project-E from Project-B -->
          <artifactId>Project-E</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>
</project>

Maven依賴插件輸出格式為:

[groupId]:[artifactId]:[type]:[version]

對於依賴項:

org.eclipse.persistence:javax.persistence:jar:2.1.0:compile

該組是org.eclipse.persistence ,artifactId是javax.persistence

您的排除規則有誤,組和工件相反。 它應該是:

<exclusions>
    <exclusion>
        <artifactId>javax.persistence</artifactId>
        <groupId>org.eclipse.persistence</groupId>
    </exclusion>
</exclusions>

編輯:添加maven-shade-plugin配置

要從maven-shade-plugin中排除依賴項,請嘗試將排除項添加到插件配置中:

<execution>
    <phase>package</phase>
    <goals>
        <goal>shade</goal>
    </goals>
    <configuration>
        <artifactSet>
            <excludes>
                <exclude>org.eclipse.persistence:javax.persistence</exclude>
            </excludes>
        </artifactSet>
        <transformers>
            <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                <mainClass>hello.HelloWorld</mainClass>
            </transformer>
        </transformers>
    </configuration>
</execution>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM