".\gradlew" works but "gradlew" is not recognized as command?

I’m learning Gradle and in the tutorial I’m following, I needed to execute gradlew command, which gave me this error:

gradlew : The term ‘gradlew’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct
and try again.

But, I found the solution online, and it is to call this command as .\gradlew. I have never seen command invoked in this way, and was wondering, why I was not able to call gradlew, even though it’s on my PATH?

Are you sure gradlew is on your PATH?
Don’t confuse gradle with gradlew.

If you installed a Gradle version and put its installation location to PATH, then gradle would be found as command, but not gradlew.

gradlew is one of the four files that make the Gradle wrapper and are included with the project you build.
Or at least imho they should be included with every project you build and it is a bug if they are not.

You actually never need any installed version of Gradle at all, as you should always use the wrapper to run a build as it auto-provisions and uses the correct Gradle version for that exact build.

How you run gradlew (if . is not part of PATH) depends on what shell you use.
In Bash or similar shells for example it is ./gradlew.
In CMD it indeed is just gradlew.
In PowerShell either ./gradlew or .\gradlew works.

So I’d say you are following a Windows tutorial that was written using CMD while you are using PowerShell.

You are correct. I was trying to execute gradlew as a command, and not a script in the executable file.