我的Gradle脚本问题:在源集上找不到属性'groovy'

时间:2014-11-06 17:28:31

标签: groovy gradle build.gradle

自从我添加了自定义end2endTest任务后,我的Gradle构建脚本出现问题。

以下是与我的某个项目对应的构建脚本部分:

project("bignibou-server") {
    description = "Bignibou Server"

    configurations { querydslapt }

    apply plugin: 'groovy'
    apply plugin: 'spring-boot'

    dependencies {
        compile project(":bignibou-client")

        //Spring bootbignibou-server
        compile("org.springframework.boot:spring-boot-starter-actuator")
        compile("org.springframework.boot:spring-boot-starter-data-jpa")
        ...


        // Testing
        testCompile("org.springframework.boot:spring-boot-starter-test")
        testCompile("org.springframework.security:spring-security-test:${springSecurityVersion}")
        testCompile("org.mockito:mockito-core:${mockitoVersion}")
        testCompile("org.hamcrest:hamcrest-core:${hamcrestVersion}")
        testCompile("org.easytesting:fest-assert:${festVersion}")
        ...
    }

    springBoot { mainClassName = "com.bignibou.Application" }


    sourceSets {
        generated {
            java { srcDirs = [ 'build/generated-sources/java'
                ] } }

        main { java { srcDir 'build/generated-sources/java' } }

        integrationTest {
            java.srcDirs = ['src/it/java']
            resources.srcDir file('src/it/resources')
            compileClasspath = sourceSets.main.output + configurations.testRuntime
            runtimeClasspath = output + compileClasspath
        }

        end2endTest {
            java.srcDirs = []
            groovy.srcDirs = ['src/end2end/groovy']
            compileClasspath = sourceSets.main.output + configurations.testRuntime + sourceSets.integrationTest.output.classesDir
            runtimeClasspath = output + compileClasspath
        }
    }

    task generateQueryDSL(type: JavaCompile, group: 'build') {
        description "Generates the QueryDSL query types"
        source = sourceSets.main.java
        classpath = configurations.compile + configurations.querydslapt
        options.compilerArgs = [
            "-proc:only",
            "-processor",
            "com.mysema.query.apt.jpa.JPAAnnotationProcessor"
        ]
        destinationDir = sourceSets.generated.java.srcDirs.iterator().next()
    }

    task integrationTest(type: Test) {
        description "Run the integration tests."
        testClassesDir = sourceSets.integrationTest.output.classesDir
        classpath = sourceSets.integrationTest.runtimeClasspath
        reports.html.destination = file("$reports.html.destination/integration")
        reports.junitXml.destination = file("$reports.junitXml.destination/integration")
    }

    task end2endTest(type: Test) {
        description "Run the end2end tests."
        testClassesDir = sourceSets.end2endTest.output.classesDir
        classpath = sourceSets.end2endTest.runtimeClasspath + sourceSets.integrationTest.compileClasspath
        reports.html.destination = file("$reports.html.destination/end2end")
        reports.junitXml.destination = file("$reports.junitXml.destination/end2end")
    }


    compileJava {
        dependsOn generateQueryDSL
        source generateQueryDSL.destinationDir
    }

    compileGeneratedJava {
        dependsOn generateQueryDSL
        options.warnings = false
        classpath += sourceSets.main.runtimeClasspath
    }

    compileGroovy {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    end2endTest {
        doFirst {
            systemProperties['geb.build.reportsDir'] = 'build/geb-reports'
            systemProperties['geb.build.baseUrl'] = 'http://localhost:8080/'
        }
    }

    check.dependsOn integrationTest
    integrationTest.shouldRunAfter test
    end2endTest.shouldRunAfter integrationTest

    clean {
        delete sourceSets.generated.java.srcDirs
    }
}

当我运行gradle clean end2endTest

我得到以下内容:

* What went wrong:
A problem occurred evaluating root project 'bignibou'.
> Could not find property 'groovy' on source set 'end end test'.

我不确定为什么groovy插件找不到groovy属性..

有人可以帮忙吗?

编辑1 :以下是完整文件:gist here

编辑2 :这是失败的行:

groovy.srcDirs = ['src/end2end/groovy']

编辑3 :如果我注释掉compileClasspath变量的最后一部分(在end2end源集中),如下所示:

compileClasspath = sourceSets.main.output + configurations.testRuntime //+ sourceSets.integrationTest.output.classesDir

然后gradle构建更进一步,我得到编译错误。

我试图通过将sourceSets.integrationTest.output.classesDir添加到编译类路径来实现的目的是使end2end测试能够使用集成测试任务中的编译类。

那么如何从集成测试任务中添加生成的.class文件来编译end2end测试任务呢?

1 个答案:

答案 0 :(得分:0)

你尝试过语法吗?:

groovy { srcDirs = ['src/end2end/groovy'] }

但看看你在这里有什么:

  

sourceSets {           生成{               java {srcDirs = [' build / generated-sources / java'                   ]}}

在sourceSets中你只有java闭包,在这里你必须指定是使用java还是使用groovy编译源代码。问题可能是您必须将groovy添加到sourceSet,例如:

sourceSets {
  main {
    java { srcDirs = [] }    // no source dirs for the java compiler
    groovy { srcDirs = ['src/end2end/groovy'] }  // compile everything in src/ with groovy
    //noinspection GroovyAssignabilityCheck
    resources { srcDirs = ['src/resources']}
  }