mojohaus / versions

Versions Maven Plugin
https://www.mojohaus.org/versions/versions-maven-plugin/
Apache License 2.0
337 stars 267 forks source link

versions:resolve-ranges very slow when parents contain lots of version properties #1121

Closed m-schutte-ohra-nl closed 1 month ago

m-schutte-ohra-nl commented 2 months ago

versions:2.17.1:resolve-ranges

The resolve-ranges goal takes a lot of time processing properties that are used in dependency versions (let's call them version properties) in parent projects . As far as I can tell the only version properties that need to be considered are those occurring in the pom of the current project because those are the only ones that could possibly be updated.

When using a parent with a lot of version properties (eg. spring-boot-dependencies) this leads to execution times of several minutes. This has already been reported for other mojos.

For instance the following pom takes 01:23 min and hits the repository with several hundreds of maven-metadata.xml requests.

<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>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-dependencies</artifactId>
    <version>3.3.2</version>
  </parent>
  <artifactId>it-resolve-ranges-issues-todo</artifactId>
  <packaging>pom</packaging>

  <properties>
    <htmlunit.version>[2.6,3)</htmlunit.version>
  </properties>
</project>

Browsing the history of issues and pull requests I see the introduction of 'includeParents' in several mojos and methods (as a solution to for instance #367) to have caused this.

I don't think introduction of the includeParents parameter to the resolve-ranges mojo is the best solution, because as already stated in #837, setting this to false will sometimes lead to incorrect results. Instead, I am preparing a merge request that restricts the properties to consider to those that exist in the current project.

khmarbaise commented 2 months ago

You should configure the resolution of transitive deps etc. via configuration https://www.mojohaus.org/versions/versions-maven-plugin/resolve-ranges-mojo.html And it might be a good idea to ignore the dependencyManagement depending your use case:

            <configuration>
              <processDependencyManagementTransitive>false</processDependencyManagementTransitive>
            </configuration>
m-schutte-ohra-nl commented 2 months ago

processDependencyManagementTransitive is not a parameter of the resolve-ranges mojo.

Besides that, the time is spent in handling the properties, not in the dependencyManagement. To be exact, it is spent in the 'while (i.hasNext())' loop in DefaultVersionsHelper.getVersionPropertiesMap.