Gradle subproject build dependency
Asked Answered
P

1

8

I have a dependency problem and I do not know how to solve it.

I have a project A, B and C.

A needs B and C

B needs C

My directory structure looks like this:

A
|-settings.gradle
|-build.gradle
|-lib
   |- B
   |- C

settings.gradle content:

include 'lib/B'
include 'lib/C'

build.gradle content:

apply plugin: 'java'
dependencies {
  compile project(':lib/B'), 
          project(':lib/C') 
}

project(':lib/B'){
  dependencies {
    compile project(':lib/C')
  }
}

If I do NOT declare the project(':lib/B'){...} part, project B can not be build because of dependencies.

If I declare the project(':lib/B'){...} part, Gradle tells me : Could not find method compile() for arguments [project ':lib/C'] on org.gradle.api.internal.artifacts.dsl.pendencies.DefaultDependencyHandler_Decorated@221bad.

How am I able to solve it, or compile C before B?

PS: Data structure changes are not possible.

Plague answered 4/9, 2015 at 6:7 Comment(1)
Do you have a separate build.gradle for your B and C subprojects?Acrobatic
I
10

Please, try to add

subprojects {
    apply plugin: 'java'
}

to your main build.gradle

Idolla answered 4/9, 2015 at 7:2 Comment(2)
This fixes the issue, although I already have separate build.gradle files for my B and C which are containing this plugin.Plague
This answer helped me to realize that inside scope of subprojects/allprojects {} you can't use plugin specific blocks (e.g. dependencies {} from java plugin) unless you apply plugin explicitly.Cousingerman

© 2022 - 2024 — McMap. All rights reserved.