Spring Boot project to create a multi-module configuration [rpm]

A parent module creation

1. Create a spring boot for the demo project name

2. created above on a good project name demo, right click and select New-> Module, New Module to enter the page name is dubbo-server

3, create another Module, name as dubbo-client

4. Delete useless files and folders, including three modules mvnw, mvnw.cmd .mvn files and folders, src directory, only the parent module dependency management

5. Configure the parent 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.sun</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <!--<packaging>jar</packaging>-->
    <packaging>pom</packaging>  <!--父模块打包类型必须为pom-->

    <modules>
        <module>dubbo-server</module>
        <module>dubbo-client</module>
    </modules>

    <name>demo</name>
    <description>Practice the learned code</description>

    <!-- parent指明继承关系,给出被继承的父项目的具体信息-->
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.8.RELEASE</version>
        <relativePath/>
        <!-- lookup parent from repository -->
    </parent>

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

        <!- in the properties of the unified version control dependencies, clearer -> 
        <dubbo.version> 2.5.3 </dubbo.version>
        <zkclient.version> 0.10 </zkclient.version>artifactId>spring-boot-starter-test</artifactId>-->
                <!--<scope>test</scope>-->/zkclient.version>
    </properties>

    <dependencyManagement> <-! dependencyManagement for managing dependencies version number -> 
        <the Dependencies> 
            <-! deleted spring-boot-starter and spring-boot-starter-test, 
            because inherited parent ancestors already had, and rely on general dependencyManagement management should write the version number -> 
            <-! <dependency> -> 
                <-! <groupId> org.springframework.boot </ groupId> -> 
                <-! <artifactId> Starter-Boot-Spring </ the artifactId> -> 
            <-! </ dependency> -> 

            <-! <dependency> -> 
                <-! <the groupId> org.springframework.boot </ the groupId> - -> 
                <-! <the artifactId> Starter-Spring-Boot-Test </ the artifactId> ->
            <-! </ dependency> -> 

            <-! new subsequent desired Dubbo project dependency, dubbo, zk ->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>dubbo</artifactId>
                <!--<version>2.5.3</version>-->    <!--使用properties中配置的版本号-->
                <version>${dubbo.version}</version>
                <exclusions>
                    <exclusion>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring</artifactId>
                    </exclusion>
                </exclusions>
            </dependency>

            <dependency>
                <groupId>com.101tec</groupId>
                <the artifactId> zkclient </ the artifactId> 
                <-! <Version> 0.10 </ Version> -> <-! version number of the configuration properties -> 
                <Version> zkclient.version $ {} </ Version> 
            </ dependency> 
        </ the Dependencies> 

    </ dependencyManagement> 

    <-! the plug-in is playing the role of a package can run, you must write in the need to package the project. Here's parent module does not need to run the package, so delete the plugin. -> 
    <-! <Build> -> 
        <-! <Plugins> -> 
            <-! <Plugin> -> 
                <-! <The groupId> org.springframework.boot </ the groupId> - -> 
                <-! <the artifactId> Boot-Spring-Maven-plugin </ the artifactId> -> 
            <-! </ plugin>

6.dubbo-server\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.sun</groupId>
   <artifactId>dubbo-server</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>dubbo-server</name>
   <description>Demo project for Spring Boot</description>

   <!-- 子模块的parent要使用顶层的父模块-->
   <parent>
      <!--<groupId>org.springframework.boot</groupId>-->
      <!--<artifactId>spring-boot-starter-parent</artifactId>-->
      <!--<version>1.5.8.RELEASE</version>-->
      <!--<relativePath/>-->
      <groupId>com.sun</groupId>
      <artifactId>demo</artifactId>
      <version>0.0.1-SNAPSHOT</version>
   </parent>

   <!-- properties可删掉,会继承父模块的-->
   <!--<properties>-->
      <!--<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>-->
      <!--<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>-->
      <!--<java.version>1.8</java.version>-->
   <!--</properties>-->

   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
      </ dependency>

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <the artifactId> Starter-Spring-Boot-Test </ the artifactId> 
         <scope> Test </ scope> 
      </ dependency> 

      <-! new subsequent desired Dubbo project dependency, dubbo, zk. 
         Pom dependencyManagement parent module used to manage the version number of dependent sub-module is not required to write the version number pom, nor need Exclusion -> 
      <dependency> 
         <the groupId> com.alibaba </ the groupId> 
         <the artifactId> Dubbo </ the artifactId > 
         <-! <Version> 2.5.3 </ Version> -> 
         <-! <Exclusions> -> 
            <-! <Exclusion> -> 
               <-! <the groupId> org.springframework </ the groupId> -> 
               <-! <the artifactId> Spring </ the artifactId> -> 
            <!

         <groupId>com.101tec</groupId>
         <artifactId>zkclient</artifactId>
         <!--<version>0.10</version>-->
      </dependency>
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

</project>

7.dubbo-client/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.sun</groupId>
   <artifactId>dubbo-client</artifactId>
   <version>0.0.1-SNAPSHOT</version>
   <packaging>jar</packaging>

   <name>dubbo-client</name>
   <description>Demo project for Spring Boot</description>

   <!-- 子模块的parent要使用顶层的父模块-->
   <parent>
      <!--<groupId>org.springframework.boot</groupId>-->
      <!--<artifactId>spring-boot-starter-parent</artifactId>-->
      <!--<version>1.5.8.RELEASE</version>-->
      <!--<relativePath/>-->
      <groupId>com.sun</groupId>
      <artifactId>demo</artifactId>
      <version>0.0.1-SNAPSHOT</version>
   </parent>

   <!-- properties可删掉,会继承父模块的-->
   <!--<properties>-->
      <!--<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>-->
      <!--<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>-->
      <!--<java.version>1.8</java.version>-->
   <!--</properties>-->

   <dependencies>
      <dependency>
         <groupId>org.springframework.boot</groupId>
         <artifactId>spring-boot-starter</artifactId>
      </ dependency>
         <!--<exclusions>-->

      <dependency>
         <groupId>org.springframework.boot</groupId>
         <the artifactId> Starter-Spring-Boot-Test </ the artifactId> 
         <scope> Test </ scope> 
      </ dependency> 

      <-! need to start the web service module, in need of such dependence -> 
      <dependency> 
         <the groupId> ORG .springframework.boot </ the groupId> 
         <the artifactId> Starter-Spring-Boot-Web </ the artifactId> 
      </ dependency> 

      <-! new subsequent desired Dubbo project dependency, dubbo, zk 
         parent module pom used to dependencyManagement management relies version number, sub-module pom does not need to write the version number of 
         the parent module pom in there exclusion, sub-module pom Do not write Exclusion -> 
      <dependency> 
         <groupId> com.alibaba </ groupId> 
         <artifactId> Dubbo < / artifactId> 
         <-! <Version> 2.5.3 </version>-->
            <!--<exclusion>-->
               <!--<groupId>org.springframework</groupId>-->
               <!--<artifactId>spring</artifactId>-->
            <!--</exclusion>-->
         <!--</exclusions>-->
      </dependency>

      <dependency>
         <groupId>com.101tec</groupId>
         <artifactId>zkclient</artifactId>
         <!--<version>0.10</version>-->
      </dependency>

      <!--client模块需要依赖server模块-->
      <dependency>
         <groupId>com.sun</groupId>
         <artifactId>    dubbo-server</artifactId>
         <version>0.0.1-SNAPSHOT</version>
      </dependency>
   </dependencies>

   <build>
      <plugins>
         <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
         </plugin>
      </plugins>
   </build>

</project>      

Click on the right side of the IDEA Maven Projects, you can view each internal version number of dependency and reliance on each Dependencies module

 

 

 

Guess you like

Origin www.cnblogs.com/sunkang-work/p/12001374.html