简体   繁体   中英

Gradle compileTestJava fails during gradle clean build

I'm currently having this strange issue with gradle build. Below are the details.

I currently have a java-spring boot based multi module gradle project in the following structure

  RootProjectDir
      SubProjectA
      SubProjectB
      SubProjectCommon

The build.gradle file of each one of projects is as below

RootProjectDir build.gradle

dependencies {
 compile project(":SubProjectA")
 compile project(":SubProjectB")
 compile project(":SubProjectCommon")
 testCompile('org.springframework.boot:spring-boot-starter-test')
}

SubProjectA build.gradle

dependencies {
 compile project(":SubProjectCommon")

}

SubProjectB build.gradle

dependencies {
 compile project(":SubProjectCommon")

}

SubProjectCommon build.gradle

dependencies {
 compile('org.springframework.boot:spring-boot-starter-actuator')
 compile('org.springframework.boot:spring-boot-starter-jdbc')
 compile('org.springframework.boot:spring-boot-starter-web')
 .....
 .....
}

When I execute the

gradle clean build

the build is failing during the compileTestJava phase of SubProjectA. SubProjectA tests have compile time dependency on classes in SubProjectCommon.

If I just execute the following

gradle :subProjectA compileTestJava

the build is successful again.

It is failing with the message that SubProjectCommon classes could not be resolved.

The strange thing is that in the IntelliJ IDEA it doesn't show any compilation issues for the SubProjectA test classes and test executes fine. Also when I just execute the

gradle clean test

everything works fine.

I even tried putting a testCompile dependency on SubProjectCommon in the SubProjectA build.gradle like this

SubProjectA build.gradle

 dependencies {
     compile project(":SubProjectCommon")
     testCompile project(":SubProjectCommon")

    }

but still doesn't work

PS:-I currently have written test cases only for SubProjectA classes.

IDEs do not honor module paths very nicely, especially Eclipse, so everything is usually included together, thus you do not get any path problems.

Gradle makes clean distinctions between different projects.

So if your classes were in the test folder, You may need to reference the test sets properly using the below:

 testCompile project(":SubProjectCommon").sourceSets.test.output

or

 compile project(":SubProjectCommon").sourceSets.test.output

depending on which sourceSet is using classes from the other project.

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