如何使用gradle。 Java和Groovy一起? [英] How to use gradle. Java, and Groovy together?

查看:212
本文介绍了如何使用gradle。 Java和Groovy一起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在IntelliJ 13中使用一个Gradle项目,但我一直遇到以下问题:


  • Java文件不能请参阅Groovy文件
  • IntelliJ似乎忘记了Groovy并提示我为其配置GDK



<我读过groovy插件允许Groovy和Java在混合自己的源代码路径中,但Java想要它自己的。所以我有以下目录结构:


  • src\main\groovy

  • src\\ \\ main \java
  • src\test\groovy



Java和Groovy类



这是我的build.gradle:

  apply plugin:'java'
apply plugin:'groovy'
apply plugin:'eclipse'
apply plugin:'idea'
apply plugin:'spring-boot'
apply plugin:'jacoco'
apply plugin:'war'


buildscript {
repositories {
maven {urlhttp:/ /repo.spring.io/libs-snapshot}
mavenLocal()
}
依赖关系{
classpath(org.springframework.boot:spring-boot-gradle-plugin :1.0.0.RC4)
}
}

jar {
baseName ='my-app'
version ='0.1.0'
}

存储库{
mavenCentral()
maven {urlhttp://repo.spring .io / libs-snapshot}
}

依赖关系{
compile(org.springframework.boot:spring-boot-starter-web)
compile (org.springframework.boot:spring-boot-starter-data-jpa:1.0.0.RC4)
compile(org.springframework:spring-orm:4.0.0.RC1)
编译(org.hibernate:hibernate-entitymanager:4.2.1.Final)
编译(com.h2database:h2:1.3.172)
compile(joda-time:joda-时间:2.3)
compile(org.thymeleaf:thymeleaf-spring4)
compile(org.codehaus.groovy.modules.http-builder:http-builder:0.7.1)
compile('org.codehaus.groovy:groovy-all:2.2.1')

testCompile('org.spockframework:spock-core:0.7-groovy-2.0'){
exclude group:'org.codehaus.groovy',模块:'groovy-all'
}
testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+ ')
testCompile(junit:junit)
}

jacocoTestReport {
<! - 不确定这是否正确 - >
group =报告
description =运行测试后生成Jacoco覆盖报告。


任务包装器(类型:包装器){
gradleVersion ='1.11'
}

以下是我在运行 gradle clean build 时得到的构建错误:

  ... src / main / java / com / product / service / FileDownloadService.java:24:找不到符号
符号:class FileDownload
位置: class com.product.service.FileDownloadService

private FileDownload fileDownload;

如果我创建了所有Java,那么我不会收到任何编译或执行错误。

解决方案

尝试追加到文件build.gradle下一行

< pre $ sourceSets {
main {
java {srcDirs = []} //没有源代码用于java编译器
groovy {srcDirsrc} //在groovy $ s $ b中编译所有内容




对不起因为我的英语不好。我希望这可以帮助您解决问题。


I am trying to use a Gradle project in IntelliJ 13 but I keep running into issues such as:

  • Java files can't see Groovy files
  • IntelliJ seems to forget about Groovy and prompts me to configure a GDK for it

I read that the groovy plugin allows Groovy and Java in mixed own source path, but Java wants its own. So I have the following directory structure:

  • src\main\groovy
  • src\main\java
  • src\test\groovy

I have a mix of Java and Groovy classes

Here is my build.gradle:

apply plugin: 'java'
apply plugin: 'groovy'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'
apply plugin: 'jacoco'
apply plugin: 'war'


buildscript {
    repositories {
        maven { url "http://repo.spring.io/libs-snapshot" }
        mavenLocal()
    }
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.0.RC4")
    }
}

jar {
    baseName = 'my-app'
    version = '0.1.0'
}

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

dependencies {
    compile("org.springframework.boot:spring-boot-starter-web")
    compile("org.springframework.boot:spring-boot-starter-data-jpa:1.0.0.RC4")
    compile("org.springframework:spring-orm:4.0.0.RC1")
    compile("org.hibernate:hibernate-entitymanager:4.2.1.Final")
    compile("com.h2database:h2:1.3.172")
    compile("joda-time:joda-time:2.3")
    compile("org.thymeleaf:thymeleaf-spring4")
    compile("org.codehaus.groovy.modules.http-builder:http-builder:0.7.1")
    compile ('org.codehaus.groovy:groovy-all:2.2.1')

    testCompile('org.spockframework:spock-core:0.7-groovy-2.0') {
        exclude group: 'org.codehaus.groovy', module: 'groovy-all'
    }
    testCompile('org.codehaus.groovy.modules.http-builder:http-builder:0.7+')
    testCompile("junit:junit")
}

jacocoTestReport {
  <!-- not sure this is right  -->
    group = "Reporting"
    description = "Generate Jacoco coverage reports after running tests."
}

task wrapper(type: Wrapper) {
    gradleVersion = '1.11'
}

And here is a build error I get when I run "gradle clean build":

...src/main/java/com/product/service/FileDownloadService.java:24:  cannot find symbol 
symbol  : class FileDownload 
location: class com.product.service.FileDownloadService

private FileDownload fileDownload;

If I make everything Java, then I don't get any compile or execution errors.

解决方案

tries append to file "build.gradle" the next lines

sourceSets {
      main {
        java { srcDirs = [] }    // no source dirs for the java compiler
        groovy { srcDir "src" }  // compile everything in src/ with groovy
       }
    }

excuse me for my bad english. I hope that this can help your solution.

这篇关于如何使用gradle。 Java和Groovy一起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆