Maven配置文件

Maven配置文件

  • 关于 pom.xml文件: 是每个项目都存在的配置文件,包含版本管理,依赖处理,项目信息等.

<project>
  <modelVersion>4.0.0</modelVersion>
  <!-- 组ID -->
  <groupId>com.example</groupId> 
  <!-- 项目ID -->
  <artifactId>my-first-app</artifactId>
    
  <!-- 发行版本,代表开发版 -->
  <version>1.0-SNAPSHOT</version> 

  <!--
  以下为其他版本示例(已注释)
  <version>1.0-BETA</version>   测试版
  <version>1.0-M1</version>      里程碑版
  <version>1.0-GA</version>      正式稳定版
  -->

  <!-- 指定JDK版本 + 编码 -->
  <properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <!-- JUnit 5 最新版(现在标准) -->
  <dependencies>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-api</artifactId>
      <version>5.10.0</version>
      <scope>test</scope>
    </dependency>
    
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <version>5.10.0</version>
      <scope>test</scope>
    </dependency>
    
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>RELEASE</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>7.0.7</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
</project>

<!--
依赖范围说明:
<scope>compile</scope>  编译时&&运行时依赖,打包会放进项目
<scope>provided</scope>  仅编译时需要,不打包进项目
<scope>runtime</scope>   编译时不用,运行时需要
<scope>test</scope>      仅测试时需要,正式代码不使用
-->
  • <dependency></>:依赖管理:
<dependencies>
    
  <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>3.8.1</version>
    <scope>test</scope>
  </dependency>

  <!-- Source: https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
  <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>7.0.7</version>
      <scope>compile</scope>
  </dependency>
  . . .
    
</dependencies>

其中,大多数开源依赖都可以去MvnRepo官网查询,复制粘贴到 .xml 文件中即可:

jdbc 依赖查询

jdbc 依赖查询
  • <properties></>:全局变量:

<properties>
  <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
    <maven.compiler.encoding>UTF-8</maven.compiler.encoding>

  <spring.version>6.1.11</spring.version>

  . . .
</properties>

<dependency>
. . .
  <version>${spring.version}</version>
    
</dependency>

使用社交账号登录

  • Loading...
  • Loading...
  • Loading...
  • Loading...
  • Loading...