如何强制依赖项包含具有特定版本号的工件

时间:2016-02-20 19:45:07

标签: java maven gwt maven-3

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

  

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

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

奇怪的是,在我做之前,构建工作正在进行中。

这是我的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>

1 个答案:

答案 0 :(得分:3)

解决方案1 ​​

问题是eventbinder依赖于gwt-user工件。它默认使用2.6.0,您可以使用此命令查看它。

mvn dependency:tree

enter image description here

如果您将此依赖关系块添加到您的pom;

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

enter image description here

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

这意味着您的项目将始终拥有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>

结果:

enter image description here