2

I have three eclipse projects (Project A, Project B, and Project C) in my workspace. Project B and C depend on Project A.

In my build.gradle file, I've set up the dependencies in B and C to refer to A:

repositories {
    mavenCentral()
    mavenLocal()
}

dependencies {
    compile('com.example:projectA:1.0')
}

However, when I right click and select Gradle->Refresh Gradle Project on Project B or C, it states that it is unable to resolve the projectA dependency.

I'm using Mars 4.5.2 and Buildship version 1.0.20. I understand that Buildship 2.0 once released will provide support such that it can refer to other eclipse projects as dependencies. In the interim though, how do I install project A into the repo and refer to it in project B and C? I do not see an install option for project A in the Buildship Gradle Tasks.

Hans
  • 2,419
  • 2
  • 30
  • 37
James
  • 2,876
  • 18
  • 72
  • 116
  • Does the above config build successfully if you use the gradle command line? `./gradlew projectB:build` – Jolta Sep 27 '16 at 15:19
  • No. It states `Could not find com.example:projectA:1.0. Searched in the following locations:` The locations include the local repo. When I navigate the local repo file system, I also cannot find the path to projectA, so my issue appears to be the inability to install project A in the local repo. But I'm not sure how to install project A using Buildship. – James Sep 27 '16 at 15:27
  • I think your problem is not related to Buildship... I'll post an answer. – Jolta Sep 27 '16 at 15:28
  • What gradle version are you using? – Jolta Sep 27 '16 at 15:28
  • Thanks. I'm using version 2.11 – James Sep 27 '16 at 15:33

1 Answers1

1

You've added a dependency using a GAV (group-artifact-version): com.example:projectA:1.0.

When you declare a dependency in gradle using a GAV, gradle assumes that it should go look for that dependency in all the available Maven or Ivy repositories that it knows about. I presume that the reason it can't resolve the GAV, is that you never published project A to any repository where your build is searching.

You have two ways out:

  1. Publish project A's output (jar files) to a Maven repo. You would need to apply the Maven publishing plugin. For example, you could publish to your local repo using "gradle publishToMavenLocal".

  2. Declare the dependency as a Project dependency, and keep your projects as sub-project of the same parent project. You'd declare the dependency as compile project(':projectA')

The latter is probably a lot easier to work with.

BTW, Buildship itself probably has little to do with this issue, rather it's a general problem of using dependency tracking build systems like Gradle or Maven. I remember seeing some reference to how Gradle would solve this problem better in 3.0 and up, but I can't seem to find the link at the moment.

Jolta
  • 2,620
  • 1
  • 29
  • 42
  • 1
    In Gradle 3.1, [composite builds](https://docs.gradle.org/current/userguide/composite_builds.html) is an option. It's not supported in Buildship 1.0.20 but will be in 2.0. In the interim, I'm choosing to use the Maven publishing plugin. It should be easy to convert to using composites once supported. My existing repo (SVN) directory structure does work with the Gradle standard multi-project structure. – James Sep 28 '16 at 17:54
  • Thanks for the pointer! I'll be looking into using this, because inter-project dependency has been my major gripe with Gradle so far. – Jolta Sep 29 '16 at 07:01