简体   繁体   English

Gradle CleanBuild期间Gradle compileTestJava失败

[英]Gradle compileTestJava fails during gradle clean build

I'm currently having this strange issue with gradle build. 我目前在gradle build中遇到这个奇怪的问题。 Below are the details. 以下是详细信息。

I currently have a java-spring boot based multi module gradle project in the following structure 我目前有以下结构的基于java-spring引导的多模块gradle项目

  RootProjectDir
      SubProjectA
      SubProjectB
      SubProjectCommon

The build.gradle file of each one of projects is as below 每个项目的build.gradle文件如下

RootProjectDir build.gradle RootProjectDir build.gradle

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

SubProjectA build.gradle SubProjectA build.gradle

dependencies {
 compile project(":SubProjectCommon")

}

SubProjectB build.gradle SubProjectB build.gradle

dependencies {
 compile project(":SubProjectCommon")

}

SubProjectCommon build.gradle 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 gradle干净的构建

the build is failing during the compileTestJava phase of SubProjectA. SubProjectA的compileTestJava阶段,构建失败。 SubProjectA tests have compile time dependency on classes in SubProjectCommon. SubProjectA测试对SubProjectCommon中的类具有编译时依赖性。

If I just execute the following 如果我只执行以下内容

gradle :subProjectA compileTestJava gradle:subProjectA compileTestJava

the build is successful again. 构建再次成功。

It is failing with the message that SubProjectCommon classes could not be resolved. 消息失败,提示无法解析SubProjectCommon类。

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. 奇怪的是,在IntelliJ IDEA中,它没有显示SubProjectA测试类的任何编译问题,并且测试执行正常。 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中将testCompile依赖项放在SubProjectCommon上

SubProjectA build.gradle 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. PS:-我目前只为SubProjectA类编写测试用例。

IDEs do not honor module paths very nicely, especially Eclipse, so everything is usually included together, thus you do not get any path problems. IDE不能很好地遵循模块路径,尤其是Eclipse,因此通常所有内容都包含在内,因此不会遇到任何路径问题。

Gradle makes clean distinctions between different projects. Gradle在不同项目之间进行了明确区分。

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. 取决于哪个sourceSet正在使用另一个项目中的类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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