使用maven-war-plugin和Spring BOM

时间:2014-05-09 17:26:42

标签: spring maven maven-war-plugin maven-compiler-plugin

我正在尝试将Spring BOM添加到我的项目中。我的POM在下面。

  1. 我在这里没有做正确的事吗?
  2. 另外,一个半相关的问题:为什么spring-ws,spring-data-jpa和其他版本的版本号与spring core,context等版本不一致?

    <build>
        <finalName>myproject</finalName>
        <plugins>
            <plugin>
                <version>3.1</version>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-framework-bom</artifactId>
                <version>4.0.3.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>commons-logging</groupId>
                        <artifactId>commons-logging</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </dependency>
        ...
        </dependencies>
    </dependencyManagement>
    
    <dependencies>
    
        <!-- Spring -->
        <dependency>
            <groupId>org.springframework.ws</groupId>
            <artifactId>spring-ws-core</artifactId>
            <version>${spring-ws.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>${spring-data-jpa.version}</version>
        </dependency>
    ...
    </dependencies>
    

  3. 它会产生以下错误:

    [INFO] BUILD FAILURE
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time: 3.863s
    [INFO] Finished at: Fri May 09 13:15:24 EDT 2014
    [INFO] Final Memory: 17M/214M
    [INFO] ------------------------------------------------------------------------
    [ERROR] Failed to execute goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war (default-war) on
    project myproject: Execution default-war of goal org.apache.maven.plugins:maven-war-plugin
    :2.1.1:war failed: For artifact {org.springframework:spring-core:null:jar}: The version cannot be em
    pty. -> [Help 1]
    org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plug
    ins:maven-war-plugin:2.1.1:war (default-war) on project myproject: Execution default-war o
    f goal org.apache.maven.plugins:maven-war-plugin:2.1.1:war failed: For artifact {org.springframework
    :spring-core:null:jar}: The version cannot be empty.
    

1 个答案:

答案 0 :(得分:3)

非BOM Spring依赖项位于dependencies部分,而不是dependencyManagement

<dependencies>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework.ws</groupId>
        <artifactId>spring-ws-core</artifactId>
        <version>${spring-ws.version}</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.data</groupId>
        <artifactId>spring-data-jpa</artifactId>
        <version>${spring-data-jpa.version}</version>
    </dependency>
   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <exclusions>
            <exclusion>
                <groupId>commons-logging</groupId>
                <artifactId>commons-logging</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
    </dependency>
</dependencies>