英文:
mvn command for updating version in dependency and one project that uses the dependency
问题
我正在尝试弄清楚在多个其他Java项目中使用的POM文件中更新版本的最佳实践。我对Java和Maven都不熟悉,但对OOP和语义版本控制很了解。
我接管了一些使用Maven构建系统的Java代码的Git仓库。我需要向“core”仓库添加新功能,该仓库被多个其他仓库使用,尽管我只需要一个仓库受益于新功能。我希望保持其他仓库不受影响。如果其他仓库通过某个DevOps流程重新部署,我希望它们继续使用“core”的版本,而不包含我添加到“core”的任何更改。
我认为我应该在将“core”的构建存储到Nexus之前,更新“core”仓库的POM文件中的版本,以便其他仓库不会下载包含我的更改的“core”版本。我应该使用什么mvn
命令?
目前,“core”库声明其版本如下:
<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>
使用“core”的项目具有如下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>
标签何时有用,但我注意到它没有用于将应用程序仓库与“core”仓库连接。
我想要更新POM:
- 为“core”。
- 并且为只想要使用新构建的一个项目,而不是其他使用“core”的项目。
我解释了在所有其他项目的引用中使用版本-SNAPSHOT
告诉我,至少在当前版本中没有为“core”创建“release”。如果我希望“core”包含我的功能的版本为1.0.5-SNAPSHOT
,我可以跳过创建1.0.4
的“release”吗?
我需要在“core”仓库和我想要使用新构建的仓库中执行哪些命令?我认为有些命令只是修改POM,但其他命令将构建发布到Nexus。
还是我只需在POM中键入新版本号,然后运行mvn命令将构建推送到Nexus以使用新版本?如果我只是使用文本编辑器更改值,我计划在增加的“core”版本以及我想要使用新功能的一个应用程序中保留-SNAPSHOT
这个词。然后我只需要发布“core”到Nexus。
--- 更新 ---
我了解到以下命令将增加“core”中的版本号。它似乎过于复杂,因为您仍然需要在CLI提示时键入完整版本值(我键入了“1.0.5-SNAPSHOT”)。
mvn versions:set nestSnapshot
我猜这是更新应用程序以使用最新依赖项版本的方法,但我认为只有在成功发布依赖项后才能工作。
mvn versions:use-latest-releases -Dincludes=com.company.team:foo-core -DallowSnapshots=true
英文:
I'm trying to figure out the best practice for updating the version in a POM file that is used by several other Java projects. I'm new to Java and Maven, but not OOP and semver.
I took over a few git repos with Java code using a maven build system. I need to add new features to a "core" repo that is used by several other repos, even though I only need one of the repos to benefit from the new features. My hope is to leave the other repos untouched. If the other repos get redeployed by some devops process, I want them to use the version of "core" without any changes I added to "core".
I think I should update the version in the POM file of the "core" repo before storing its artifact in Nexus so the other repos won't download the version of "core" containing my changes. What mvn
command should I use?
Right now, the "core" library declares its version like:
<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>
The projects that use "core" have a POM that looks like:
<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>
I'm not sure when <parent>
is a useful tag, but I notice it is not being used to connect the application repos to the "core" repo.
I imagine I want to update the POM
- for the core
- and for the one project that uses the core, but not the other projects that also use the core.
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
答案1
得分: 1
你可以直接进入你提到的两个POM文件,然后在文件中修改版本号。
我会首先修改核心部分的版本,然后运行构建命令 mvn clean install
(如果这是在你的本地机器上进行的)或者 mvn clean deploy
(如果你想将其发送到公司的仓库),然后再在另一个项目中修改核心部分的版本号。
请注意,SNAPSHOT版本是用于开发的。当你想要发布某个版本时,请通过Maven发布插件创建一个发布版本。
英文:
You can just go to the two POM files you mentioned and change the version number in the file.
I would first change the version of the core, then run a build mvn clean install
(if this done on your local machine) or mvn clean deploy
(if you want to sent it to your company repository) and then change the version number of core in the other project.
Note that SNAPSHOT versions are for development. When you want to release something, create a release version, e.g. through the Maven release plugin.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论