Apply gradle file from different repository

匿名 (未验证) 提交于 2019-12-03 02:11:02

问题:

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.

  1. 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.
  2. 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
  3. 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.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!