Gradle任务来编译Java和Groovy源代码

时间:2017-04-15 22:39:46

标签: java maven gradle groovy

我们正在开始一个带有gradle的新项目(我以前的所有项目都在Maven上),这是我第一次使用gradle的经验,下面是我的build.gradle文件,我正在尝试编译{{1}使用任务java

的{}和groovy来源
compile

当我运行buildscript { ext { springBootVersion = '1.5.2.RELEASE' springVersion = '4.3.7.RELEASE' } repositories { mavenCentral() } dependencies { classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}") } } apply plugin: 'java' apply plugin: 'eclipse' apply plugin: 'groovy' apply plugin: 'org.springframework.boot' version = '0.0.1-SNAPSHOT' sourceCompatibility = 1.8 repositories { mavenCentral() } task compile(type: GroovyCompile) { //source = fileTree(dir: 'src', include: '**/*.java') sourceSets { main { java { srcDirs = [] } // no source dirs for the java compiler groovy { srcDir "src" } // compile everything in src/ with groovy } } destinationDir = file('build/classes/main') classpath = files('build/classes/main') } dependencies { compile "org.codehaus.groovy:groovy-all:2.4.10" compile('org.springframework.boot:spring-boot-starter-actuator:${springBootVersion}') compile('org.springframework.boot:spring-boot-actuator-docs:${springBootVersion}') compile('org.springframework.boot:spring-boot-starter-groovy-templates:${springBootVersion}') compile('org.springframework.boot:spring-boot-starter-jdbc:${springBootVersion}') compile('org.springframework.boot:spring-boot-starter-jersey:${springBootVersion}') compile('org.springframework.boot:spring-boot-starter-security:${springBootVersion}') compile('org.springframework.boot:spring-boot-starter-web:${springBootVersion}') compile('org.springframework:spring-webmvc:${springVersion}') compile "com.microsoft:sqljdbc4:4.0" testCompile('org.springframework.boot:spring-boot-starter-test:${springBootVersion}') } 命令时看到gradle compile并且:compile NO-SOURCE

中没有编译过的类

有人可以帮助我使用gradle任务来编译build\classes\mainjava来源吗?

1 个答案:

答案 0 :(得分:0)

Groovy插件的Gradle docs描述了默认布局,如下所示。如果它是一个坚持的选项,则不需要自定义编译任务。

src/main/java       Production Java source
src/main/resources  Production resources
src/main/groovy     Production Groovy sources. May also contain Java sources for joint compilation.
src/test/java       Test Java source
src/test/resources  Test resources
src/test/groovy     Test Groovy sources. May also contain Java sources for joint compilation.

```