【问题标题】:How to force the dependency to include an artifact with a specific version number如何强制依赖项包含具有特定版本号的工件
【发布时间】:2016-06-02 09:00:09
【问题描述】:

尝试使用 maven 构建 GWT 项目时出现此错误:

您的项目声明对 gwt-user 2.6.0 的依赖。这个插件是 至少为 gwt 2.7.0 版设计

我发现 gwt-user 2.6.0 是使用 com.google.gwt.eventbinder 下载的。 如何强制 com.google.gwt.eventbinder 使用 gwt-user 2.7.0 而不是 2.6.0?

奇怪的是,在我执行 'git pull' 之前构建工作。

这是我的 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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.prognoz.ra.okhs</groupId>
<artifactId>gwtclient</artifactId>
<version>0.3.1-SNAPSHOT</version>

<packaging>war</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <gwt.version>2.7.0</gwt.version>
    <maven.version>3.0.5</maven.version>
    <jdk.version>1.7</jdk.version>
    <version.org.codehaus.mojo.gwt.maven.plugin>2.7.0</version.org.codehaus.mojo.gwt.maven.plugin>
    <webappDirectory>war</webappDirectory>
    <maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format>
    <skipTests>true</skipTests>
</properties>

<prerequisites>
    <maven>${maven.version}</maven>
</prerequisites>

<dependencies>
    <dependency>
        <groupId>org.moxieapps.gwt</groupId>
        <artifactId>highcharts</artifactId>
        <version>1.7.0</version>
        <scope>system</scope>
        <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/highcharts-1.7.0.jar</systemPath>
    </dependency>

    <dependency>
        <groupId>com.prognoz.ra.dbutil</groupId>
        <artifactId>dbutil</artifactId>
        <scope>system</scope>
        <version>1.0.1-SNAPSHOT</version>
        <systemPath>${basedir}/out/artifacts/dbutil_jar/dbutil.jar</systemPath>
    </dependency>

    <dependency>
        <groupId>com.liferay.org.apache.commons.fileupload</groupId>
        <artifactId>com.liferay.org.apache.commons.fileupload</artifactId>
        <version>6.2.0.1</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-io</artifactId>
        <version>1.3.2</version>
    </dependency>

    <dependency>
        <groupId>com.google.gwt</groupId>
        <version>${gwt.version}</version>
        <artifactId>gwt-servlet</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jsp-api</artifactId>
        <version>2.0</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava</artifactId>
        <version>18.0</version>
    </dependency>
    <dependency>
        <groupId>com.google.guava</groupId>
        <artifactId>guava-gwt</artifactId>
        <version>18.0</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

    <dependency>
        <groupId>commons-io</groupId>
        <artifactId>commons-io</artifactId>
        <version>2.3</version>
    </dependency>

    <dependency>
        <groupId>com.google.gwt.eventbinder</groupId>
        <artifactId>eventbinder</artifactId>
        <version>1.1.0</version>
    </dependency>
</dependencies>

<build>
    <resources>
        <resource>
            <directory>${basedir}/src/main/java</directory>
            <includes>
                <include>**/*.properties</include>
            </includes>
        </resource>
    </resources>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>gwt-maven-plugin</artifactId>
            <version>${version.org.codehaus.mojo.gwt.maven.plugin}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
              <compileReport>true</compileReport>
              <logLevel>INFO</logLevel>
              <copyWebapp>true</copyWebapp>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-source-plugin</artifactId>
            <version>2.4</version>
        </plugin>

        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.5</version>
            <configuration>

            </configuration>
        </plugin>

        <plugin>
            <artifactId>maven-deploy-plugin</artifactId>
            <version>2.8.2</version>
            <executions>
                <execution>
                    <id>deploy</id>
                    <phase>deploy</phase>
                    <goals>
                        <goal>deploy</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

        <plugin>
            <groupId>org.apache.tomcat.maven</groupId>
            <artifactId>tomcat7-maven-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <url>http://localhost:8080/manager/text</url>
                <server>Tomcat8_local</server>
                <path>/ra-okhs</path>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.2</version>
            <configuration>
                <source>${jdk.version}</source>
                <target>${jdk.version}</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<profiles>
    <profile>
        <id>m2e</id>
        <activation>
            <property>
                <name>m2e.version</name>
            </property>
        </activation>
        <build>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.mojo</groupId>
                    <artifactId>gwt-maven-plugin</artifactId>
                </plugin>
            </plugins>
        </build>
    </profile>
</profiles>

【问题讨论】:

    标签: java maven gwt maven-3


    【解决方案1】:

    解决方案 1

    问题是 eventbinder 依赖于 gwt-user 工件。它默认使用2.6.0,你可以通过这个命令看到它。

    mvn dependency:tree
    

    如果你把这个依赖块添加到你的 pom 中;

    <dependency>
       <groupId>com.google.gwt</groupId>
       <artifactId>gwt-user</artifactId>
       <version>2.7.0</version>
    </dependency>
    

    它看起来像这样......

    这意味着您的项目将一直使用 gwt-user 2.7.0,我还没有测试过版本兼容性是否一切正常,或者您的问题将得到解决..

    解决方案 2 感谢@Thomas Broyer 的评论,我们可以强制 eventbinder 使用 2.7.0 gwt-user 或任何 gwt 依赖项。如果我们只是将这个依赖管理添加到我们的 pom 中

    <dependencyManagement>
     <dependencies>
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>2.7.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
     </dependencies>
    </dependencyManagement>
    

    结果:

    【讨论】:

    • 或者你可以使用dependencyManagement。从 2.7.0 开始,您可以使用 scope=import 和 com.google.gwt:gwt 在 dependencyManagement 中导入 gwt-user、gwt-servlet、gwt-dev 等。
    • 解决方案 2 确实有助于解决反射之间的冲突>0.9.11 和 Guava
    猜你喜欢
    • 2016-07-29
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 1970-01-01
    • 2018-06-29
    • 1970-01-01
    • 2020-04-18
    • 1970-01-01
    相关资源
    最近更新 更多