-
Notifications
You must be signed in to change notification settings - Fork 2.6k
feat(gradle): use project configurations to determine project dependencies #32704
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
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.
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.
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.
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
}
⚙️ An Nx Cloud workspace admin can disable these reviews in workspace settings.
815f5aa
to
44c99d3
Compare
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 #