Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependencies of subproject can not be resolved for dependent project (but are resolved when building subproject itself)

Tags:

java

gradle

Following the explanation in "Building and Testing with Gradle" I have a multiproject gradle setup like this:

rootFolder
    build.gradle
    settings.gradle
    EMS
        build.gradle
    cloud-sdk
        build.gradle

The cloud-sdk project depends on several jars, partially resolved via maven partially via locale jars:

// file: cloud-sdk/build.gradle
apply plugin: 'java'

repositories {
    mavenCentral()
}

dependencies {
    compile group:'org.apache.tomcat', name:'tomcat-catalina', version:'7.0.47'
    compile group:'org.mongodb', name:'mongo-java-driver', version:'2.11.3'
    compile group:'com.google.code.gson', name:'gson', version:'2.2.4'
    compile group:'com.thoughtworks.xstream', name:'xstream', version:'1.4.6'
    compile fileTree(dir:'lib/', include:'JavaPNS_2.2.jar')
    compile fileTree(dir:'lib/', include:'gcm-server.jar')
}

The EMS-project depends on the cloud-sdk which I think should be defined like this:

// file: EMS/build.gradle
apply plugin: 'java'

dependencies {
    compile project(':cloud-sdk')
}

Furthermore, my root build.gradle and settings.gradle files look like this:

settings.gradle

include 'cloud-sdk', 'EMS'

build.gradle

apply plugin: 'java'

dependencies {
    compile project(':EMS')
}

In this case I am not sure whether I also need the dependency compile project (':cloud-sdk'). I tried both version but since I get the same error message in both cases I assume it doesn't matter.

When I try to run the script from the rootFolder via gradle build I get the following error messages:

Could not resolve all dependencies for configuration ':EMS:compile'.
> Could not find org.apache.tomcat:tomcat-catalina:7.0.47.
  Required by:
    rootFolder:EMS:unspecified > rootFolder:cloud-sdk:unspecified
> Could not find org.mongodb:mongo-java-driver:2.11.3.
  Required by:
    rootFolder:EMS > rootFolder:cloud-sdk:unspecified
> Could not find com.google.code.gson:gson:2.2.4.
  Required by:
    rootFolder:EMS > rootFolder:cloud-sdk:unspecified
> Could not find com.thoughtworks.xstream:xstream:1.4.6.
  Required by:
    rootFolder:EMS:unspecified > rootFolder:cloud-sdk:unspecified

But when I just build the cloud-sdk project via gradle cloud-sdk:build gradle downloads the required jars and builds the project without a problem.

But even if I try gradle build after that, although gradle notices that the cloud-sdk project is already up-to-date, it complains about the missing dependencies.

Why is that? It downloaded them already so they should be available somewhere and even if not the cloud-sdk knows what it needs and how to fetch it. What am I missing? Do I need to specify the dependencies in some other way?

like image 837
Joachim Kurz Avatar asked Jan 08 '14 10:01

Joachim Kurz


People also ask

How do you resolve transitive dependencies in Gradle?

A variant of a component can have dependencies on other modules to work properly, so-called transitive dependencies. Releases of a module hosted on a repository can provide metadata to declare those transitive dependencies. By default, Gradle resolves transitive dependencies automatically.

How will you include a dependency in a 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.

What is subproject in Gradle?

subprojects { sourceCompatibility = 11 } It adds the sourceCompatibility property to all sub-projects. This property is then used by the Gradle build Java Plugin: Java version compatibility to use when compiling Java source. Default value: version of the current JVM in use JavaVersion.


1 Answers

Ok, it turns out gradle could not fetch the dependencies in the EMS project since I did not specify any repositories to fetch them from. I assumed that would not be necessary since the only dependencies I needed it to fetch were declared in the cloud-sdk project and that did have a repository given.

This is basically the solution to my problem, but if anybody can explain to me why it is necessary to specify the repository again or explain why it is a bug in gradle that should be fixed, I'll accept that answer as it would answer the "why" and not just the "how do I get it to work".

like image 189
Joachim Kurz Avatar answered Oct 05 '22 07:10

Joachim Kurz