1

我正在使用jgitver 库使用 Git 存储库的状态自动生成semver 。

我有一个多模块项目,其中模块是相互依赖的,这意味着如果我对一个模块进行更改,那么其他模块应该开始引用已更改模块的新版本。

所有模块都在同一个 Git 存储库中,因此 Git 中的任何更改都会更改所有模块的版本。以下是我的项目结构的示例

.git   (Common repository)
module1
common-module
pom.xml (Parent POM)

以下是我如何包含依赖模块的示例

<-- POM of module1, includes common-module-->

    <dependency>
        <groupId> com.test</groupId>
        <artifactId>common-module</artifactId>
        <version>1.0.0</version> <!-- version generated by jgitver -->
    </dependency>

由于在任何时候由 和 生成的版本都是jgitver相同的,因为它们在同一个 Git 存储库中,所以我不想在所有模块中对版本进行硬编码。好像版本发生了变化,那么我将不得不手动更改所有模块中的版本以获取依赖关系。module1common-modulecommon-module

是否有类似的变量${project.version}可用于引用由 生成的当前版本jgitver

我希望配置module1如下

<dependency>
    <groupId> com.test</groupId>
    <artifactId>common-module</artifactId>
    <version>${JGITVER_GENERATED_VERSION_VARIABLE}</version> <!-- version generated by jgitver -->
</dependency>
4

2 回答 2

1

Sorry to be a bit late on this question I did not saw it before.

If you are in the same multi-module project, then usage of jgitver should not change the way you declare dependencies between sub-modules. Even with jgitver in the party you should still reference your sub-modules using project.version

<dependency> <groupId> com.test</groupId> <artifactId>common-module</artifactId> <version>${project.version}</version> <!-- use a reference to the POM model --> </dependency>

For the IDE, the problem is a bit different because they do not like that much the dynamic behavior of jgitver (same for Eclipse & Intellij IDEA at least). You can have a look at the wiki page about jgitver IDE usage by using profiles and/or deactivation ; you can then use your IDE normally but you will have to delegate to either maven or gradle a normal build for release/deployments.

Hope that helps.

--
Matthieu, author and maintainer of jgitver

于 2018-09-18T07:31:43.693 回答
0

事实证明,有一个属性可用于指定自发布jgitver.calculated_version以来计算的版本0.2.0-alpha20.2.0-alpha2然而,自同一个版本以来,它应该是不需要的。

想要指定计算版本作为依赖版本的子模块应该使用project.version. 静态值保持为 0,当使用 maven 构建项目时,project.version将解析为正确的值。

在遇到以下问题后,我遇到了这个问题多模块项目:仅构建子模块无法解析 deps 的版本

project.version只要它的项目是从父级构建的,它就可以工作,如果项目是从子模块目录本身构建的,它就不起作用。project.version解决0并因此导致错误common-module-0.jar丢失。该问题已关闭,并且jgitver应该从子模块开始工作0.2.0-alpha2。但是它不适用于某些版本的 Maven。

在项目的 github 页面上提到了 maven 的最低版本应该是3.3.2Ref: jgitver-maven-plugin 至少需要 maven-3.3.2 才能正常工作。. 但是对我来说jgitver 1.1.4不适用于 maven3.3.5并且 build 会继续导致common-module-0仅在构建子模块时丢失错误。我可以确认它适用于 maven 3.3.9。我之所以知道这一点,是因为我在两台不同的机器上使用两种不同版本的 Maven 工作。我已将 maven 更新到当前版本3.5.2,它在子模块中运行良好。

注意:似乎我的 IDESTS 3.8.4/Eclipse Mars.2 (4.5.2)无法解析项目的计算版本,project.version它试图解析common-module-0. 只要这个项目在 Eclipse 中打开,它就可以解决。可能这就是它应该如何工作的方式。

于 2017-12-18T17:00:21.097 回答