我正在尝试找出更新其他几个 Java 项目使用的 POM 文件中的版本的最佳实践。我是 Java 和 Maven 的新手,但不是 OOP 和 semver。
我使用 maven 构建系统接管了一些带有 Java 代码的 git 存储库。我需要向其他几个存储库使用的“核心”存储库添加新功能,即使我只需要其中一个存储库即可从新功能中受益。我的希望是保持其他存储库不变。如果其他存储库被某些 devops 进程重新部署,我希望他们使用“核心”版本,而不需要对“核心”添加任何更改。
我认为我应该先更新“核心”存储库的 POM 文件中的版本,然后再将其工件存储在 Nexus 中,这样其他存储库就不会下载包含我的更改的“核心”版本。我应该使用什么mvn
命令?
现在,“核心”库声明其版本如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.team</groupId>
<artifactId>foo-core</artifactId>
<version>1.0.4-SNAPSHOT</version>
<packaging>jar</packaging>
<name>foo-core</name>
<url>http://maven.apache.org</url>
<blah/>
<blah/>
</project>
使用“核心”的项目具有如下所示的 POM:
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.company.team</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<description>Bar</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<dependencies>
<dependency>
<groupId>com.company.team</groupId>
<artifactId>foo-core</artifactId>
<version>1.0.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
我不确定什么时候<parent>
是一个有用的标签,但我注意到它没有被用来将应用程序存储库连接到“核心”存储库。
我想我想更新 POM
- 为核心
- 对于使用核心的一个项目,而不是也使用核心的其他项目。
I interpret the fact that the version -SNAPSHOT
is used in references to "core" by all the other projects to tell me that no "release" was created for the "core", at least at the current version. Can I skip ever making a release for 1.0.4 if I want to the version of "core" container my features to be 1.0.5-SNAPSHOT?
What are the commands I need to execute in both the "core" repo and the repo for the one project I want to use the new build? I think some commands simply modify the POM, but other commands will publish the build to Nexus.
Or can I just type a new number in the POM and run a mvn command to push the build to Nexus with the new version? If I simply change the value with a text editor, I plan to leave the word -SNAPSHOT
in the incremented version of "core" as well as the reference to "core" in the one app I want to use the new features. Then I will just need to publish core to Nexus.
--- UPDATE ---
I learned that this command will bump the version number in "core". It seems unnecessarily complex since you still need to type in the full version value when prompted by the CLI (I typed "1.0.5-SNAPSHOT").
mvn versions:set nestSnapshot
And I guess this is how you update the app to use the latest version of the dependency, but I think it only works if you succeeded to publish the dependency with mvn deploy
.
mvn versions:use-latest-releases -Dincludes=com.company.team:foo-core -DallowSnapshots=true