RussellSpitzer commented on code in PR #15857:
URL: https://github.com/apache/iceberg/pull/15857#discussion_r3024649004


##########
build.gradle:
##########
@@ -128,6 +138,147 @@ subprojects {
 
   apply plugin: 'java-library'
 
+  // Helper closure to truncate version to major.minor
+  ext.truncateVersion = { String version ->
+    if (version == null || version.isEmpty()) {
+      return version
+    }
+
+    // Remove any build metadata or qualifiers first (e.g., +something, 
-SNAPSHOT)
+    def cleanVersion = version.replaceAll(/[+-].*$/, '')
+
+    // Split by dots and take first two parts
+    def parts = cleanVersion.split(/\./)
+    if (parts.length >= 2) {
+      return "${parts[0]}.${parts[1]}"
+    } else if (parts.length == 1) {
+      return parts[0]
+    }
+
+    return version
+  }
+
+  // Helper closure to resolve dependencies for a configuration
+  ext.resolveDependencies = { String configuration ->
+    def dependencies = new TreeSet<String>()
+
+    try {
+      def config = configurations.findByName(configuration)
+      if (config != null && config.canBeResolved) {
+        config.resolvedConfiguration.resolvedArtifacts.each { artifact ->
+          def id = artifact.moduleVersion.id
+          def groupId = id.group
+          def artifactId = id.name
+          def version = id.version
+
+          // Truncate version to major.minor (remove patch and beyond)
+          def truncatedVersion = truncateVersion(version)
+
+          
dependencies.add("${groupId}:${artifactId}:${truncatedVersion}".toString())
+        }
+      } else {
+        throw new GradleException("Configuration '${configuration}' not found 
or cannot be resolved")
+      }
+    } catch (Exception e) {
+      throw new GradleException("Could not resolve ${configuration}: 
${e.message}", e)
+    }
+
+    return dependencies
+  }
+
+  // Task to generate a dependency list for this module
+  // Usage: ./gradlew :iceberg-core:generateDependencyList
+  // Usage with custom config: ./gradlew :iceberg-core:generateDependencyList 
-Pconfiguration=compileClasspath
+  // Generates a file at <module-root>/dependencies-<configuration>.txt
+  tasks.register('generateDependencyList') {
+    description = "Generates a sorted dependency list for ${project.name} with 
truncated versions"
+    group = 'build'
+
+    doLast {
+      def configuration = (project.findProperty('configuration') ?: 
'runtimeClasspath').toString()
+      def outputFile = file("${projectDir}/dependencies-${configuration}.txt")
+
+      def dependencies = resolveDependencies(configuration)
+
+      // Write to output file
+      outputFile.text = dependencies.join('\n') + '\n'
+
+      project.logger.lifecycle("Generated dependency list with 
${dependencies.size()} dependencies at: ${outputFile}")
+    }
+  }
+
+  // Task to validate the dependency list matches the actual dependencies
+  // Usage: ./gradlew :iceberg-core:checkDependencyList
+  // Usage with custom config: ./gradlew :iceberg-core:checkDependencyList 
-Pconfiguration=compileClasspath
+  // Fails if dependencies-<configuration>.txt exists but doesn't match actual 
dependencies
+  tasks.register('checkDependencyList') {

Review Comment:
   Do we want to run this for every config? Just wondering if we care about 
changes in dependencies for jars we aren't shipping



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to