简体   繁体   English

如何确保git存储库中的所有Java项目都具有最新或所需的maven依赖项版本?

[英]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: 但你能做什么呢:

  • Check out a project. 检查一个项目。
  • Use versions:use-latest-releases to replace all dependencies by the newest ones. 使用versions:use-latest-releases替换所有依赖项。
  • Build and test the project. 构建并测试项目。

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 : 要计算具有更新版本的依赖项:

  • clone the repository 克隆存储库
  • use a script or a program to walk the local repository and filter folders containing at the root a 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.

相关问题 我可以通过本地存储库覆盖Maven依赖版本吗? - Can I overwrite a maven dependency version through my local repository? 如何告诉 Maven 使用最新版本的依赖项? - How do I tell Maven to use the latest version of a dependency? 如何确保Maven使用依赖项之一使用的适当快照版本? - How can I ensure Maven uses the appropriate snapshot version used by one of my dependencies? 如何从远程存储库向我的Java项目添加Maven依赖关系? - How to add a Maven dependency from a remote repository to my Java project? 我如何确保版权声明伴随我所有的 java-maven 构建源文件? - How do I ensure that copyright notices accompany all of my source files for a java-maven build? 如何列出Git存储库的所有文件夹(项目) - How to List all folders (projects) of a Git Repository Maven正在搜索Javax.Mail依赖项的旧版本(1.4.3),尽管我具有最新版本(1.6.1)并抛出ClasNotFoundException - Maven searching for an old version of Javax.Mail dependency (1.4.3) though I have the latest version of it (1.6.1) and throwing ClasNotFoundException 如何将Apache Archiva设置为我所有maven项目的缓存? - How can I setup Apache Archiva as cache fo all my maven projects? 如何让我的子项目从多模块Maven项目中的超级项目继承依赖项版本? - How can I get my sub projects to inherit dependency versions from the super project in a multi module Maven project? 确保 Maven 拉取最新版本 - Ensure Maven pulls latest version of release
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM