How to write a custom build step

I would like to write a custom step in our build that validates the filenames of a set of files in one of the source code directories. If the files are invalid then the build should fail. This custom step is specific to a single project and won’t be needed in other projects. What is the best way to do this? Should I write a custom plugin, should I write a custom task? Should I write the step directly into the build.gradle file of my project?

Hi - to better help, could you please give and idea of the file and directory structures please?

Based on what you’ve said, if it’s not used across projects, a plugin feels like overkill.