java - Gradle 多模块项目找不到模块依赖项

标签 java gradle

我正在尝试在 Intellij 中构建具有许多模块的简单 java 项目。

我有以下项目结构: project_structure

我的根项目build.gradle:

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

apply plugin: 'java'

sourceCompatibility = 1.8
repositories {
    mavenCentral()
}
dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

我的根项目settings.gradle:

rootProject.name = 'Foot'
include 'app'
include 'model'

和我的应用程序模块build.gradle:

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

apply plugin: 'java'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile project ':model'
}

当我刷新项目时,出现以下错误:

Error:(14, 0) Could not get unknown property ':model' for DefaultProjectDependency{dependencyProject='project ':app'', configuration='default'} of type org.gradle.api.internal.artifacts.dependencies.DefaultProjectDependency.
<a href="openFile:C:\Users\lukas\IdeaProjects\Foot\app\build.gradle">Open File</a>

我一直在寻找类似的问题,但他们的解决方案都不能解决我的问题。

当我离开的时候

dependencies {
testCompile group: 'junit', name: 'junit', version: '4.12'
compile project ':model'
}

在每个模块中build.gradle

我收到以下错误:

Error:(2, 0) Gradle DSL method not found: 'testCompile()'
Possible causes:<ul><li>The project 'Foot' may be using a version of the Android Gradle plug-in that does not contain the method (e.g. 'testCompile' was added in 1.1.0).
<a href="fixGradleElements">Upgrade plugin to version 2.3.0 and sync project</a></li><li>The project 'Foot' may be using a version of Gradle that does not contain the method.
<a href="open.wrapper.file">Open Gradle wrapper file</a></li><li>The build file may be missing a Gradle plugin.
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li>

最佳答案

你试过吗

compile project(path: ':model', configuration: 'compile')

而不是

compile project ':model'

关于java - Gradle 多模块项目找不到模块依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47738788/

相关文章:

java - assertTrue 语句需要在 intelliJ IDEA 中静态导入吗?

java - 如何检查jsp文件是否包含在另一个jsp文件中?

java - JDK 文档是语言规范的一部分吗?

java - Eclipse STS Gradle 插件依赖关系中断

android - 更新android studio后出现错误 "Minimum supported Gradle version is 5.1.1. Current version is 4.4.1"

android - com.android.build.api.transform.TransformException : java. util.zip.ZipException:构建 APK 时重复条目

java - 如何使用 FatJar (Gradle) 创建单个 jar

java - 通过强制转换调用 Animal 类的 methodS

java - Gradle命令行错误,任务 ':..:jar'的执行失败

android-studio - Android Studio 和 Gradle 同步中缺少模块