You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by sj...@apache.org on 2026/04/28 21:51:19 UTC

(maven-artifact-plugin) branch master updated: Detect version range usage in project or transitive dependencies (#206)

This is an automated email from the ASF dual-hosted git repository.

slawekjaranowski pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-artifact-plugin.git


The following commit(s) were added to refs/heads/master by this push:
     new d88c013  Detect version range usage in project or transitive dependencies (#206)
d88c013 is described below

commit d88c0132b0b537380e55cd4a7ad6b39b45dae28e
Author: Slawomir Jaranowski <s....@gmail.com>
AuthorDate: Tue Apr 28 23:51:14 2026 +0200

    Detect version range usage in project or transitive dependencies (#206)
---
 src/it/buildinfo-mono/pom.xml                      |   8 ++
 src/it/buildinfo-mono/verify.groovy                |   1 +
 .../invoker.properties                             |  19 +++
 .../pom.xml                                        |  68 ++++------
 .../invoker.properties                             |  19 +++
 .../pom.xml                                        |  74 ++++-------
 .../verify.groovy                                  |  27 ++++
 .../invoker.properties                             |  18 +++
 .../pom.xml                                        |  76 +++++------
 .../verify.groovy                                  |  26 ++++
 src/it/compare-mono/pom.xml                        |   8 ++
 src/it/compare-mono/verify.groovy                  |   9 ++
 .../artifact/buildinfo/AbstractBuildinfoMojo.java  |  50 +++++--
 .../artifact/buildinfo/BuildInfoWriter.java        |   7 +-
 .../plugins/artifact/buildinfo/BuildinfoMojo.java  |   3 +-
 .../artifact/buildinfo/CheckBuildPlanMojo.java     |  28 +++-
 .../plugins/artifact/buildinfo/CompareMojo.java    |   3 +-
 .../buildinfo/DescribeBuildOutputMojo.java         |   3 +-
 .../plugins/artifact/buildinfo/RangesUtil.java     | 146 +++++++++++++++++++++
 19 files changed, 442 insertions(+), 151 deletions(-)

diff --git a/src/it/buildinfo-mono/pom.xml b/src/it/buildinfo-mono/pom.xml
index 18d2786..effb628 100644
--- a/src/it/buildinfo-mono/pom.xml
+++ b/src/it/buildinfo-mono/pom.xml
@@ -53,6 +53,14 @@
     <project.build.outputTimestamp>2019-12-03T10:04:00Z</project.build.outputTimestamp>
   </properties>
 
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>(1.7.30,1.7.36]</version>
+    </dependency>
+  </dependencies>
+
   <build>
     <plugins>
       <plugin>
diff --git a/src/it/buildinfo-mono/verify.groovy b/src/it/buildinfo-mono/verify.groovy
index f1e35a1..a2903ff 100644
--- a/src/it/buildinfo-mono/verify.groovy
+++ b/src/it/buildinfo-mono/verify.groovy
@@ -28,6 +28,7 @@ String buildinfo = buildinfoFile.text
 assert buildinfo.contains( "outputs.0.filename=mono-1.0-SNAPSHOT.pom" )
 assert buildinfo.contains( "outputs.1.filename=mono-1.0-SNAPSHOT.jar" )
 assert buildinfo.contains( "mvn.minimum.version=3.0.5" )
+assert buildinfo.contains( "mvn.rebuild-args=-Dmaven.session.versionFilter=e(org.slf4j:slf4j-api:(1.7.36,))" )
 
 // check existence of buildinfo in local repository
 File local = new File( basedir, "../../local-repo/org/apache/maven/plugins/it/mono/1.0-SNAPSHOT/mono-1.0-SNAPSHOT.buildinfo")
diff --git a/src/it/check-buildplan-range-no-fail-depMan/invoker.properties b/src/it/check-buildplan-range-no-fail-depMan/invoker.properties
new file mode 100644
index 0000000..1479d5e
--- /dev/null
+++ b/src/it/check-buildplan-range-no-fail-depMan/invoker.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals=artifact:check-buildplan
+
diff --git a/src/it/compare-mono/pom.xml b/src/it/check-buildplan-range-no-fail-depMan/pom.xml
similarity index 52%
copy from src/it/compare-mono/pom.xml
copy to src/it/check-buildplan-range-no-fail-depMan/pom.xml
index 750703e..3d8142e 100644
--- a/src/it/compare-mono/pom.xml
+++ b/src/it/check-buildplan-range-no-fail-depMan/pom.xml
@@ -20,49 +20,39 @@
 <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.apache.maven</groupId>
-    <artifactId>maven-parent</artifactId>
-    <version>39</version>
-  </parent>
-
   <groupId>org.apache.maven.plugins.it.compare</groupId>
-  <artifactId>mono</artifactId>
+  <artifactId>compare-version-range-no-fail-depMan</artifactId>
   <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
 
-  <description>A simple IT verifying the basic use case of artifact:compare for mono-module build.</description>
-
-  <prerequisites>
-    <maven>3.0.5</maven>
-  </prerequisites>
-
-  <scm>
-    <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</connection>
-    <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</developerConnection>
-    <tag>maven-buildinfo-plugin</tag>
-    <url>https://github.com/apache/maven-studies/tree/${project.scm.tag}</url>
-  </scm>
-
-  <distributionManagement>
-    <snapshotRepository>
-      <uniqueVersion>false</uniqueVersion>
-      <id>local-snapshots</id>
-      <url>file://${basedir}/target/remote-repo</url>
-    </snapshotRepository>
-  </distributionManagement>
+  <description>A simple IT verifying dependencies with range in version</description>
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
+  <dependencyManagement>
+    <dependencies>
+      <!-- Overwrite the version to avoid range selection -->
+      <dependency>
+        <groupId>io.cucumber</groupId>
+        <artifactId>messages</artifactId>
+        <version>32.1.0</version>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+  <dependencies>
+    <dependency>
+      <!-- Contains transitive dependencies with version ranges -->
+      <groupId>io.cucumber</groupId>
+      <artifactId>gherkin</artifactId>
+      <version>38.0.0</version>
+    </dependency>
+  </dependencies>
+
   <build>
     <pluginManagement>
       <plugins>
-        <plugin>
-          <artifactId>maven-jar-plugin</artifactId>
-          <!-- intentionally non-reproducible -->
-          <version>2.4</version>
-        </plugin>
         <plugin>
           <groupId>@project.groupId@</groupId>
           <artifactId>@project.artifactId@</artifactId>
@@ -70,19 +60,5 @@
         </plugin>
       </plugins>
     </pluginManagement>
-    <plugins>
-      <plugin>
-        <groupId>org.spdx</groupId>
-        <artifactId>spdx-maven-plugin</artifactId>
-        <version>0.6.3</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>createSPDX</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
   </build>
 </project>
diff --git a/src/it/check-buildplan-version-range-fail/invoker.properties b/src/it/check-buildplan-version-range-fail/invoker.properties
new file mode 100644
index 0000000..077d077
--- /dev/null
+++ b/src/it/check-buildplan-version-range-fail/invoker.properties
@@ -0,0 +1,19 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals=artifact:check-buildplan
+invoker.buildResult=failure
diff --git a/src/it/compare-mono/pom.xml b/src/it/check-buildplan-version-range-fail/pom.xml
similarity index 52%
copy from src/it/compare-mono/pom.xml
copy to src/it/check-buildplan-version-range-fail/pom.xml
index 750703e..3d10d93 100644
--- a/src/it/compare-mono/pom.xml
+++ b/src/it/check-buildplan-version-range-fail/pom.xml
@@ -20,49 +20,45 @@
 <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.apache.maven</groupId>
-    <artifactId>maven-parent</artifactId>
-    <version>39</version>
-  </parent>
-
   <groupId>org.apache.maven.plugins.it.compare</groupId>
-  <artifactId>mono</artifactId>
+  <artifactId>compare-version-range-fail</artifactId>
   <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
 
-  <description>A simple IT verifying the basic use case of artifact:compare for mono-module build.</description>
-
-  <prerequisites>
-    <maven>3.0.5</maven>
-  </prerequisites>
-
-  <scm>
-    <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</connection>
-    <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</developerConnection>
-    <tag>maven-buildinfo-plugin</tag>
-    <url>https://github.com/apache/maven-studies/tree/${project.scm.tag}</url>
-  </scm>
-
-  <distributionManagement>
-    <snapshotRepository>
-      <uniqueVersion>false</uniqueVersion>
-      <id>local-snapshots</id>
-      <url>file://${basedir}/target/remote-repo</url>
-    </snapshotRepository>
-  </distributionManagement>
+  <description>A simple IT verifying dependencies with range in version</description>
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+    <project.build.outputTimestamp>0</project.build.outputTimestamp>
   </properties>
 
+  <dependencies>
+    <dependency>
+      <!-- Contains transitive dependencies with version ranges -->
+      <groupId>io.cucumber</groupId>
+      <artifactId>gherkin</artifactId>
+      <version>38.0.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>[3.20.0]</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>[2.20.0,)</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>LATEST</version>
+    </dependency>
+  </dependencies>
+
   <build>
     <pluginManagement>
       <plugins>
-        <plugin>
-          <artifactId>maven-jar-plugin</artifactId>
-          <!-- intentionally non-reproducible -->
-          <version>2.4</version>
-        </plugin>
         <plugin>
           <groupId>@project.groupId@</groupId>
           <artifactId>@project.artifactId@</artifactId>
@@ -70,19 +66,5 @@
         </plugin>
       </plugins>
     </pluginManagement>
-    <plugins>
-      <plugin>
-        <groupId>org.spdx</groupId>
-        <artifactId>spdx-maven-plugin</artifactId>
-        <version>0.6.3</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>createSPDX</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
   </build>
 </project>
diff --git a/src/it/check-buildplan-version-range-fail/verify.groovy b/src/it/check-buildplan-version-range-fail/verify.groovy
new file mode 100644
index 0000000..e4cc1bd
--- /dev/null
+++ b/src/it/check-buildplan-version-range-fail/verify.groovy
@@ -0,0 +1,27 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+def buildLog = new File(basedir, 'build.log').text
+
+assert buildLog.contains('[ERROR] Version specification with a range found in dependencies may make the project build non-reproducible')
+assert buildLog.contains(' - Dependency io.cucumber:messages:jar:32.2.0 (compile) via io.cucumber:gherkin:jar:38.0.0 has been resolved from a version range [32.0.0,33.0.0)')
+assert buildLog.contains(' - Dependency commons-io:commons-io:jar:2.21.0 (compile) has been resolved from a version range [2.20.0,)')
+assert buildLog.contains(' - Dependency commons-collections:commons-collections:jar:LATEST (compile) has been resolved from a version range LATEST')
+assert !buildLog.contains(' - Dependency org.apache.commons:commons-lang3')
\ No newline at end of file
diff --git a/src/it/check-buildplan-version-range-no-fail/invoker.properties b/src/it/check-buildplan-version-range-no-fail/invoker.properties
new file mode 100644
index 0000000..f2191ac
--- /dev/null
+++ b/src/it/check-buildplan-version-range-no-fail/invoker.properties
@@ -0,0 +1,18 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+invoker.goals=artifact:check-buildplan
diff --git a/src/it/compare-mono/pom.xml b/src/it/check-buildplan-version-range-no-fail/pom.xml
similarity index 52%
copy from src/it/compare-mono/pom.xml
copy to src/it/check-buildplan-version-range-no-fail/pom.xml
index 750703e..5d91dd1 100644
--- a/src/it/compare-mono/pom.xml
+++ b/src/it/check-buildplan-version-range-no-fail/pom.xml
@@ -20,69 +20,53 @@
 <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.apache.maven</groupId>
-    <artifactId>maven-parent</artifactId>
-    <version>39</version>
-  </parent>
-
   <groupId>org.apache.maven.plugins.it.compare</groupId>
-  <artifactId>mono</artifactId>
+  <artifactId>compare-version-range-no-fail</artifactId>
   <version>1.0-SNAPSHOT</version>
+  <packaging>pom</packaging>
 
-  <description>A simple IT verifying the basic use case of artifact:compare for mono-module build.</description>
-
-  <prerequisites>
-    <maven>3.0.5</maven>
-  </prerequisites>
-
-  <scm>
-    <connection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</connection>
-    <developerConnection>scm:git:https://gitbox.apache.org/repos/asf/maven-studies.git</developerConnection>
-    <tag>maven-buildinfo-plugin</tag>
-    <url>https://github.com/apache/maven-studies/tree/${project.scm.tag}</url>
-  </scm>
-
-  <distributionManagement>
-    <snapshotRepository>
-      <uniqueVersion>false</uniqueVersion>
-      <id>local-snapshots</id>
-      <url>file://${basedir}/target/remote-repo</url>
-    </snapshotRepository>
-  </distributionManagement>
+  <description>A simple IT verifying dependencies with range in version</description>
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
+  <dependencies>
+    <dependency>
+      <!-- Contains transitive dependencies with version ranges -->
+      <groupId>io.cucumber</groupId>
+      <artifactId>gherkin</artifactId>
+      <version>38.0.0</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.commons</groupId>
+      <artifactId>commons-lang3</artifactId>
+      <version>[3.20.0]</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <version>[2.20.0,)</version>
+    </dependency>
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>LATEST</version>
+    </dependency>
+  </dependencies>
+
   <build>
     <pluginManagement>
       <plugins>
-        <plugin>
-          <artifactId>maven-jar-plugin</artifactId>
-          <!-- intentionally non-reproducible -->
-          <version>2.4</version>
-        </plugin>
         <plugin>
           <groupId>@project.groupId@</groupId>
           <artifactId>@project.artifactId@</artifactId>
           <version>@project.version@</version>
+          <configuration>
+            <failOnNonReproducible>false</failOnNonReproducible>
+          </configuration>
         </plugin>
       </plugins>
     </pluginManagement>
-    <plugins>
-      <plugin>
-        <groupId>org.spdx</groupId>
-        <artifactId>spdx-maven-plugin</artifactId>
-        <version>0.6.3</version>
-        <executions>
-          <execution>
-            <goals>
-              <goal>createSPDX</goal>
-            </goals>
-          </execution>
-        </executions>
-      </plugin>
-    </plugins>
   </build>
 </project>
diff --git a/src/it/check-buildplan-version-range-no-fail/verify.groovy b/src/it/check-buildplan-version-range-no-fail/verify.groovy
new file mode 100644
index 0000000..b697f68
--- /dev/null
+++ b/src/it/check-buildplan-version-range-no-fail/verify.groovy
@@ -0,0 +1,26 @@
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+def buildLog = new File(basedir, 'build.log').text
+
+assert buildLog.contains('[WARNING] Version specification with a range found in dependencies may make the project build non-reproducible')
+assert buildLog.contains(' - Dependency io.cucumber:messages:jar:32.2.0 (compile) via io.cucumber:gherkin:jar:38.0.0 has been resolved from a version range [32.0.0,33.0.0)')
+assert buildLog.contains(' - Dependency commons-io:commons-io:jar:2.21.0 (compile) has been resolved from a version range [2.20.0,)')
+assert buildLog.contains(' - Dependency commons-collections:commons-collections:jar:LATEST (compile) has been resolved from a version range LATEST')
diff --git a/src/it/compare-mono/pom.xml b/src/it/compare-mono/pom.xml
index 750703e..7d86283 100644
--- a/src/it/compare-mono/pom.xml
+++ b/src/it/compare-mono/pom.xml
@@ -55,6 +55,14 @@
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
   </properties>
 
+  <dependencies>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-api</artifactId>
+      <version>(1.7.30,1.7.36]</version>
+    </dependency>
+  </dependencies>
+
   <build>
     <pluginManagement>
       <plugins>
diff --git a/src/it/compare-mono/verify.groovy b/src/it/compare-mono/verify.groovy
index 4fd75f0..71523fe 100644
--- a/src/it/compare-mono/verify.groovy
+++ b/src/it/compare-mono/verify.groovy
@@ -37,3 +37,12 @@ if( File.separator == '/' ) {
 } else {
   assert compare.contains( '# diffoscope target\\reference\\org.apache.maven.plugins.it.compare\\mono-1.0-SNAPSHOT.jar target\\mono-1.0-SNAPSHOT.jar' )
 }
+
+// check existence of generated buildinfo in target
+File buildinfoFile = new File( basedir, "target/mono-1.0-SNAPSHOT.buildinfo" );
+assert buildinfoFile.isFile()
+
+// check generated buildinfo content
+String buildinfo = buildinfoFile.text
+
+assert buildinfo.contains( "mvn.rebuild-args=-Dmaven.session.versionFilter=e(org.slf4j:slf4j-api:(1.7.36,))" )
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java
index 3ea16e5..a34f0a9 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/AbstractBuildinfoMojo.java
@@ -34,8 +34,12 @@ import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
 import java.time.Instant;
 import java.time.format.DateTimeFormatter;
+import java.util.Collections;
+import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
 import java.util.stream.Collectors;
 
 import org.apache.maven.archiver.MavenArchiver;
@@ -49,6 +53,8 @@ import org.apache.maven.rtinfo.RuntimeInformation;
 import org.apache.maven.toolchain.Toolchain;
 import org.apache.maven.toolchain.ToolchainManager;
 import org.eclipse.aether.artifact.Artifact;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyNode;
 
 /**
  * Base buildinfo-generating class, for goals related to Reproducible Builds {@code .buildinfo} files.
@@ -90,6 +96,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
      * Avoid taking fingerprints for full modules, specified as glob matching against
      * <code>${groupId}/${artifactId}</code>.
      * For ignoring only a few files instead of full modules, see {@code ignore}.
+     *
      * @since 3.5.0
      */
     @Parameter(property = "buildinfo.skipModules")
@@ -131,6 +138,8 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
 
     protected final RuntimeInformation rtInformation;
 
+    private final RangesUtil rangesUtil;
+
     /**
      * The Maven project.
      */
@@ -144,12 +153,14 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
     protected AbstractBuildinfoMojo(
             ToolchainManager toolchainManager,
             RuntimeInformation rtInformation,
+            RangesUtil rangesUtil,
             MavenProject project,
             MavenSession session) {
         this.toolchainManager = toolchainManager;
         this.rtInformation = rtInformation;
         this.project = project;
         this.session = session;
+        this.rangesUtil = rangesUtil;
     }
 
     @Override
@@ -338,6 +349,7 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
 
         return bi;
     }
+
     /**
      * Generate buildinfo file.
      *
@@ -351,20 +363,17 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
 
         buildinfoFile.getParentFile().mkdirs();
 
+        List<MavenProject> mavenProjects = getProjectListForBuildInfo(mono);
+        String rangeFilter = getVersionRangeDependenciesFilters(mavenProjects);
+
         try (PrintWriter p = new PrintWriter(new BufferedWriter(
                 new OutputStreamWriter(Files.newOutputStream(buildinfoFile.toPath()), StandardCharsets.UTF_8)))) {
             BuildInfoWriter bi = newBuildInfoWriter(p, mono);
-            bi.printHeader(root, mono ? null : project, reproducible);
+            bi.printHeader(root, mono ? null : project, rangeFilter, reproducible);
 
             // artifact(s) fingerprints
-            if (mono) {
+            for (MavenProject project : mavenProjects) {
                 bi.printArtifacts(project);
-            } else {
-                for (MavenProject project : session.getProjects()) {
-                    if (!isSkip(project)) {
-                        bi.printArtifacts(project);
-                    }
-                }
             }
 
             if (p.checkError()) {
@@ -377,6 +386,31 @@ public abstract class AbstractBuildinfoMojo extends AbstractMojo {
         }
     }
 
+    private List<MavenProject> getProjectListForBuildInfo(boolean mono) {
+        if (mono) {
+            return Collections.singletonList(project);
+        } else {
+            return session.getProjects().stream().filter(p -> !isSkip(p)).collect(Collectors.toList());
+        }
+    }
+
+    private String getVersionRangeDependenciesFilters(List<MavenProject> mavenProjects) throws MojoExecutionException {
+
+        Set<DependencyNode> dependencyNodeSet = new LinkedHashSet<>();
+        for (MavenProject project : mavenProjects) {
+            dependencyNodeSet.addAll(
+                    rangesUtil.findVersionRangeDependencies(session, project).keySet());
+        }
+
+        return dependencyNodeSet.stream()
+                .map(DependencyNode::getDependency)
+                .filter(Objects::nonNull)
+                .map(Dependency::getArtifact)
+                .filter(Objects::nonNull)
+                .map(a -> String.format("e(%s:%s:(%s,))", a.getGroupId(), a.getArtifactId(), a.getVersion()))
+                .collect(Collectors.joining(";"));
+    }
+
     protected MavenProject getLastProject() {
         int i = session.getProjects().size();
         while (i > 0) {
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
index f603a78..11e5989 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildInfoWriter.java
@@ -67,7 +67,7 @@ class BuildInfoWriter {
         this.rtInformation = rtInformation;
     }
 
-    void printHeader(MavenProject project, MavenProject aggregate, boolean reproducible) {
+    void printHeader(MavenProject project, MavenProject aggregate, String rangeFilter, boolean reproducible) {
         p.println("# https://reproducible-builds.org/docs/jvm/");
         p.println("buildinfo.version=1.0-SNAPSHOT");
         p.println();
@@ -106,6 +106,11 @@ class BuildInfoWriter {
             // TODO wrong algorithm, should reuse algorithm written in versions-maven-plugin
             p.println("mvn.minimum.version=" + project.getPrerequisites().getMaven());
         }
+
+        if (!rangeFilter.isEmpty()) {
+            p.println("mvn.rebuild-args=-Dmaven.session.versionFilter=" + rangeFilter);
+        }
+
         if (toolchain != null) {
             String javaVersion = JdkToolchainUtil.getJavaVersion(toolchain);
             if (reproducible) {
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java
index 8ceb512..acf4f68 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/BuildinfoMojo.java
@@ -55,10 +55,11 @@ public class BuildinfoMojo extends AbstractBuildinfoMojo {
     public BuildinfoMojo(
             ToolchainManager toolchainManager,
             RuntimeInformation runtimeInformation,
+            RangesUtil rangesUtil,
             MavenProject project,
             MavenSession session,
             MavenProjectHelper projectHelper) {
-        super(toolchainManager, runtimeInformation, project, session);
+        super(toolchainManager, runtimeInformation, rangesUtil, project, session);
         this.projectHelper = projectHelper;
     }
 
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java
index fc7eca7..e8f8401 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CheckBuildPlanMojo.java
@@ -28,6 +28,7 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
+import java.util.stream.Collectors;
 
 import org.apache.maven.execution.MavenSession;
 import org.apache.maven.lifecycle.LifecycleExecutor;
@@ -39,6 +40,7 @@ import org.apache.maven.plugin.MojoExecutionException;
 import org.apache.maven.plugins.annotations.Mojo;
 import org.apache.maven.plugins.annotations.Parameter;
 import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.graph.DependencyNode;
 import org.eclipse.aether.util.version.GenericVersionScheme;
 import org.eclipse.aether.version.InvalidVersionSpecificationException;
 import org.eclipse.aether.version.Version;
@@ -91,11 +93,15 @@ public class CheckBuildPlanMojo extends AbstractMojo {
 
     private final VersionScheme versionScheme = new GenericVersionScheme();
 
+    private final RangesUtil rangesUtil;
+
     @Inject
-    public CheckBuildPlanMojo(MavenProject project, MavenSession session, LifecycleExecutor lifecycleExecutor) {
+    public CheckBuildPlanMojo(
+            MavenProject project, MavenSession session, LifecycleExecutor lifecycleExecutor, RangesUtil rangesUtil) {
         this.project = project;
         this.session = session;
         this.lifecycleExecutor = lifecycleExecutor;
+        this.rangesUtil = rangesUtil;
     }
 
     protected MavenExecutionPlan calculateExecutionPlan() throws MojoExecutionException {
@@ -164,6 +170,8 @@ public class CheckBuildPlanMojo extends AbstractMojo {
             getLog().info("No known issue in " + okCount + " plugins");
         }
 
+        fail = checkVersionRangeInDependencies();
+
         if (fail) {
             getLog().info("current module pom.xml is " + project.getBasedir() + "/pom.xml");
             MavenProject parent = project;
@@ -183,6 +191,24 @@ public class CheckBuildPlanMojo extends AbstractMojo {
         }
     }
 
+    private boolean checkVersionRangeInDependencies() throws MojoExecutionException {
+        Map<DependencyNode, String> versionRangeDependencies =
+                rangesUtil.findVersionRangeDependencies(session, project);
+        if (!versionRangeDependencies.isEmpty()) {
+            String message =
+                    "Version specification with a range found in dependencies may make the project build non-reproducible"
+                            + versionRangeDependencies.values().stream()
+                                    .collect(Collectors.joining(
+                                            System.lineSeparator() + " - ", System.lineSeparator() + " - ", ""));
+            if (failOnNonReproducible) {
+                getLog().error(message);
+            } else {
+                getLog().warn(message);
+            }
+        }
+        return !versionRangeDependencies.isEmpty();
+    }
+
     private Properties loadIssues() throws MojoExecutionException {
         try (InputStream in = (pluginIssues == null)
                 ? getClass().getResourceAsStream("not-reproducible-plugins.properties")
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
index b4ed00c..9c5ca01 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/CompareMojo.java
@@ -107,10 +107,11 @@ public class CompareMojo extends AbstractBuildinfoMojo {
     public CompareMojo(
             ToolchainManager toolchainManager,
             RuntimeInformation rtInformation,
+            RangesUtil rangesUtil,
             MavenProject project,
             MavenSession session,
             RepositorySystem repoSystem) {
-        super(toolchainManager, rtInformation, project, session);
+        super(toolchainManager, rtInformation, rangesUtil, project, session);
         this.repoSystem = repoSystem;
     }
 
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java
index cbb9b91..9f3329e 100644
--- a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/DescribeBuildOutputMojo.java
@@ -60,9 +60,10 @@ public class DescribeBuildOutputMojo extends AbstractBuildinfoMojo {
     public DescribeBuildOutputMojo(
             ToolchainManager toolchainManager,
             RuntimeInformation rtInformation,
+            RangesUtil rangesUtil,
             MavenProject project,
             MavenSession session) {
-        super(toolchainManager, rtInformation, project, session);
+        super(toolchainManager, rtInformation, rangesUtil, project, session);
     }
 
     @Override
diff --git a/src/main/java/org/apache/maven/plugins/artifact/buildinfo/RangesUtil.java b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/RangesUtil.java
new file mode 100644
index 0000000..614cd86
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/artifact/buildinfo/RangesUtil.java
@@ -0,0 +1,146 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.plugins.artifact.buildinfo;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.stream.Collectors;
+
+import org.apache.maven.RepositoryUtils;
+import org.apache.maven.execution.MavenSession;
+import org.apache.maven.model.DependencyManagement;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
+import org.eclipse.aether.RepositorySystem;
+import org.eclipse.aether.artifact.ArtifactTypeRegistry;
+import org.eclipse.aether.collection.CollectRequest;
+import org.eclipse.aether.collection.DependencyCollectionException;
+import org.eclipse.aether.graph.Dependency;
+import org.eclipse.aether.graph.DependencyNode;
+import org.eclipse.aether.util.graph.visitor.PathRecordingDependencyVisitor;
+import org.eclipse.aether.version.VersionConstraint;
+
+import static java.util.Optional.ofNullable;
+
+/**
+ * Utility class to find dependencies with version ranges in the project.
+ */
+@Named
+public class RangesUtil {
+
+    private final RepositorySystem repoSystem;
+
+    @Inject
+    RangesUtil(RepositorySystem repoSystem) {
+        this.repoSystem = repoSystem;
+    }
+
+    /**
+     * Finds all dependencies with version ranges in the project.
+     *
+     * @param session the Maven session
+     * @param project the Maven project to analyze
+     * @return a map of dependency nodes with version ranges to their issue descriptions
+     * @throws MojoExecutionException if dependency collection fails
+     */
+    public Map<DependencyNode, String> findVersionRangeDependencies(MavenSession session, MavenProject project)
+            throws MojoExecutionException {
+        DependencyNode rootNode = collectDependencies(session, project);
+        return collectVersionRangeDependencies(rootNode);
+    }
+
+    private DependencyNode collectDependencies(MavenSession session, MavenProject project)
+            throws MojoExecutionException {
+        ArtifactTypeRegistry artifactTypeRegistry =
+                session.getRepositorySession().getArtifactTypeRegistry();
+
+        List<Dependency> dependencies = project.getDependencies().stream()
+                .map(d -> RepositoryUtils.toDependency(d, artifactTypeRegistry))
+                .collect(Collectors.toList());
+
+        List<Dependency> managedDependencies = ofNullable(project.getDependencyManagement())
+                .map(DependencyManagement::getDependencies)
+                .map(list -> list.stream()
+                        .map(d -> RepositoryUtils.toDependency(d, artifactTypeRegistry))
+                        .collect(Collectors.toList()))
+                .orElse(null);
+
+        CollectRequest collectRequest =
+                new CollectRequest(dependencies, managedDependencies, project.getRemoteProjectRepositories());
+        collectRequest.setRootArtifact(RepositoryUtils.toArtifact(project.getArtifact()));
+
+        try {
+            return repoSystem
+                    .collectDependencies(session.getRepositorySession(), collectRequest)
+                    .getRoot();
+        } catch (DependencyCollectionException e) {
+            throw new MojoExecutionException("Cannot build dependency tree: " + e.getMessage(), e);
+        }
+    }
+
+    private Map<DependencyNode, String> collectVersionRangeDependencies(DependencyNode rootNode) {
+        Map<DependencyNode, String> result = new LinkedHashMap<>();
+
+        rootNode.accept(new PathRecordingDependencyVisitor((node, parents) -> {
+            VersionConstraint versionConstraint = node.getVersionConstraint();
+            if (isVersionRange(versionConstraint)) {
+                String path = "";
+                if (parents.size() > 1) {
+                    path = " via "
+                            + parents.stream()
+                                    .limit(parents.size() - 1)
+                                    .map(n -> n.getDependency().getArtifact().toString())
+                                    .collect(Collectors.joining(" --> "));
+                }
+                result.put(
+                        node,
+                        "Dependency " + node.getDependency() + path + " has been resolved from a version range "
+                                + versionConstraint);
+            }
+
+            // track all dependencies
+            return false;
+        }));
+
+        return result;
+    }
+
+    private boolean isVersionRange(VersionConstraint versionConstraint) {
+        if (versionConstraint == null) {
+            return false;
+        }
+
+        if (versionConstraint.getVersion() != null) {
+            String version = versionConstraint.getVersion().toString();
+            return version.equals("LATEST") || version.equals("RELEASE");
+        }
+
+        if (versionConstraint.getRange() != null) {
+            return !Objects.equals(
+                    versionConstraint.getRange().getLowerBound(),
+                    versionConstraint.getRange().getUpperBound());
+        }
+        return false;
+    }
+}