build.gradle changes for git submodule

2019-05-06 15:49发布

Source Tree is as follows:

core               // root
  .gitmodules     // this has box-sdk as submodule
  box-sdk          // git submodule
     BoxJavaLibraryV2     // Box related files

I also created settings.gradle

include 'box-sdk:BoxJavaLibraryV2'

My build.gradle

compile project(':box-sdk:BoxJavaLibraryV2')

At this point I was able to compile and build root project with box as dependency.

Problem started when I tried to checkin and checkout again the whole project. I did following:

I was able to check in .gitmodules and box-sdk directory. But I was not able to checkin BoxJavaLibraryV2.

It errored out saying BoxJavaLibraryV2 is a submodule

I checked out root again separately where I get both .gitmodules and box-sdk (without BoxJavaLibraryV2)

Then to build my project I had to do manually:

git submodule init
git submodule update
gradle war

What changes and where I need to do to eliminate init and update steps.

What I am looking for is:

when I checkout git master, the whole project with submodules should build with gradle war

Please help

1条回答
别忘想泡老子
2楼-- · 2019-05-06 16:46

First, you can have only one step:

git submodule update --init --recursive

Second, Gradle itself has an open issue (since 2010) to integrate that step:
GRADLE-21: "Streamline issues with including the build as a git submodule".

A git clone --recursive would clone:checkout your repo with submodules checked out.

The issue suggests various ways, one of them being making a gradle wrapper (which would call the appropriate git submodule command before calling gradle).

查看更多
登录 后发表回答