美文网首页
项目结构以及jar 依赖管理

项目结构以及jar 依赖管理

作者: collery | 来源:发表于2017-10-25 07:56 被阅读0次

项目目录结构

├── apps
│   ├── api-platform
│   │   ├── src
│   │   └── target
│   └── manage-platform
│       ├── src
│       └── target
├── build
│   └── db
│       ├── alter_v1.0.0
│       └── init
├── common
│   ├── 3rd-libs
│   │   ├── src
│   │   └── target
│   └── util
│       ├── src
│       └── target
├── doc
└── feature
    ├── app
    │   ├── app-api
    │   └── app-service
    ├── flow
    │   ├── flow-api
    │   └── flow-service
    ├── openservice
    │   ├── openservice-api
    │   └── openservice-service
    └── security
        ├── security-api
        └── security-service  

依赖集中管理

  1. 在父目录管理所有依赖的jar包
  2. 将公共的jar包放入3rd-libs中,并保持尽量最小
  3. 父目录管理jar包的版本
  4. 父pom中将子pom中依赖的爷爷pom中的jar包显式的标记出来
<!--父目录依赖管理 -->
<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.3.RELEASE</version>
        <relativePath/>
</parent>
    
<dependencyManagement>

    <dependencies>
    
    <!--springboot的这两个starter包在父项目spring-boot-starter-parent中进行了包管理,此处说明注释-->
        <!--<dependency>-->
            <!--<groupId>org.springframework.boot</groupId>-->
            <!--<artifactId>spring-boot-starter</artifactId>-->
        <!--</dependency>-->
    
       <!-- 具体的某个依赖-->
        <dependency>
                <groupId>org.mybatis</groupId>
                <artifactId>mybatis</artifactId>
                <!-- 版本在 properties 中指定-->
                <version>${mybatis.version}</version>
            </dependency>
            
    </dependencies>
</dependencyManagement>


<!--子pom -->
<dependencies>
    <!--无需指定版本,已经在父pom中指定 -->
    <dependency>
        <groupId>org.mybatis</groupId>
        <artifactId>mybatis</artifactId>
    </dependency>
    
    <!--这个引用其实已经在爷爷pom中指定了 -->
    <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
    </dependency>


    
</dependencies>

严格的依赖控制

  1. api 中严禁依赖其他jar包
  2. service 中只准依赖api
  3. 明确原则,并明显的标识出来
<!-- api pom 示例-->

<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>

    <artifactId>flow-api</artifactId>
    <packaging>jar</packaging>

    <name>flow-api</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>com.mytijian.openapi</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../../..</relativePath>
        <artifactId>open-api</artifactId>
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <!-- 不能依赖任何包和工程 -->

</project>

相关文章

网友评论

      本文标题:项目结构以及jar 依赖管理

      本文链接:https://www.haomeiwen.com/subject/rxbfpxtx.html