Skip to content
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

Detekt Gradle Task Is Not Remote Gradle Cache Friendly #7170

Open
AlexanderGH opened this issue Apr 12, 2024 · 3 comments
Open

Detekt Gradle Task Is Not Remote Gradle Cache Friendly #7170

AlexanderGH opened this issue Apr 12, 2024 · 3 comments

Comments

@AlexanderGH
Copy link

Expected Behavior

It should be possible to configure the detekt tasks in such a way as they can be cached in CI or one machine and then get a cache hit on another machine where the code lives under a different path while not breaking any functionality.

Observed Behavior

It is not possible to use the gradle remote cache without breaking the basePath functionality since the base path, at least from the documentation, takes an absolute path which will differ on different machines which will then result in different task cache keys and therefore cache misses.

Steps to Reproduce

Run detekt on two machines where the module has different paths on the file system. If you have the gradle remote cache enabled, you will notice that there is a cache miss and different cache keys for the two runs due ti the different basePath values.

The only way I've found to make it work is to pass "" as the basePath, but then we get non-relativized paths in the generated reports.

Context

It's nice to allow developers and CI builds to leverage a shared cache.

Your Environment

  • Version of detekt used: 1.23.6
  • Version of Gradle used: 8.7
  • Gradle scan link (add --scan option when running the gradle task):
  • Operating System and version:
  • Link to your project (if it's a public repository):
@BraisGabin
Copy link
Member

I think that to be able to implement this we will need #6879.

With that we could split the task in two. One with the analysis (that is the heavy part) and it should be cacheable and another(s) task(s) with the report creation. That last one would not be cacheable because it would depend on the absolute path but it should be a really fast.

@AlexanderGH
Copy link
Author

AlexanderGH commented Apr 12, 2024

What are your thoughts of accepting a relative path (relative to the module path)?

Then the implementation would do something like:
fileWithIssues.absolutePath.stripPrefix(File(projectDir.absolutePath, baseDir).absolutePath)

I imagine that's the usual use-case and would allow everything to be cacheable.

Alternatively, I think this could be solved by accepting a File instead of a string and marking it with @PathSensitive(PathSensitivity.NAME_ONLY). I would hope gradle would then relativize the input and make the outputs relocatable.

@AlexanderGH
Copy link
Author

Here's my concrete proposal that should be mostly backwards compatible:

  • accept the directory of the project projectRootPath as an input with @PathSensitive(PathSensitivity.NAME_ONLY) defaulting to the current dir by convention
  • if basePath does not start with a "/", assume it is relative and then get the base path using File(projectRootPath, basePath)
    • You might need to use some level of canonicalPath or absolutePath on the base path and detected file locations
  • if basePath starts with a '/', assume it is the absolute path and just use that as you do today

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants