@conveyal/maven-semantic-release

中文文档
5.0.0发布于 2021/01/12MITCommonJS近 30 天下载 7254

Automated release management for maven projects

原始使用文档
文档目录9 节
  1. About
  2. Setup
  3. Step 1: Setup an account with OSSRH
  4. Step 2: Make sure your pom.xml file is ready to be released
  5. Step 3: Create a maven-settings.xml file
  6. Step 4: Create gpg keys to sign your artifact
  7. Step 5: Create a .travis.yml file that'll run maven-semanti…
  8. Step 6: Add a github token to Travis
  9. Which mvn will be used

maven-semantic-release

Automated release management for maven projects

About

maven-semantic-release is a plugin for semantic-release v16+. This project will deploy a maven project to maven central instead of deploying a node.js project to npm. This tool is intended to be used on github projects that use a Travis-CI server.

The workflow this assumes is that your project will use Angular-style commit messages (theoretically you could override this and use a different style) and only merge to master when you want to create a new release. When a new release is generated, it will automatically be deployed to maven central.

Optionally, you can also use this enable this tool to create and push some commits and then merge those back into the development branch of your git repository.

Setup

This tool is intended to automate the releases of maven projects to maven central. However, a lot of manual steps unfortunately must be taken to get your maven project setup so it can work properly. Big thanks to Nathan Fischer for detailing how to do a lot of these steps in a blog post here.

If your project merely wants to take advantage of committing version numbers and creating nice release notes on your github project, you can skip steps 1-4. In step 5, the creation of the maven artifact signing key can be skipped and the skip-maven-deploy flag must be set.

Step 1: Setup an account with OSSRH

Follow this guide.

Step 2: Make sure your pom.xml file is ready to be released

See this example project for a sample pom.xml.

Your maven project needs to have at least the following items in your pom.xml:

  • name - the name of the project
  • description - a short description
  • url - location where users can go to get more information about the library
  • licences - self explanatory
  • scm - source control information
  • developers - who worked on the project
  • distributionManagement - the places where you want to distribute your project to

Plugins

Your pom.xml file needs to have the following maven plugins included:

  • maven-gpg-plugin
  • maven-javadoc-plugin
  • maven-source-plugin

Your pom.xml file also needs the following sonatype plugin to automatically close and release your project from nexus.

  • nexus-staging-maven-plugin

See this example project for a sample pom.xml.

Step 3: Create a maven-settings.xml file

You can copy paste this file into your repository. The file must be called maven-settings.xml and must exist in the root directory of your project.

Step 4: Create gpg keys to sign your artifact

Follow the all steps from Create code signing cert to Encrypt cert and variables for travis in this guide. When adding keys to Travis you could also add them using the Travis-CI website in the settings of your repository instead of adding secure variables to your .travis.yml file.

We wish you good luck as this step is really easy to mess up and get exactly right. Adding your password to travis can be infuriating as you may need to escape parts of it if it has a space, @ symbol or something else.

Step 5: Create a .travis.yml file that'll run maven-semantic-release after success

See this example file. In your .travis.yml file you'll want the following items:

after_success

After the success of your CI Run, you'll want to run semantic-release with the maven-semantic-release plugins. At a minimum, you must include the following recommended configuration. This includes overriding the plugins so that the default npm plugin is not used.

after_success:
  - semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release

If you want to enable the Conveyal workflow of making commits of the release version, snapshot version and then merging master into dev, use this configuration:

after_success:
  - semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release --use-conveyal-workflow --dev-branch=dev

It is also possible to skip deploying to maven central, but still incrementing the version in pom.xml by setting the flag skip-maven-deploy. For example:

after_success:
  - semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release --use-conveyal-workflow --dev-branch=dev --skip-maven-deploy

By default the commit message contains the appendix '[ci skip]' that skips the pipeline to run when the pom.xml is pushed. This can be disabled for snapshot and final versions if needed by providing the flag disable-snapshot-skip-ci or disable-final-skip-ci. For example:

after_success:
  - semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release --use-conveyal-workflow --dev-branch=dev --disable-snapshot-skip-ci --disable-final-skip-ci

If you use the conveyal workflow just the updated pom.xml will be part of the commit. To add more files to the commit (e.g. a CHANGELOG.md generated by a different plugin) you can specify those via the parameter --additionalFilesToCommit. This parameter accepts a list of filenames and will include them in the commit. Example:

after_success:
  - semantic-release --prepare @conveyal/maven-semantic-release --publish @semantic-release/github,@conveyal/maven-semantic-release --verify-conditions @semantic-release/github,@conveyal/maven-semantic-release --verify-release @conveyal/maven-semantic-release --use-conveyal-workflow --dev-branch=dev --additionalFilesToCommit CHANGELOG.md,readme.txt

before_install

Be sure to include the import of your signing keys. If you followed everything correctly in step 4 you should have something like the following added to your .travis.yml file:

before_install: |
  # only install signing keys under the same circumstances we do a mvn deploy later
  if [[ "$TRAVIS_PULL_REQUEST" = false ]] && [[ "$TRAVIS_BRANCH" = master ]]; then
    openssl aes-256-cbc -K $encrypted_### -iv $encrypted_### -in maven-artifact-signing-key.asc.enc -out maven-artifact-signing-key.asc -d
    gpg --import --batch maven-artifact-signing-key.asc
  fi

cache:

This should help speed up the installation of maven-semantic-release. You'll want to include the m2 directory as well.

cache:
  directories:
    - $HOME/.m2
    - $HOME/.yarn-cache

Also, you'll want to install maven-semantic-release and semantic-release in a step before the build because travis caches immediately after the build.

before_script:
  - yarn global add @conveyal/maven-semantic-release semantic-release

Step 6: Add a github token to Travis

Create a Github token that will be used to make commits and create releases. Add the token to your travis environment variables as either GH_TOKEN or GITHUB_TOKEN. Add the following permissions to your token:

Which mvn will be used

This plugin uses the mvn command in your PATH. If you have maven-wrapper script at the project root directory, this plugin will use that instead.

版本与发布记录

@conveyal/maven-semantic-release 共发布 37 个版本,首次发布于 2018/02/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
5.0.0latest2021/01/125 年前
4.5.02019/10/267 年前
4.4.02019/08/097 年前
4.3.02019/03/027 年前
4.2.02019/01/057 年前
4.1.12018/11/307 年前

关于 @conveyal/maven-semantic-release 的常见问题

@conveyal/maven-semantic-release 是什么?

Automated release management for maven projects

如何安装 @conveyal/maven-semantic-release?

在项目目录运行 npm install @conveyal/maven-semantic-release,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:semantic-release(^17.3.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@conveyal/maven-semantic-release 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/conveyal__maven-semantic-release 是否存在。

@conveyal/maven-semantic-release 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@conveyal/maven-semantic-release 可以商用吗?

@conveyal/maven-semantic-release 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@conveyal/maven-semantic-release 的下载量有多少?

根据 npm 官方下载统计,@conveyal/maven-semantic-release 在 2026/10/11 – 2026/11/09 这 30 天内被下载 7,254 次,日均约 242 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@conveyal/maven-semantic-release 还在维护吗?

最新版本 5.0.0 发布于 2021/01/12(5 年前);至今共发布 37 个版本,其中过去 12 个月发布了 0 个;首次发布于 2018/02/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。