copy-plugin-deps: Copy Bazel dependency files from plugins

Copy external_plugin_deps.bzl into the Gerrit plugins directory
when present.

Also copy external_plugin_deps.MODULE.bazel when present, so
plugins using Bazel module dependency declarations are handled
the same way.

Update the role documentation accordingly.

Issue: 492561165
Change-Id: Id23dbe3b3fd24f63413e49d44ba3ef428e4faed0
diff --git a/roles/copy-plugin-deps/README.rst b/roles/copy-plugin-deps/README.rst
index 9a86596..4d219a4 100644
--- a/roles/copy-plugin-deps/README.rst
+++ b/roles/copy-plugin-deps/README.rst
@@ -1,7 +1,16 @@
-Copy plugin bazel deps
+Copy plugin Bazel dependency files
+==================================
 
-If the plugin being built has an ``external_plugin_deps.bzl`` file,
-copy it into the Gerrit plugins directory.
+This role copies Bazel dependency files from a plugin source tree
+into the Gerrit ``plugins`` directory when they are present.
+
+If the plugin being built contains an ``external_plugin_deps.bzl`` file,
+it is copied into the Gerrit plugins directory.
+
+If the plugin being built contains an ``external_plugin_deps.MODULE.bazel``
+file, it is also copied into the Gerrit plugins directory.
+
+Both files are optional and are copied only if they exist.
 
 **Role Variables**
 
diff --git a/roles/copy-plugin-deps/tasks/main.yaml b/roles/copy-plugin-deps/tasks/main.yaml
index d2fdbdb..7dd5f5e 100644
--- a/roles/copy-plugin-deps/tasks/main.yaml
+++ b/roles/copy-plugin-deps/tasks/main.yaml
@@ -5,4 +5,13 @@
 
 - name: Copy external plugin deps
   command: "cp -f {{ ansible_user_dir }}/src/gerrit.googlesource.com/gerrit/plugins/{{ gerrit_plugin }}/external_plugin_deps.bzl {{ gerrit_root }}/plugins"
-  when: "deps_stat.stat.exists is true"
+  when: deps_stat.stat.exists
+
+- name: Check if external plugin deps MODULE file exists
+  stat:
+    path: "{{ ansible_user_dir }}/src/gerrit.googlesource.com/gerrit/plugins/{{ gerrit_plugin }}/external_plugin_deps.MODULE.bazel"
+  register: module_deps_stat
+
+- name: Copy external plugin deps MODULE file
+  command: "cp -f {{ ansible_user_dir }}/src/gerrit.googlesource.com/gerrit/plugins/{{ gerrit_plugin }}/external_plugin_deps.MODULE.bazel {{ gerrit_root }}/plugins"
+  when: module_deps_stat.stat.exists