Gitlab-ci.yml file configuration for maven projects under single repository

I have a repository setup where there are multiple maven projects, 2 are main projects and rest are dependency project. I would like to configure gitlab-ci.yml file to handle changes in dependency to project to trigger build for corresponding main project.

Here is the example of project structure. There are 2 main projects and rest are dependency project. Main Project AB have 2 dependency project (A&B) and Main project CD have 2 dependency (C&D). If there is any change in project A or B, it should trigger main project AB. If there is any change in project C or D, it should trigger main project CD. How to write this condition in gitlab-ci.yml file? Do we need multiple .gitlab-ci.yml file for each project ?

  master
  - Dependency Project A
  - Dependency Project B
  - Main Project AB
  - Dependency Project C
  - Dependency Project D
  - Main Project CD
  - .gitlab-ci.yml