Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apply gradle file from different repository

Tags:

git

gradle

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.

like image 336
Sundeep Gupta Avatar asked Jul 12 '14 04:07

Sundeep Gupta


People also ask

What is Mavencentral () in Gradle?

Maven Central is a popular repository hosting open source libraries for consumption by Java projects. To declare the Maven Central repository for your build add this to your script: Example 1. Adding central Maven repository. build.gradle.

What is apply from in Gradle?

#1 Use 'apply' to structure the script content In Gradle apply command can be used to apply not only plugins, but also script files (*). In this way you can divide your main build. gradle file into smaller parts, and move extra tasks like jacoco report and findbugs to the separate files.

How do I change the build Gradle file?

It says Project change it to Android from drop down menu. That tab will have only the necessary files. There you will find both the Project gradle and module gradle. The thing is you can find those files in Project also but it's easy and more convenient to work in Android Tab.


1 Answers

In that case, you could add a git subtree Merging (different to git subtree) to each of your repo, referring to the infra repo.

git read-tree --prefix=<subdirectory_name>/ –u <shared_library_branch>

You can see a study doing that in "Managing Nested Libraries Using the GIT Subtree Merge Workflow".

http://www.typecastexception.com/image.axd?picture=Subtree%20Illustration_thumb_1.png

In your case:

cd /path/to/project
git remote add infrarepo /url/to/infra/repo
git fetch infrarepo
git checkout -b infra infrarepo/master

git checkout master
git read-tree --prefix=infra/ –u infra
git commit -m "Add Infra subtree"

To update the project repo with subtree changes:

git checkout infra
git pull
git checkout master
git merge --squash –s subtree –-no-commit infra
git commit -m "update infra"

To update the subtree repo with change from the subtree folder of the project repo:

git checkout infra
git merge --squash –s subtree --no-commit master
git commit -m "(infra subtree) nature of changes"

git push infrarepo infra
like image 82
VonC Avatar answered Oct 02 '22 21:10

VonC