-
-
Notifications
You must be signed in to change notification settings - Fork 117
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
#1114 print build path in projectHealth #1178
#1114 print build path in projectHealth #1178
Conversation
28dfb6c
to
cd7f7ef
Compare
I've updated the implementation moving the gradle file name prepending to |
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.
Thanks for this contribution! I only worry about it being inconsistent with how buildHealth
works, while simultaneously being concerned about how verbose it would be if buildHealth
also had this behavior. But I'm happy to support this use-case, for the reasons you indicated.
@@ -15,6 +15,8 @@ import org.gradle.api.tasks.TaskAction | |||
|
|||
abstract class ProjectHealthTask : DefaultTask() { | |||
|
|||
private val buildFilePath = project.buildFile.path |
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.
I don't think this should be an instance property. You can just move this down into the task action.
Oh, and of course I think that means that either buildFile
or buildFile.path
must then be a task input property.
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.
The project
(getProject()
) cannot be executed inside of @TaskAction
for tasks that are not explicitly marked as non-cacheable:
1 problem was found storing the configuration cache.
- Task `:proj:projectHealth` of type `com.autonomousapps.tasks.ProjectHealthTask`: invocation of 'Task.project' at execution time is unsupported.
See https://docs.gradle.org/7.4/userguide/configuration_cache.html#config_cache:requirements:use_project_during_execution
So this simple trick is used to resolve the project parameter on the phase before TaskAction execution and not to pass as Input from the plugin. You suggested to make it an input - Done. Initially I didn't mark it as input, because this task is not cacheable.
private fun prependBuildPath(consoleReport: String): String { | ||
return buildFilePath + "\n" + consoleReport | ||
} |
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.
I would prefer this be inlined.
val output ="${project.buildFile.path}\n$consoleReport
for example.
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.
Done
def "projectHealth prints build file path (#gradleVersion)"() { | ||
given: | ||
def project = new AbiGenericsProject(SourceKind.METHOD) | ||
gradleProject = project.gradleProject | ||
|
||
when: | ||
var result = build(gradleVersion, gradleProject.rootDir, 'projectHealth') | ||
|
||
then: | ||
assertThat(result.output).contains( | ||
"""${gradleProject.rootDir.getPath()}/proj/build.gradle | ||
|Existing dependencies which should be modified to be as indicated: | ||
| api project(':genericsBar') (was implementation) | ||
| api project(':genericsFoo') (was implementation) | ||
|""".stripMargin()) | ||
|
||
where: | ||
gradleVersion << gradleVersions() | ||
} |
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.
Could you instead create a new spec, ProjectHealthSpec
, and put this test there? You can continue to use AbiGenericsProject
, if you prefer. I realize that we don't have any specs that run projectHealth
, so it makes sense to have that encapsulated somewhere.
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.
Done
gradleProject = project.gradleProject | ||
|
||
when: | ||
var result = build(gradleVersion, gradleProject.rootDir, 'projectHealth') |
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.
Please use def
instead of var
for consistency.
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.
Done
cd7f7ef
to
9a02fcc
Compare
What would you prefer - address both |
Solves #1114 (only
projectHealth
, but notbuildHealth
).Prints absolute path of according
build.gradle
of the project module. This can be pretty helpful in large multi-module projects, especially when there is no full matching between module name and submodule directory.Sample task output:
Using absolute path
The absolute path is printed intentionally as it seems to be the best trade-off.
![Screenshot 2024-04-27 at 19 25 50](https://private-user-images.githubusercontent.com/2844909/326197662-68ce483d-6ee0-4c5c-b8c5-f392c94d1115.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYwMjEyMTAsIm5iZiI6MTcyNjAyMDkxMCwicGF0aCI6Ii8yODQ0OTA5LzMyNjE5NzY2Mi02OGNlNDgzZC02ZWUwLTRjNWMtYjhjNS1mMzkyYzk0ZDExMTUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDkxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA5MTFUMDIxNTEwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTcwMTdjYzYyOGEyY2VmMGMyMmMyZWFkMzAyMTNjODNkNDA2OGRhODQxYTYxYThlOWFhYTVlNThkNWU1NWVmNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.jJ6psWQL7TWhfDhJoQpBJhdnykZejFmHfcxETWbn9ns)
![Screenshot 2024-04-27 at 19 26 10](https://private-user-images.githubusercontent.com/2844909/326197703-9aa48f3d-66e9-4f6d-b34d-be838fd0d3eb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYwMjEyMTAsIm5iZiI6MTcyNjAyMDkxMCwicGF0aCI6Ii8yODQ0OTA5LzMyNjE5NzcwMy05YWE0OGYzZC02NmU5LTRmNmQtYjM0ZC1iZTgzOGZkMGQzZWIucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDkxMSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA5MTFUMDIxNTEwWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NWFhZTQxOWRmZGE1MDU0NGY5YjdlMzFmYTNlMjU2YzI1YjNhMzI1Yzk1M2ZjNTRlZjFkYjIyNDU1Y2FjN2RkNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.Xqwf6dCit3X2KnD_YWltuMp_kqqaLF0lxrkZNRGRPrU)
This path is recognized in IDEA to open file in "Navigate to File...":
For instance, if relative path is used, there can be ambiguity:
Also, the relative path is not always in parent directory (for included builds) and printing "../../parent/build.gradle" will not help navigating to the file in the IDE.