可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
We have multiple git repositories for different projects. There is also a git repository for infrastructure purpose. We have custom gradle plugins written in this infrastructure repository which we use in other repositories
Example:
buildscript { apply from: 'foo/bar/devinfra-buildscript.gradle', to: buildscript } apply plugin: 'devinfra'
Here we are having the buildscript{} file, foo/bar/buildscript.gradle in every Git repository. I want to know if there is a way where we can apply the file directly from a infrastructure repository. So that any change is visible across other repositories directly.
回答1:
In that case, you could add a git subtree Merging (different to git subtree) to each of your repo, referring to the infra repo.
You can see a study doing that in "Managing Nested Libraries Using the GIT Subtree Merge Workflow".

In your case:
To update the project repo with subtree changes:
To update the subtree repo with change from the subtree folder of the project repo:
回答2:
The answer depends on what exactly you're going to achieve.
- If you simply want to update your build file in one place and "automagically" receive the changes in all project repos, then you probably should take the file out of GIT control and, for example, simply use a link or something like that to an outer location.
- The second option is to move all the build stuff into a common directory, make that directory a separated shareable GIT repository and then plug-in that repository in all your projects repos, e.g. as a submodule But in this case you won't receive "automagical" updates because git strictly binds submodule content to a particular commit in the submodule and une need to run
git submodule update and subsequent git commit to receive updated contents in your project repos. The variant of this method is git subtree merge proposed by @VonC - If your build machinery is complex enough you may want to consider creating a "gradle artifact" and hide the complexity there. Then you may plug in that artifact to your projects and rely not on a particular version of the artifact but rather on a range of versions
回答3:
Assuming the Git repository is accessible over HTTP(S), one option is to use apply from: "http://...". Note that script plugins accessed over HTTP aren't currently cached, so the build will fail if the script cannot be fetched.