简体   繁体   中英

Gradle subproject not recognizing 3rd party dependencies from root build.gradle

I have a project like this:

  • module1
    • src/
    • build.gradle
  • module2
    • src/
    • build.gradle
  • build.gradle
  • settings.gradle

In the root build.gralde I am defining 3rd party dependencies needed by all submodules. However, in intellij the submodules don't seem to recognize the dependencies and won't compile. I've seen this work in the past and can't figure out what I'm doing wrong

Root build.gradle plugins { id 'java' }

group 'com.XXX'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

allprojects {
    repositories {
        mavenLocal()
        mavenCentral()
        jcenter()
    }
}

dependencies { 
   ...
}

settings.gradle

rootProject.name = 'XXX'
include 'module1'
include 'module2'

module1 build.gradle

plugins {
    id 'java'
}

group 'com.XXX'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

I realized I just needed to put the dependencies in the root build.gradle within a "subprojects" block and add the java plugin as well.

subprojects {
    apply plugin: 'java'

    dependencies { 
        ...
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM