-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix(gradle): ensure Gradle 9 compatibility in FilesTaskV2 #4472
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
Changes from 3 commits
5ba76f1
fdbeec3
e6705cc
a3d1cac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -91,16 +91,16 @@ public void listFiles() throws IOException { | |||||
|
|
||||||
| Set<File> projectDependencyJars = new HashSet<>(); | ||||||
| for (ProjectDependency projectDependency : projectDependencies) { | ||||||
| addProjectFiles(projectDependency.getDependencyProject()); | ||||||
| Project dependentProject = getDependentProject(projectDependency); | ||||||
| addProjectFiles(dependentProject); | ||||||
|
|
||||||
| // Keep track of project dependency jars for filtering out later | ||||||
| String configurationName = projectDependency.getTargetConfiguration(); | ||||||
| if (configurationName == null) { | ||||||
| configurationName = "default"; | ||||||
| } | ||||||
| Project dependencyProject = projectDependency.getDependencyProject(); | ||||||
| for (Configuration targetConfiguration : | ||||||
| dependencyProject.getConfigurations().getByName(configurationName).getHierarchy()) { | ||||||
| dependentProject.getConfigurations().getByName(configurationName).getHierarchy()) { | ||||||
| for (PublishArtifact artifact : targetConfiguration.getArtifacts()) { | ||||||
| projectDependencyJars.add(artifact.getFile()); | ||||||
| } | ||||||
|
|
@@ -142,8 +142,7 @@ private void addGradleFiles(Project project) { | |||||
| skaffoldFilesOutput.addBuild(project.getBuildFile().toPath()); | ||||||
|
|
||||||
| // Add settings.gradle | ||||||
| if (GradleVersion.current().compareTo(GRADLE_9) < 0 | ||||||
| && project.getGradle().getStartParameter().getSettingsFile() != null) { | ||||||
| if (isBeforeGradle9() && project.getGradle().getStartParameter().getSettingsFile() != null) { | ||||||
| skaffoldFilesOutput.addBuild( | ||||||
| project.getGradle().getStartParameter().getSettingsFile().toPath()); | ||||||
| } else if (Files.exists(projectPath.resolve(Settings.DEFAULT_SETTINGS_FILE))) { | ||||||
|
|
@@ -212,7 +211,7 @@ private Set<ProjectDependency> findProjectDependencies(Project project) { | |||||
| // If this is a project dependency, save it | ||||||
| ProjectDependency projectDependency = (ProjectDependency) dependency; | ||||||
| if (!projectDependencies.contains(projectDependency)) { | ||||||
| projects.push(projectDependency.getDependencyProject()); | ||||||
| projects.push(getDependentProject(projectDependency)); | ||||||
| projectDependencies.add(projectDependency); | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -222,4 +221,36 @@ private Set<ProjectDependency> findProjectDependencies(Project project) { | |||||
| } | ||||||
| return projectDependencies; | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Resolves a {@link ProjectDependency} to its corresponding {@link Project} instance. | ||||||
| * | ||||||
| * <p>This method handles the removal of {@code ProjectDependency.getDependencyProject()} in | ||||||
| * Gradle 9.0 by falling back to {@code getPath()} and resolving it via the project hierarchy. | ||||||
| * | ||||||
| * @param projectDependency the project dependency to resolve | ||||||
| * @return the resolved project | ||||||
| * @throws RuntimeException if the dependent project could not be resolved | ||||||
| */ | ||||||
| private Project getDependentProject(ProjectDependency projectDependency) { | ||||||
| if (isBeforeGradle9()) { | ||||||
| return projectDependency.getDependencyProject(); | ||||||
| } | ||||||
| try { | ||||||
| String path = | ||||||
| (String) projectDependency.getClass().getMethod("getPath").invoke(projectDependency); | ||||||
| return getProject().project(path); | ||||||
| } catch (Exception ex) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching the generic
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I applied your suggestion. Please verify that is solved and resolve this conversation.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, apparently gemini code assist does not react to conversations the same way coderabbit does 😁 |
||||||
| throw new RuntimeException("Failed to get dependent project from " + projectDependency, ex); | ||||||
| } | ||||||
| } | ||||||
|
|
||||||
| /** | ||||||
| * Checks if the current Gradle version is older than 9.0. | ||||||
| * | ||||||
| * @return {@code true} if the current Gradle version is less than 9.0, {@code false} otherwise | ||||||
| */ | ||||||
| private static boolean isBeforeGradle9() { | ||||||
| return GradleVersion.current().compareTo(GRADLE_9) < 0; | ||||||
| } | ||||||
| } | ||||||
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.
this was removed in gradle9, so reflection needs to be used here as well
https://docs.gradle.org/current/userguide/upgrading_major_version_9.html#removal_of_custom_build_layout_options