Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle Local Project Dependency

Tags:

java

gradle

I have 2 Gradle projects both inside the same directory. The directory structure is as follows:

ParentDirectory\
    GradleProjectA\
        build.gradle
    GradleProjectB\
        settings.gradle
        build.gradle

I want to add GradleProjectA as a dependency to GradleProjectB. In the settings.gradle for GradleProjectB, I've tried adding include 'GradleProjectA' and then in build.gradle: compile project(':GradleProjectA') but that didn't work.

Any help would be greatly appreciated. Thanks.

like image 917
Josh M Avatar asked Apr 07 '16 14:04

Josh M


People also ask

Where are Gradle dependencies stored locally?

The local build cache uses a system directory to store tasks outputs. The default location is the Gradle user home directory that points to $USER_HOME/. gradle/caches. Every time we run the build in our system, artifacts will be stored here.

What is project dependency in Gradle?

A project dependency is a special form of an execution dependency. It causes the other project to be built first and adds the jar with the classes of the other project to the classpath. It also adds the dependencies of the other project to the classpath. You can trigger a gradle :api:compile .

Where should I add dependency in Gradle project?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.

How do I force Gradle to use specific dependency?

If the project requires a specific version of a dependency on a configuration-level then it can be achieved by calling the method ResolutionStrategy. force(java. lang. Object[]).


2 Answers

The way I did something like this is as follows:

GradleProjectB/settings.gradle:

include ':GradleProjectA'
project(':GradleProjectA').projectDir = new File('../GradleProjectA')

GradleProjectB/build.gradle:

compile project(":GradleProjectA")
like image 111
Pavel Dudka Avatar answered Sep 20 '22 01:09

Pavel Dudka


In the latest version of Gradle, you can use Composite Builds, like that:

In GradleProjectB's settings.gradle, add the following line:

includeBuild "../GradleProjectA"

It will automatically handle dependency collisions and all that stuff.

like image 37
Cosmin Ioniță Avatar answered Sep 21 '22 01:09

Cosmin Ioniță