Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

MaxKless
Copy link
Collaborator

@MaxKless MaxKless commented Sep 11, 2025

Current Behavior

gradle dependencies are hardcoded to included builds & subprojects

Expected Behavior

we use project configurations to determine dependencies like the tooling api does

Related Issue(s)

Fixes #

@MaxKless MaxKless requested review from a team, FrozenPandaz, lourw and Coly010 as code owners September 11, 2025 16:23
Copy link

vercel bot commented Sep 11, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Sep 12, 2025 8:39pm

Copy link
Contributor

nx-cloud bot commented Sep 11, 2025

View your CI Pipeline Execution ↗ for commit 44c99d3

Command Status Duration Result
nx run-many -t check-imports check-commit check... ✅ Succeeded 1m 56s View ↗
nx affected --targets=lint,test,build,e2e,e2e-c... ✅ Succeeded 53s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 5s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 5s View ↗
nx documentation ✅ Succeeded 2m 39s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-12 20:36:46 UTC

Comment on lines 5 to 6
import org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult
import org.gradle.internal.component.local.model.DefaultProjectComponentSelector
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dependency on internal Gradle APIs creates brittleness

The code imports and uses internal Gradle implementation classes (DefaultResolvedDependencyResult and DefaultProjectComponentSelector) that aren't part of Gradle's public API contract. These internal classes can change without notice between Gradle versions.

Consider using the public API interfaces instead:

import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.artifacts.component.ProjectComponentSelector

This would make the implementation more robust against Gradle upgrades and follow Gradle's recommended practices for plugin development.

Suggested change
import org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult
import org.gradle.internal.component.local.model.DefaultProjectComponentSelector
import org.gradle.api.artifacts.result.ResolvedDependencyResult
import org.gradle.api.artifacts.component.ProjectComponentSelector

Spotted by Diamond

Fix in Graphite


Is this helpful? React 👍 or 👎 to let us know.

nx-cloud[bot]

This comment was marked as outdated.

Copy link
Contributor

@nx-cloud nx-cloud bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud is proposing a fix for your failed CI:

We have automatically formatted the ProjectDependencyUtils.kt file using ktfmt to fix the linting errors. This includes proper indentation, import organization, and code style consistency to match the project's Kotlin formatting standards.

We verified this fix by re-running gradle-project-graph:lint.

Suggested Fix changes
diff --git a/packages/gradle/project-graph/src/main/kotlin/dev/nx/gradle/utils/ProjectDependencyUtils.kt b/packages/gradle/project-graph/src/main/kotlin/dev/nx/gradle/utils/ProjectDependencyUtils.kt
index 8b2b35f..f001de4 100644
--- a/packages/gradle/project-graph/src/main/kotlin/dev/nx/gradle/utils/ProjectDependencyUtils.kt
+++ b/packages/gradle/project-graph/src/main/kotlin/dev/nx/gradle/utils/ProjectDependencyUtils.kt
@@ -2,60 +2,54 @@ package dev.nx.gradle.utils
 
 import dev.nx.gradle.data.Dependency
 import org.gradle.api.Project
-
-import org.gradle.api.artifacts.result.ResolvedDependencyResult
 import org.gradle.api.artifacts.component.ProjectComponentSelector
-
+import org.gradle.api.artifacts.result.ResolvedDependencyResult
 
 private val dependencyCache = mutableMapOf<Project, Set<Dependency>>()
 
 fun getDependenciesForProject(project: Project): MutableSet<Dependency> {
-    return dependencyCache
-        .getOrPut(project) { buildDependenciesForProject(project) }
-        .toMutableSet() // Return a new mutable copy to prevent modifying the cached set
+  return dependencyCache
+      .getOrPut(project) { buildDependenciesForProject(project) }
+      .toMutableSet() // Return a new mutable copy to prevent modifying the cached set
 }
 
 private fun buildDependenciesForProject(project: Project): Set<Dependency> {
-    val dependencies = mutableSetOf<Dependency>()
-
-    val sourcePath = project.projectDir.absolutePath
-    val sourceFilePath = project.buildFile.takeIf { it.exists() }?.absolutePath ?: ""
-
-    project.configurations
-        .matching { it.isCanBeResolved }
-        .forEach { conf ->
-            try {
-                conf.incoming.resolutionResult.allDependencies.forEach { dependency ->
-                    if (dependency is ResolvedDependencyResult) {
-                        val requested = dependency.requested
-                        if (requested is ProjectComponentSelector) {
-                            val dependentProject =
-                                project.findProject(requested.projectPath)
-
-                            if (
-                                dependentProject != null &&
-                                    dependentProject.projectDir.exists() &&
-                                    dependentProject.buildFile.exists()
-                            ) {
-
-                                val targetPath = dependentProject.projectDir.absolutePath
-
-                                dependencies.add(
-                                    Dependency(
-                                        source = sourcePath,
-                                        target = targetPath,
-                                        sourceFile = sourceFilePath,
-                                    )
-                                )
-                            }
-                        }
-                    }
+  val dependencies = mutableSetOf<Dependency>()
+
+  val sourcePath = project.projectDir.absolutePath
+  val sourceFilePath = project.buildFile.takeIf { it.exists() }?.absolutePath ?: ""
+
+  project.configurations
+      .matching { it.isCanBeResolved }
+      .forEach { conf ->
+        try {
+          conf.incoming.resolutionResult.allDependencies.forEach { dependency ->
+            if (dependency is ResolvedDependencyResult) {
+              val requested = dependency.requested
+              if (requested is ProjectComponentSelector) {
+                val dependentProject = project.findProject(requested.projectPath)
+
+                if (dependentProject != null &&
+                    dependentProject.projectDir.exists() &&
+                    dependentProject.buildFile.exists()) {
+
+                  val targetPath = dependentProject.projectDir.absolutePath
+
+                  dependencies.add(
+                      Dependency(
+                          source = sourcePath,
+                          target = targetPath,
+                          sourceFile = sourceFilePath,
+                      ))
                 }
-            } catch (e: Exception) {
-                // Log the error but don't fail the build
-                project.logger.debug("Error processing configuration ${conf.name}: ${e.message}")
+              }
+            }
+          }
+        } catch (e: Exception) {
+          // Log the error but don't fail the build
+          project.logger.debug("Error processing configuration ${conf.name}: ${e.message}")
         }
+      }
 
-    return dependencies
+  return dependencies
 }

Apply fix via Nx Cloud  Reject fix via Nx Cloud  Nx CloudView interactive diff and more actions ↗


⚙️ An Nx Cloud workspace admin can disable these reviews in workspace settings.

@lourw lourw force-pushed the gradle-use-configuration-dependencies branch from 815f5aa to 44c99d3 Compare September 12, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants