G. Blake Meike
G. Blake Meike

Reputation: 6715

Gradle: Can I depend on a module in a different project?

I would like to set up a project with the following structure:

Project 1
  + build.gradle
  + settings.gradle
  + module A
      + build.gradle
      + src
      + ...
  + module B
      + build.gradle
      + src
      + ...
Project 2
  + build.gradle
  + settings.gradle
  + module C
      + build.gradle
      + src
      + ...
  + module D
      + build.gradle
      + src
      + ...

I would like Project 1's module A to depend on Project 2's module D. I would like this to be a source (not maven artifact) dependency and to work with gradle 2.14 and Android Studio 2.1.

I do not control the layout of Project 2 or it's root build.gradle. All I can do is pull it into my workspace and use it.

I have complete control over Project 1, and can set it up any way that I want. I would prefer that a full build of Project 1 did not cause a complete build of Project 2, just :project2:moduleD. Anything that works, though, will do.

I'd like to know how to set up the build.gradle files for Project 1, and what to put in the dependency clause in the build.gradle for Module A.

Upvotes: 0

Views: 322

Answers (3)

Zero Code
Zero Code

Reputation: 19

you can check blow URl

https://docs.gradle.org/current/userguide/declaring_dependencies_between_subprojects.html

and make sure that all this project share same root project

Example for gradle:

rootProject.name = 'sof-portofolio'

include 'core:model1','service:model2'

Upvotes: 0

kageiit
kageiit

Reputation: 61

have you tried a symlink? Make a symlink in project 1 to project D's folder and add it to project 1's settings.gradle

Upvotes: 0

Pieces
Pieces

Reputation: 2295

I'm taking a guess that what you described is not set up a multi-project, that is they are two stand alone projects. If you can't convince the maintainer to publish the artifact anywhere and you always need the latest version of Project 2. Your best bet is to link to the project's output jar file.

compile files('path/to/Project2/build/output.jar')

This would require a build to be run on Project 2 after the latest source is pulled onto the system. If you have a specific location of the project you could automate this a bit more but all of it is pretty fragile.

Upvotes: 1

Related Questions