V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
rockyou12
V2EX  ›  Java

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

  •  
  •   rockyou12 · 2016-08-22 17:26:19 +08:00 · 13869 次点击
    这是一个创建于 2802 天前的主题,其中的信息可能已经有所发展或是发生改变。

    写了个 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'
    	}
    }
    
    4 条回复    2016-08-29 15:02:23 +08:00
    wahyd4
        1
    wahyd4  
       2016-08-22 17:40:28 +08:00   ❤️ 1
    添加个 gradle idea plugin 在 build.gradle 里面,然后执行 gradle idea 就好了。
    rockyou12
        2
    rockyou12  
    OP
       2016-08-22 17:47:09 +08:00
    确实是差 iml 文件,感谢 @wahyd4
    teemoer
        3
    teemoer  
       2016-08-29 13:49:10 +08:00
    @rockyou12 = = 帅哥你怎么解决的 贴一下 代码哇 我刚学习 gradle
    rockyou12
        4
    rockyou12  
    OP
       2016-08-29 15:02:23 +08:00
    @teemoer 一楼说得很清楚啊,其实我贴的 gradle 也没得错。
    1.在项目 build.gradle 加 apply plugin: 'idea'
    2.输入命令 gradle idea
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1542 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 23:59 · PVG 07:59 · LAX 16:59 · JFK 19:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.