Want to create simple plugin/script

The project I am working on is Gradle based. So I want to create a plugin/script that will run a certain Gradle task whenever I made changes to one of the files from the project. 

For example 

There is A.xml file and a B Gradle task. Whenever I do changes to A.xml and save it I want the B Gradle task to be run.

Can you suggest where to start? Should it be done through plugins? Maybe there are automatisation settings that have file watchers or smth. Thanks.