首页
/ Semantic Versioning 技术文档

Semantic Versioning 技术文档

2024-12-20 19:14:32作者:董宙帆

1. 安装指南

1.1 通过 Maven 安装

要在 Maven 项目中使用 semantic-versioning,首先需要在 pom.xml 文件中添加依赖:

<dependency>
    <groupId>org.semver</groupId>
    <artifactId>enforcer-rule</artifactId>
    <version>0.9.33</version>
</dependency>

1.2 通过命令行工具安装

你可以通过下载 semver.jar 文件来使用命令行工具。下载后,你可以通过以下命令运行工具:

java -jar semver.jar --help

2. 项目的使用说明

2.1 命令行工具

semantic-versioning 提供了一个简单的命令行工具,用于检查 Java JAR 文件之间的 API 变化。以下是一些常用的命令:

  • 显示帮助信息

    java -jar semver.jar --help
    
  • 显示两个 JAR 文件之间的差异

    java -jar semver.jar --diff --base-jar previousJar --new-jar current.jar
    
  • 检查两个 JAR 文件的兼容性

    java -jar semver.jar --check --base-jar previousJar --new-jar current.jar
    
  • 推断新 JAR 文件的版本

    java -jar semver.jar --infer --base-version 1.0.0 --base-jar previous.jar --new-jar current.jar
    
  • 验证 JAR 文件的版本是否符合语义化版本规范

    java -jar semver.jar --validate --base-version 1.0.0 --base-jar previous.jar --new-version 1.0.1 --new-jar current.jar
    

2.2 Maven Enforcer 规则

semantic-versioning 还提供了一个 Maven Enforcer 规则,用于检查项目的版本是否符合语义化版本规范。你可以在 pom.xml 中配置该规则:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.0.1</version>
        ...
        <dependencies>
            ...
            <dependency>
                <groupId>org.semver</groupId>
                <artifactId>enforcer-rule</artifactId>
                <version>0.9.33</version>
            </dependency>
            ...
        </dependencies>
        ...
        <executions>
           ....
          <execution>
            <id>check</id>
            <phase>verify</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireSemanticVersioningConformance implementation="org.semver.enforcer.RequireSemanticVersioningConformance" />
              </rules>
            </configuration>
          </execution>
          ...
        </executions>
        ...
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

3. 项目API使用文档

3.1 API 概述

semantic-versioning 提供了一个 API,用于以编程方式验证项目的版本号是否符合语义化版本规范。以下是一个简单的示例:

final File previousJar = ...;
final File currentJar = ...;
        
final Comparer comparer = new Comparer(previousJar, currentJar, ..., ...);
final Delta delta = comparer.diff();

final String compatibilityType = ...;

// 验证计算的兼容性类型是否与提供的兼容性类型兼容
final Delta.CompatibilityType expectedCompatibilityType = Delta.CompatibilityType.valueOf(compatibilityType);
final Delta.CompatibilityType detectedCompatibilityType = delta.computeCompatibilityType();
if (detectedCompatibilityType.compareTo(expectedCompatibilityType) > 0) {
  // 不兼容
}

// 提供 previous 和 current Jar 文件的版本号
final Version previous = Version.parse(...);
final Version current = Version.parse(...);

// 验证当前版本号是否基于语义化版本原则有效
final boolean compatible = delta.validate(previous, current);

3.2 Maven Enforcer 规则 API

semantic-versioning 还提供了一个 Maven Enforcer 规则 API,用于检查项目的版本是否符合语义化版本规范。你可以在 pom.xml 中配置该规则:

<project>
  ...
  <build>
    ...
    <plugins>
      ...
      <plugin>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.0.1</version>
        ...
        <dependencies>
            ...
            <dependency>
                <groupId>org.semver</groupId>
                <artifactId>enforcer-rule</artifactId>
                <version>0.9.33</version>
            </dependency>
            ...
        </dependencies>
        ...
        <executions>
           ....
          <execution>
            <id>check</id>
            <phase>verify</phase>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireSemanticVersioningConformance implementation="org.semver.enforcer.RequireSemanticVersioningConformance" />
              </rules>
            </configuration>
          </execution>
          ...
        </executions>
        ...
      </plugin>
      ...
    </plugins>
    ...
  </build>
  ...
</project>

4. 项目安装方式

4.1 通过 Maven 安装

在 Maven 项目中,你可以通过在 pom.xml 文件中添加以下依赖来安装 semantic-versioning

<dependency>
    <groupId>org.semver</groupId>
    <artifactId>enforcer-rule</artifactId>
    <version>0.9.33</version>
</dependency>

4.2 通过命令行工具安装

你可以通过下载 semver.jar 文件来使用命令行工具。下载后,你可以通过以下命令运行工具:

java -jar semver.jar --help

通过以上步骤,你可以轻松安装并使用 semantic-versioning 来验证你的项目版本是否符合语义化版本规范。

登录后查看全文
热门项目推荐

热门内容推荐

项目优选

收起
docsdocs
OpenHarmony documentation | OpenHarmony开发者文档
Dockerfile
149
1.95 K
kernelkernel
deepin linux kernel
C
22
6
openHiTLSopenHiTLS
旨在打造算法先进、性能卓越、高效敏捷、安全可靠的密码套件,通过轻量级、可剪裁的软件技术架构满足各行业不同场景的多样化要求,让密码技术应用更简单,同时探索后量子等先进算法创新实践,构建密码前沿技术底座!
C
980
395
ohos_react_nativeohos_react_native
React Native鸿蒙化仓库
C++
192
274
RuoYi-Vue3RuoYi-Vue3
🎉 (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
Vue
931
555
openGauss-serveropenGauss-server
openGauss kernel ~ openGauss is an open source relational database management system
C++
145
190
nop-entropynop-entropy
Nop Platform 2.0是基于可逆计算理论实现的采用面向语言编程范式的新一代低代码开发平台,包含基于全新原理从零开始研发的GraphQL引擎、ORM引擎、工作流引擎、报表引擎、规则引擎、批处理引引擎等完整设计。nop-entropy是它的后端部分,采用java语言实现,可选择集成Spring框架或者Quarkus框架。中小企业可以免费商用
Java
8
0
金融AI编程实战金融AI编程实战
为非计算机科班出身 (例如财经类高校金融学院) 同学量身定制,新手友好,让学生以亲身实践开源开发的方式,学会使用计算机自动化自己的科研/创新工作。案例以量化投资为主线,涉及 Bash、Python、SQL、BI、AI 等全技术栈,培养面向未来的数智化人才 (如数据工程师、数据分析师、数据科学家、数据决策者、量化投资人)。
Jupyter Notebook
75
66
openHiTLS-examplesopenHiTLS-examples
本仓将为广大高校开发者提供开源实践和创新开发平台,收集和展示openHiTLS示例代码及创新应用,欢迎大家投稿,让全世界看到您的精巧密码实现设计,也让更多人通过您的优秀成果,理解、喜爱上密码技术。
C
65
518
CangjieCommunityCangjieCommunity
为仓颉编程语言开发者打造活跃、开放、高质量的社区环境
Markdown
1.11 K
0