feat(gradle): use project configurations to determine project dependencies#32704
feat(gradle): use project configurations to determine project dependencies#32704FrozenPandaz merged 5 commits intomasterfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
db84552 to
718b69a
Compare
|
View your CI Pipeline Execution ↗ for commit 44c99d3
☁️ Nx Cloud last updated this comment at |
| import org.gradle.api.internal.artifacts.result.DefaultResolvedDependencyResult | ||
| import org.gradle.internal.component.local.model.DefaultProjectComponentSelector |
There was a problem hiding this comment.
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.ProjectComponentSelectorThis would make the implementation more robust against Gradle upgrades and follow Gradle's recommended practices for plugin development.
| 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
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
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
}
⚙️ An Nx Cloud workspace admin can disable these reviews in workspace settings.
815f5aa to
44c99d3
Compare
…cies (#32704) ## 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) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: lourw <56288712+lourw@users.noreply.github.com> (cherry picked from commit 537bb42)
…cies (#32704) ## 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) <!-- Please link the issue being fixed so it gets closed when this is merged. --> Fixes # --------- Co-authored-by: lourw <56288712+lourw@users.noreply.github.com>
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
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 #