mybatis-mapper / mapper

MyBatis Mapper
https://mapper.mybatis.io
Apache License 2.0
325 stars 47 forks source link

bom子模块依赖关系冲突 #67

Closed JoeyBling closed 1 year ago

JoeyBling commented 1 year ago

  bom子模块依赖了父模块mybatis-parent,父模块也声明了其它依赖管理dependencyManagement,则会覆盖spring-boot项目parent的声明,导致spring-boot-dependencies声明失效,

在里面有声明spring-framework-bom,会导致Spring框架工件版本和spring-boot管理的版本不一致

引入spring-boot

<parent>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-parent -->
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.4</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

依赖管理引入bom模块

<!-- 依赖管理 -->
<dependencyManagement>
<dependency>
<groupId>io.mybatis</groupId>
<artifactId>mapper-bom</artifactId>
<version>2.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencyManagement>

JoeyBling commented 1 year ago

 建议2种方式处理

  1. bom子模块还是按照最开始的样子单独管理,不依赖于parent
  2. 父模块mybatis-parent去除依赖管理dependencyManagement
JoeyBling commented 1 year ago

BOM模块应该仅仅只有是该组件包各个子模块的依赖声明,不应出现其它依赖管理

abel533 commented 1 year ago

bom添加下面的配置:

<build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>flatten-maven-plugin</artifactId>
        <version>1.1.0</version>
        <configuration>
          <updatePomFile>true</updatePomFile>
          <flattenMode>bom</flattenMode>
        </configuration>
        <executions>
          <execution>
            <id>flatten</id>
            <phase>process-resources</phase>
            <goals>
              <goal>flatten</goal>
            </goals>
          </execution>
          <execution>
            <id>flatten.clean</id>
            <phase>clean</phase>
            <goals>
              <goal>clean</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

重点是 <flattenMode>bom</flattenMode>,生成的 pom 如下:

<?xml version="1.0" encoding="UTF-8"?>
<!--
  ~ Copyright 2020-2022 the original author or authors.
  ~
  ~ Licensed under the Apache License, Version 2.0 (the "License");
  ~ you may not use this file except in compliance with the License.
  ~ You may obtain a copy of the License at
  ~
  ~    http://www.apache.org/licenses/LICENSE-2.0
  ~
  ~ Unless required by applicable law or agreed to in writing, software
  ~ distributed under the License is distributed on an "AS IS" BASIS,
  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  ~ See the License for the specific language governing permissions and
  ~ limitations under the License.
  -->
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <modelVersion>4.0.0</modelVersion>
  <groupId>io.mybatis</groupId>
  <artifactId>mapper-bom</artifactId>
  <version>2.0.1-SNAPSHOT</version>
  <packaging>pom</packaging>
  <name>mapper-bom</name>
  <description>MyBatis Mapper (Bill of Materials) | 依赖版本管理</description>
  <url>https://mybatis.io/mapper-bom</url>
  <licenses>
    <license>
      <name>Apache License 2.0</name>
      <url>https://github.com/mybatis-mapper/mapper/blob/master/LICENSE</url>
    </license>
  </licenses>
  <developers>
    <developer>
      <name>abel533</name>
      <email>abel533@gmail.com</email>
    </developer>
  </developers>
  <scm>
    <connection>scm:git:git@github.com:mybatis-mapper/mapper.git/mapper-bom</connection>
    <developerConnection>scm:git:git@github.com:mybatis-mapper/mapper.git/mapper-bom</developerConnection>
    <url>git@github.com:mybatis-mapper/mapper.git/mapper-bom</url>
  </scm>
  <properties>
    <junit.version>4.13</junit.version>
    <mybatis.version>3.5.10</mybatis.version>
    <mybatis-spring.version>2.0.7</mybatis-spring.version>
    <springframework.version>5.3.21</springframework.version>
    <maven.compiler.target>8</maven.compiler.target>
    <hsqldb.version>2.5.2</hsqldb.version>
    <springboot.version>2.7.1</springboot.version>
    <provider.version>2.1.1</provider.version>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <mybatis-spring-boot.version>2.2.2</mybatis-spring-boot.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <logback.version>1.2.11</logback.version>
    <revision>2.0.1-SNAPSHOT</revision>
    <maven.compiler.source>8</maven.compiler.source>
    <argLine>-Dfile.encoding=UTF-8</argLine>
  </properties>
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>io.mybatis</groupId>
        <artifactId>mybatis-provider</artifactId>
        <version>${provider.version}</version>
      </dependency>
      <dependency>
        <groupId>io.mybatis</groupId>
        <artifactId>mybatis-common</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>io.mybatis</groupId>
        <artifactId>mybatis-mapper</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>io.mybatis</groupId>
        <artifactId>mybatis-service</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>io.mybatis</groupId>
        <artifactId>mybatis-activerecord</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>io.mybatis</groupId>
        <artifactId>mybatis-generator</artifactId>
        <version>${project.version}</version>
      </dependency>
      <dependency>
        <groupId>io.mybatis</groupId>
        <artifactId>mybatis-jpa</artifactId>
        <version>${project.version}</version>
      </dependency>
    </dependencies>
  </dependencyManagement>
  <repositories>
    <repository>
      <releases>
        <enabled>false</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>maven-snapshots</id>
      <url>https://oss.sonatype.org/content/repositories/snapshots</url>
    </repository>
  </repositories>
</project>