Skip to content

LeetCode Came in Handy

Right in real life, yeah.

I was writing a Gradle task that finds the longest path from the root app-module to the farthest module it depends on through the chain. Moreover, I wanted to not only get the length of this critical path, but also the modules that participate in this path.

The first and main difficulty in this task actually isn't in traversing the graph, but in the fact that you can't understand Gradle concepts without reaching the Ballmer peak. Project has many Configurations, each Configuration has many Dependencies, Dependency can be of type ProjectDependency (you can literally cast it), and from it you can get Project in turn. From here you can already go into recursion or put in a queue. Thus with two loops we get projects that the current one depends on. And to learn all this I employed all forces.

The internet isn't talkative when it comes to writing Gradle tasks, it feels like two and a half people are doing this, who also don't share their knowledge. ChatGPT with a straight face carried nonsense time after time, and even my attempts to explain something to it never ended with working code. Copilot gave me even less useful info. Although, truth be told, I picked up some ideas from them, without them I would have dug into documentation for a long time.

The second difficulty is the algorithm itself. Remembered the word backtracking, wrote a function with that name and Copilot wrote the whole structure for me.

Beautiful. Works. I feel an emotional uplift.