簡體   English   中英

Gradle任務來編譯Java和Groovy源

[英]Gradle task to compile Java and Groovy sources

我們正在使用gradle啟動一個新項目(我以前的所有項目都在Maven上),這是我使用gradle的初次經驗,下面是我的build.gradle文件,並嘗試使用任務compile javagroovy源代碼

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並且build\\classes\\main沒有編譯的類

有人可以幫我執行gradle任務來編譯javagroovy源代碼嗎?

Groovy插件的Gradle文檔描述了默認布局,如下所示。 如果可以選擇這樣做,則無需自定義編譯任務。

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.

```

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM