<p>What you need is not to checkout both projects side by side, but to add the library as a <a href="https://git-scm.com/book/en/v2/Git-Tools-Submodules" rel="nofollow noreferrer">Git submodule</a> in your application repository.</p>
<p>Then <a href="https://docs.gitlab.com/ee/ci/git_submodules.html" rel="nofollow noreferrer">set up GitLab CI</a> to checkout submodules before build.</p>
<p>This will not only make your CI work, but as an added benefit each commit from application repository will reference a specific commit from library repository, so  nobody will have to remember what commit to checkout in library repository to ensure the application builds correctly.</p>
<p>Edit:</p>
<p>To be clear, I'm not saying that <a href="https://docs.gradle.org/current/userguide/composite_builds.html" rel="nofollow noreferrer">composite builds</a> (which is a proper name for your setup) are always bad, but I believe that they should be used for optional dependencies (like JetBrains did in their <a href="https://github.com/JetBrains/kotlin-native" rel="nofollow noreferrer">kotlin-native repository</a>) or when developers need need to have an option of replacing dependency norally pulled from some Maven repository with locally build version (eg. to test if their app works with some changes in the library before submitting pull/merge request for the library) and not for everyday use.</p>

CC BY-SA 4.0
2020-08-03T22:05:52.063Z
2020-08-04T09:41:01.893Z
2020-08-04T09:41:01.893Z
Konrad Botor
<p>There is an Android application using Grandle for build. It uses a &quot;library&quot; stated in build.gradle file:</p>
<pre><code>dependencies {
    api project(path: ':specialproject.speciallibrary', configuration: 'default')
</code></pre>
<p>It is configured in settings.gradle:</p>
<pre><code>include ':specialproject.speciallibrary'
project(':specialproject.speciallibrary').projectDir = new File('../specialprojectlibrary')
</code></pre>
<p>Developers currently have the main project and specialprojectlibrary projects side-by-side on their computers. So when they build it, Gradle fetches specialprojectlibrary and builds it when building the main app (APK.</p>
<p>Now, when would like to have GitLab CI/CD for the app. Main app and library app are in separe Git repositories and under separate projects inside a group in GitLab.</p>
<p>After creating CI/CD it occured it throws error:</p>
<p>FAILURE: Build failed with an exception.</p>
<pre><code>* What went wrong:
Could not determine the dependencies of task ':something:xyz'.
&gt; Could not resolve all task dependencies for configuration ':something:xyz'.
   &gt; **Could not resolve project :specialproject.speciallibrary.**
     Required by:
         project :mainproject
      &gt; Project :mainproject declares a dependency from configuration 'api' to configuration 'default' which is not declared in the descriptor for project :specialproject.speciallibrary.
</code></pre>
<p>I assume it is because it canon CI/CD Gradle of the main app does not have access to library code under .//specialprojectlibrary.</p>
<p>So my question is:</p>
<p>How to copy library source code from other Git repo to an Android Gradle application GitLab build process?</p>

<continuous-integration><gitlab><continuous-deployment><gitlab-ci-runner><gradle>
How to copy library source code from other Git repo to an Android Gradle application GitLab build process?
Tom Smykowski
# How to copy library source code from other Git repo to an Android Gradle application GitLab build process?

(Asked by: username_0 on 2020-08-03)

There is an Android application using Grandle for build. It uses a "library" stated in build.gradle file:
dependencies {
    api project(path: ':specialproject.speciallibrary', configuration: 'default')

It is configured in settings.gradle:
include ':specialproject.speciallibrary'
project(':specialproject.speciallibrary').projectDir = new File('../specialprojectlibrary')

Developers currently have the main project and specialprojectlibrary projects side-by-side on their computers. So when they build it, Gradle fetches specialprojectlibrary and builds it when building the main app (APK.
Now, when would like to have GitLab CI/CD for the app. Main app and library app are in separe Git repositories and under separate projects inside a group in GitLab.
After creating CI/CD it occured it throws error:
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine the dependencies of task ':something:xyz'.
> Could not resolve all task dependencies for configuration ':something:xyz'.
   > **Could not resolve project :specialproject.speciallibrary.**
     Required by:
         project :mainproject
      > Project :mainproject declares a dependency from configuration 'api' to configuration 'default' which is not declared in the descriptor for project :specialproject.speciallibrary.

I assume it is because it canon CI/CD Gradle of the main app does not have access to library code under .//specialprojectlibrary.
So my question is:
How to copy library source code from other Git repo to an Android Gradle application GitLab build process?

**Tags:** continuous-integration, gitlab, continuous-deployment, gitlab-ci-runner, gradle


---

## 1 answers

### Answer by username_1 on 2020-08-03. Score: 2

What you need is not to checkout both projects side by side, but to add the library as a [Git submodule](https://git-scm.com/book/en/v2/Git-Tools-Submodules) in your application repository.

Then [set up GitLab CI](https://docs.gitlab.com/ee/ci/git_submodules.html) to checkout submodules before build.

This will not only make your CI work, but as an added benefit each commit from application repository will reference a specific commit from library repository, so nobody will have to remember what commit to checkout in library repository to ensure the application builds correctly.

Edit:

To be clear, I'm not saying that [composite builds](https://docs.gradle.org/current/userguide/composite_builds.html) (which is a proper name for your setup) are always bad, but I believe that they should be used for optional dependencies (like JetBrains did in their [kotlin-native repository](https://github.com/JetBrains/kotlin-native)) or when developers need need to have an option of replacing dependency norally pulled from some Maven repository with locally build version (eg. to test if their app works with some changes in the library before submitting pull/merge request for the library) and not for everyday use.


---

