用 idea 写 gradle 项目, ide 找不到依赖

2016-08-22 17:26:19 +08:00
 rockyou12

写了个 demo ,引了个 okhttp 的依赖,但 ide 里面老是红色报错说找不到,但 gradle build 却可以通过。 好烦啊 o(>< )o 什么提示都没有还不如记事本,不知道该怎么解决。

项目有两个子项目

root
|— backend
|— front

root 的 builde.gradle

buildscript {
    ext {
        springBootVersion = '1.4.0.RELEASE'
    }
    repositories {
        jcenter()
        maven { url "http://repo.spring.io/snapshot" }
        maven { url "http://repo.spring.io/milestone" }
        mavenCentral()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
    }
}

subprojects {
    apply plugin: 'spring-boot'
    apply plugin: 'java'
    apply plugin: 'eclipse'
    apply plugin: 'idea'

    repositories {
        jcenter()
        maven { url "http://repo.spring.io/snapshot" }
        maven { url "http://repo.spring.io/milestone" }
        mavenCentral()
    }

    dependencies {
        testCompile 'junit:junit:4.12'
        compile('org.springframework.boot:spring-boot-starter')
        compile("org.springframework.boot:spring-boot-starter-web")
        compile 'com.squareup.okhttp3:okhttp:3.4.1'
        compile 'org.mousio:etcd4j:2.12.0'
        testCompile('org.springframework.boot:spring-boot-starter-test')
    }

    version = '1.0'

    jar {
        manifest.attributes provider: 'gradle'
    }

}

子项目的 build.gradle

sourceCompatibility = 1.8
targetCompatibility = 1.8

jar {
	baseName = 'front'
	version = '0.0.1-SNAPSHOT'
}

eclipse {
	classpath {
		 containers.remove('org.eclipse.jdt.launching.JRE_CONTAINER')
		 containers 'org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8'
	}
}
13876 次点击
所在节点    Java
4 条回复
wahyd4
2016-08-22 17:40:28 +08:00
添加个 gradle idea plugin 在 build.gradle 里面,然后执行 gradle idea 就好了。
rockyou12
2016-08-22 17:47:09 +08:00
确实是差 iml 文件,感谢 @wahyd4
teemoer
2016-08-29 13:49:10 +08:00
@rockyou12 = = 帅哥你怎么解决的 贴一下 代码哇 我刚学习 gradle
rockyou12
2016-08-29 15:02:23 +08:00
@teemoer 一楼说得很清楚啊,其实我贴的 gradle 也没得错。
1.在项目 build.gradle 加 apply plugin: 'idea'
2.输入命令 gradle idea

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/301000

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX