gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 06:19:57 26 4
gpt4 key购买 nike

自从我添加了自定义的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测试任务?

最佳答案

您是否尝试过语法?:

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

但是看看这里有什么:

sourceSets { generated { 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']}
}

关于groovy - 我的Gradle脚本出现问题:在源集上找不到属性 'groovy',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26785659/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com