简体   繁体   English

子项目与Gradle的依赖项失败

[英]subprojects dependencies failure with Gradle

I'm struggling with Gradle and the build configuration of the following project structure (pretty simple...): 我正在努力与Gradle和以下项目结构的构建配置(非常简单...):

/projA
   /projB
   /projC

projC using classes from projB. projC使用来自projB的类。

In projA/settings.gradle: 在projA / settings.gradle中:

include 'projB'
include 'projC'

In projC/build.gradle: 在projC / build.gradle中:

dependencies{
 compile project(':projB')
}

In IntelliJ I have no problem of dependency resolution, but when I'm running a ./gradlew build in projA, I'm facing a compilation error: 在IntelliJ中,我没有依赖关系解析的问题,但是当我在projA中运行./gradlew构建时,遇到了编译错误:

ClassC: Unresolved reference: ClassB

(where ClassC is the class of projC which is failing on the use of ClassB which is a class from projB, obviously...) (其中ClassC是projC的类,显然使用ProB的类ClassB失败了……)

Notice that the code is in Kotlin language, that I do not have any problem to run the app in IntelliJ (spring boot run), but any build with Gradle give me an error (both in Intellij and command line). 请注意,代码是用Kotlin语言编写的,使用IntelliJ(春季启动运行)运行应用程序没有任何问题,但是任何使用Gradle进行的构建都会给我一个错误(在Intellij和命令行中)。

What am I missing? 我想念什么?

Regards, Adrien 问候,阿德里安

It's a common Gradle idiom to have an additional top level directory for your rootProject . Gradle惯用语是为rootProject附加一个顶层目录。 That's a special project that's the parent to all other projects in your build, in a multi-project build . 这是一个特殊项目,是多项目构建中构建中所有其他项目的父项目

That's where your settings.gradle file goes: 那是您的settings.gradle文件所在的位置:

include ':projA:projB'
include ':projA:projC'

Then, I'd recommend having projA as a subdirectory of your rootProject, so your hierarchy would look as follows: 然后,我建议将projA作为rootProject的子目录,这样您的层次结构将如下所示:

/myProject
  settings.gradle
  /projA
    build.gradle
    /projB
      build.gradle
    /projC
      build.gradle

Also, in projC/build.gradle , you'll want instead: 另外,在projC/build.gradle ,您将需要:

dependencies {
  compile project(':projA:projB')
}

That should do it. 那应该做。

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

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