[英]How can i ensure all my java projects in a git repository have latest or desired version of maven dependency?
I have a git repository that houses a large number of java projects. 我有一个包含大量java项目的git存储库。 Some of these are utility libraries and used as maven dependency in other projects and some of them are applications.
其中一些是实用程序库,在其他项目中用作maven依赖项,其中一些是应用程序。
Over the period of time, a lot many versions have been released and not all projects have been upgraded to use the latest dependency, which is creating operational problems now. 在一段时间内,已经发布了许多版本,并且并非所有项目都已升级为使用最新的依赖项,这现在正在创建操作问题。 So, how can I find out which project is using an old version of a maven dependency, provided I have the master data, which tells me the right version for a library?
那么,如果我有主数据,我怎么能找出哪个项目正在使用旧版本的maven依赖项,它告诉我库的正确版本?
I came across a Java library, JGit. 我遇到了一个Java库,JGit。 I have not looked much into it, but I was thinking, may be I will be able to pull out the pom.xml of the master branches and run checks against it.
我没有太多关注它,但我在想,也许我将能够拔出主分支的pom.xml并对其进行检查。 Will that be a correct approach?
这是一个正确的方法吗? Is there any other/better way of doing this?
有没有其他/更好的方法这样做?
When you update the dependencies of a project, you need to build and test that project. 更新项目的依赖项时,需要构建并测试该项目。 The updated dependencies might break something.
更新的依赖项可能会破坏某些内容。
Therefore, you cannot consider this a task to be automated unless you have really good unit and integration tests. 因此,除非您有非常好的单元和集成测试,否则您不能认为这是一项自动化任务。 What you can do, though:
但你能做什么呢:
versions:use-latest-releases
to replace all dependencies by the newest ones. versions:use-latest-releases
替换所有依赖项。 It depends whether your "right" version is also the latest available version. 这取决于您的“正确”版本是否也是最新版本。 If yes, then Maven can help you do the task (see versions-maven-plugin ).
如果是,那么Maven可以帮助您完成任务(请参阅versions-maven-plugin )。 You would have to repeat this for every project, however, assuming they share no common parent POM.
但是,假设它们没有共享父POM,则必须为每个项目重复此操作。 If they do, you may also define your dependency management there and remove any explicit versions in your child POMs.
如果他们这样做,您还可以在那里定义依赖关系管理并删除子POM中的任何显式版本。 However, this would mean you are actually using these new versions in you projects, which may not be what you want.
但是,这意味着您实际上在项目中使用这些新版本,这可能不是您想要的。
So, how can I find out which project is using an old version of a maven dependency, provided I have the master data, which tells me the right version for a library?
那么,如果我有主数据,我怎么能找出哪个项目正在使用旧版本的maven依赖项,它告诉我库的正确版本?
To compute dependencies that have newer versions available : 要计算具有更新版本的依赖项:
pom.xml
file and execute the versions:display-dependency-updates-mojo
goal on filtered folders and aggregate all results in a file/some files. pom.xml
文件的文件夹,并对已过滤的文件夹执行versions:display-dependency-updates-mojo
目标,并将所有结果聚合在一个文件/某些文件中。 To update dependencies : 要更新依赖项:
Execute versions:use-latest-versions
for projects that you want to upgrade all or some dependencies. 执行
versions:use-latest-versions
用于要升级所有或某些依赖项的项目。
Some information about these Maven goals : 有关这些Maven目标的一些信息:
versions:display-dependency-updates
: versions:display-dependency-updates
:
Displays all dependencies that have newer versions available.
显示具有较新版本的所有依赖项。 It will also display dependencies which are used by a plugin or defined in the plugin within a pluginManagement.
它还将显示插件使用的插件或插件在插件管理中定义的依赖关系。
versions:use-latest-versions
: versions:use-latest-versions
:
Replaces any version with the latest version.
用最新版本替换任何版本。
These goals have options to filter the dependencies to analyse/update. 这些目标具有筛选依赖关系以进行分析/更新的选项。
I understand your dilemma. 我理解你的困境。 I created a stand-along Maven project that has a POM as follows
我创建了一个具有POM的独立Maven项目,如下所示
<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.etc</groupId>
<artifactId>dependency-management</artifactId>
<version>1.0.0</version>
<name>Maven dependency management</name>
<description>Hold version information for referenced artifacts</description>
<properties>
<spring-boot.version>1.5.3.RELEASE</spring-boot.version>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.10.Final</version>
</dependency>
</dependencies>
... more dependencies
</dependencyManagement>
I then refer that POM in other Maven projects: 然后我在其他Maven项目中引用POM:
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.etc</groupId>
<artifactId>dependency-management</artifactId>
<version>1.0.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fusionalliance.internal.interview</groupId>
<artifactId>shared-springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependency>
</dependencies>
</project>
Note that the version tags are not present in the other projects. 请注意,其他项目中不存在版本标记。 The dependency management POM controls the versions.
依赖关系管理POM控制版本。
You can then update the versions. 然后,您可以更新版本。 (Testing everything thoroughly, of course.)
(当然,彻底测试一切。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.