【发布时间】:2014-04-17 14:54:36
【问题描述】:
我正在尝试在 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 { 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'
}
这是我在运行“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;
如果我将所有内容都制作成 Java,那么我不会遇到任何编译或执行错误。
【问题讨论】:
-
Groovy 测试代码的默认位置不是
test\main\groovy,而是src\test\groovy。 -
你的java代码应该在
src\main\java中,这是编译器(默认)的位置。如果你把它们放在别的地方,它们就不会被编译。 -
在不相关的说明中,为什么您要强制使用里程碑/发布(Spring Orm 4.0.0.RC1)候选者,而 Spring 4.0.2 已经发布(并被您的启动项目引用)。
-
Java 代码应该在
src\main\groovy,因为 OP 想要联合编译。src\main\java中的 Java 代码不会看到 Groovy 代码(除非重新配置)。 -
不,这不是问题所在。如果想要Java/Groovy 联合编译,Java 源代码必须传递给Groovy 编译器,并且不涉及
CompileJava任务。 (Java 插件仍然涉及,因为 Groovy 插件建立在它之上。不过,您不必显式应用 Java 插件,因为无论如何它都会被 Groovy 插件应用。)
标签: java groovy gradle spring-boot