当前位置:   article > 正文

Maven

Maven

Maven作用

方便的依赖管理

工程所需要的依赖,只需要坐标即可。

统一的项目结构

标准的构建流程

清理,编译,打包,安装,部署......

Maven的定义

maven是管理和构建项目的工具。

Maven仓库

本地仓库

先从本地仓库引用jar包。

中央仓库

本地没有,则从中央仓库下载。

私服

国内搭建的服务平台

Maven坐标

一般三部分组成。

g

groupId 组织名。

a

artifactId 工程名。

v

version 版本号。

Maven高级

分模块设计

父类pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>com.itheima</groupId>
  7. <artifactId>tlias-pojo</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <properties>
  10. <maven.compiler.source>17</maven.compiler.source>
  11. <maven.compiler.target>17</maven.compiler.target>
  12. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  13. </properties>
  14. <!--引入父工程依赖-->
  15. <parent>
  16. <groupId>com.itheima</groupId>
  17. <artifactId>tlias-parent</artifactId>
  18. <version>1.0-SNAPSHOT</version>
  19. <relativePath>../tlias-parent/pom.xml</relativePath>
  20. </parent>
  21. <dependencies>
  22. <!--lombok-->
  23. <dependency>
  24. <groupId>org.projectlombok</groupId>
  25. <artifactId>lombok</artifactId>
  26. </dependency>
  27. </dependencies>
  28. <build>
  29. <plugins>
  30. <plugin>
  31. <groupId>org.apache.maven.plugins</groupId>
  32. <artifactId>maven-compiler-plugin</artifactId>
  33. <configuration>
  34. <source>8</source>
  35. <target>8</target>
  36. </configuration>
  37. </plugin>
  38. </plugins>
  39. </build>
  40. </project>

子类pom.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <!--依赖引入父工程-->
  6. <parent>
  7. <groupId>com.itheima</groupId>
  8. <artifactId>tlias-parent</artifactId>
  9. <version>1.0-SNAPSHOT</version>
  10. <relativePath>../tlias-parent/pom.xml</relativePath>
  11. </parent>
  12. <groupId>com.itheima</groupId>
  13. <artifactId>tlias-web-management</artifactId>
  14. <version>0.0.1-SNAPSHOT</version>
  15. <properties>
  16. <maven.compiler.source>17</maven.compiler.source>
  17. <maven.compiler.target>17</maven.compiler.target>
  18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  19. </properties>
  20. <dependencies>
  21. <!--引入父类的依赖,就可以使用父类的配置,以及父类的代码-->
  22. <!--引入pojo依赖-->
  23. <dependency>
  24. <groupId>com.itheima</groupId>
  25. <artifactId>tlias-pojo</artifactId>
  26. <version>1.0-SNAPSHOT</version>
  27. </dependency>
  28. <!--引入utils-->
  29. <dependency>
  30. <groupId>com.itheima</groupId>
  31. <artifactId>tlias-utils</artifactId>
  32. <version>1.0-SNAPSHOT</version>
  33. </dependency>
  34. <!--web起步依赖-->
  35. <dependency>
  36. <groupId>org.springframework.boot</groupId>
  37. <artifactId>spring-boot-starter-web</artifactId>
  38. </dependency>
  39. <!--mybatis起步依赖-->
  40. <dependency>
  41. <groupId>org.mybatis.spring.boot</groupId>
  42. <artifactId>mybatis-spring-boot-starter</artifactId>
  43. <version>2.2.2</version>
  44. </dependency>
  45. <!--mysql驱动-->
  46. <dependency>
  47. <groupId>com.mysql</groupId>
  48. <artifactId>mysql-connector-j</artifactId>
  49. <scope>runtime</scope>
  50. </dependency>
  51. <!--springboot单元测试-->
  52. <dependency>
  53. <groupId>org.springframework.boot</groupId>
  54. <artifactId>spring-boot-starter-test</artifactId>
  55. <scope>test</scope>
  56. </dependency>
  57. <!--PageHelper分页插件-->
  58. <dependency>
  59. <groupId>com.github.pagehelper</groupId>
  60. <artifactId>pagehelper-spring-boot-starter</artifactId>
  61. <version>1.4.2</version>
  62. </dependency>
  63. <!--fastJSON-->
  64. <dependency>
  65. <groupId>com.alibaba</groupId>
  66. <artifactId>fastjson</artifactId>
  67. <version>1.2.76</version>
  68. </dependency>
  69. <!--AOP-->
  70. <dependency>
  71. <groupId>org.springframework.boot</groupId>
  72. <artifactId>spring-boot-starter-aop</artifactId>
  73. </dependency>
  74. <dependency>
  75. <groupId>org.projectlombok</groupId>
  76. <artifactId>lombok</artifactId>
  77. </dependency>
  78. </dependencies>
  79. <build>
  80. <plugins>
  81. <plugin>
  82. <groupId>org.springframework.boot</groupId>
  83. <artifactId>spring-boot-maven-plugin</artifactId>
  84. <configuration>
  85. <excludes>
  86. <exclude>
  87. <groupId>org.projectlombok</groupId>
  88. <artifactId>lombok</artifactId>
  89. </exclude>
  90. </excludes>
  91. </configuration>
  92. </plugin>
  93. </plugins>
  94. </build>
  95. </project>

继承与聚合

父工程需要引入springboot官方依赖

父类pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  5. <modelVersion>4.0.0</modelVersion>
  6. <groupId>com.itheima</groupId>
  7. <artifactId>tlias-parent</artifactId>
  8. <version>1.0-SNAPSHOT</version>
  9. <!--父工程 打包方式pom-->
  10. <packaging>pom</packaging>
  11. <!--父工程指向的父依赖springboot官方版本依赖-->
  12. <parent>
  13. <groupId>org.springframework.boot</groupId>
  14. <artifactId>spring-boot-starter-parent</artifactId>
  15. <version>2.7.5</version>
  16. <relativePath/> <!-- lookup parent from repository -->
  17. </parent>
  18. <!--聚合其他模块 指定要聚合的模块有哪些-->
  19. <modules>
  20. <module>../tlias-pojo</module>
  21. <module>../tlias-utils</module>
  22. <module>../tlias-web-management</module>
  23. </modules>
  24. <properties>
  25. <maven.compiler.source>17</maven.compiler.source>
  26. <maven.compiler.target>17</maven.compiler.target>
  27. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  28. <!--版本统一控制-->
  29. <jwt.version>0.9.1</jwt.version>
  30. <lombok.version>1.18.30</lombok.version>
  31. </properties>
  32. <!--在这里引入依赖,父类就会下载依赖-->
  33. <dependencies>
  34. </dependencies>
  35. <!--管理子模块依赖的版本号,但是不会下载依赖-->
  36. <dependencyManagement>
  37. <dependencies>
  38. <!--lombok-->
  39. <dependency>
  40. <groupId>org.projectlombok</groupId>
  41. <artifactId>lombok</artifactId>
  42. <version>${lombok.version}</version>
  43. </dependency>
  44. <!--JWT令牌-->
  45. <dependency>
  46. <groupId>io.jsonwebtoken</groupId>
  47. <artifactId>jjwt</artifactId>
  48. <version>${jwt.version}</version>
  49. </dependency>
  50. </dependencies>
  51. </dependencyManagement>
  52. </project>

子类pom.xml

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  4. <modelVersion>4.0.0</modelVersion>
  5. <!--依赖引入父工程-->
  6. <parent>
  7. <groupId>com.itheima</groupId>
  8. <artifactId>tlias-parent</artifactId>
  9. <version>1.0-SNAPSHOT</version>
  10. <relativePath>../tlias-parent/pom.xml</relativePath>
  11. </parent>
  12. <groupId>com.itheima</groupId>
  13. <artifactId>tlias-web-management</artifactId>
  14. <version>0.0.1-SNAPSHOT</version>
  15. <properties>
  16. <maven.compiler.source>17</maven.compiler.source>
  17. <maven.compiler.target>17</maven.compiler.target>
  18. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  19. </properties>
  20. <dependencies>
  21. <!--引入pojo依赖-->
  22. <dependency>
  23. <groupId>com.itheima</groupId>
  24. <artifactId>tlias-pojo</artifactId>
  25. <version>1.0-SNAPSHOT</version>
  26. </dependency>
  27. <!--引入utils-->
  28. <dependency>
  29. <groupId>com.itheima</groupId>
  30. <artifactId>tlias-utils</artifactId>
  31. <version>1.0-SNAPSHOT</version>
  32. </dependency>
  33. <!--web起步依赖-->
  34. <dependency>
  35. <groupId>org.springframework.boot</groupId>
  36. <artifactId>spring-boot-starter-web</artifactId>
  37. </dependency>
  38. <!--mybatis起步依赖-->
  39. <dependency>
  40. <groupId>org.mybatis.spring.boot</groupId>
  41. <artifactId>mybatis-spring-boot-starter</artifactId>
  42. <version>2.2.2</version>
  43. </dependency>
  44. <!--mysql驱动-->
  45. <dependency>
  46. <groupId>com.mysql</groupId>
  47. <artifactId>mysql-connector-j</artifactId>
  48. <scope>runtime</scope>
  49. </dependency>
  50. <!--springboot单元测试-->
  51. <dependency>
  52. <groupId>org.springframework.boot</groupId>
  53. <artifactId>spring-boot-starter-test</artifactId>
  54. <scope>test</scope>
  55. </dependency>
  56. <!--PageHelper分页插件-->
  57. <dependency>
  58. <groupId>com.github.pagehelper</groupId>
  59. <artifactId>pagehelper-spring-boot-starter</artifactId>
  60. <version>1.4.2</version>
  61. </dependency>
  62. <!--fastJSON-->
  63. <dependency>
  64. <groupId>com.alibaba</groupId>
  65. <artifactId>fastjson</artifactId>
  66. <version>1.2.76</version>
  67. </dependency>
  68. <!--AOP-->
  69. <dependency>
  70. <groupId>org.springframework.boot</groupId>
  71. <artifactId>spring-boot-starter-aop</artifactId>
  72. </dependency>
  73. <dependency>
  74. <groupId>org.projectlombok</groupId>
  75. <artifactId>lombok</artifactId>
  76. </dependency>
  77. </dependencies>
  78. <build>
  79. <plugins>
  80. <plugin>
  81. <groupId>org.springframework.boot</groupId>
  82. <artifactId>spring-boot-maven-plugin</artifactId>
  83. <configuration>
  84. <excludes>
  85. <exclude>
  86. <groupId>org.projectlombok</groupId>
  87. <artifactId>lombok</artifactId>
  88. </exclude>
  89. </excludes>
  90. </configuration>
  91. </plugin>
  92. </plugins>
  93. </build>
  94. </project>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/article/detail/48873?site
推荐阅读
相关标签
  

闽ICP备14008679号