【问题标题】:Intellij-idea gradle sub-module keeps forgetting root project dependencyIntellij-idea gradle 子模块不断忘记根项目依赖
【发布时间】:2016-02-01 22:33:44
【问题描述】:

我有两个这样定义的 gradle 项目

apiclient(根) |源\ |构建.gradle |--- 安卓(模块) |源\ |构建.gradle

这些项目还没有在 maven 上,模块 apiclient.android 依赖于根模块 (apiclient)。

我一直在使用项目结构添加 apiclient...-> 依赖对话框,并且每当我在 gradle 工具窗口中单击刷新时,引用就会不断从 .iml 文件中删除。

如何防止子模块忘记父模块的依赖关系?

编辑:根据要求生成 build.gradle 文件。

apiclient build.gradle

group 'emby.apiclient'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.7

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'com.google.guava:guava:18.0'
    compile 'org.java-websocket:Java-WebSocket:1.3.0'
}

apiclient.android build.gradle

group 'emby.apiclient'
version '1.0-SNAPSHOT'

apply plugin: 'java'

sourceCompatibility = 1.7

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'org.codehaus.groovy:groovy-all:2.3.11'
    testCompile group: 'junit', name: 'junit', version: '4.11'
    compile 'com.google.code.gson:gson:2.5'
    compile 'com.mcxiaoke.volley:library:1.0.16'
    compile 'com.squareup.okhttp:okhttp:2.1.0'
    compile 'com.squareup.okhttp:okhttp-urlconnection:2.1.0'
    compile 'emby.apiclient:apiclient:1.0-SNAPSHOT'
}

最后一行 compile 'emby.apiclient:apiclient:1.0-SNAPSHOT' 在 gradle 项目窗口中带有红色下划线。我也试过compile project 'apiclient',结果没有改变。

settings.gradle

rootProject.name = 'apiclient'
include 'android'
findProject(':android')?.name = 'emby.apiclient.android'

【问题讨论】:

  • 你不是在 gradle 中管理依赖,你能显示你的 build.gradle 文件吗?
  • 更新了 build.gradle 文件。
  • 你需要在 settings.gradle 文件中包含你的子项目,让 gradle 现在它正在构建一个多项目构建
  • 两个项目都列在 settings.gradle 中。
  • appclient.android 是什么,是这样命名的文件夹吗?

标签: intellij-idea gradle


【解决方案1】:

在 /android build.gradle 文件中,您需要将compile project(":apiclient") 添加到您的依赖项列表中。我发现 IntelliJ 的“是否要向类路径添加依赖项”对话框仅将其添加到 .iml 文件中,该文件不作为构建的一部分运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 2015-11-11
    • 2018-03-06
    • 2013-11-17
    • 2014-02-10
    • 1970-01-01
    相关资源
    最近更新 更多