我一直致力于Ant to Gradle迁移,我的主要构建过程正常运行,现在正在进行测试编译和执行阶段,但是我遇到了测试编译任务的问题。 testClasses任务执行时没有错误,但是没有生成.class文件,就像testCompileJava任务无法找到所需的源目录或输出目录一样。 build.gradle如下:
//Build for XXXXX.com
apply plugin: 'java'
apply from: 'build-properties.gradle'
tasks.withType(JavaCompile) {
sourceCompatibility = compile_source
targetCompatibility = compile_target
}
//SourceSets
sourceSets{
main{
java{
srcDir src_dir
}
}
test{
java{
srcDirs test_src_dir
}
output.classesDir test_dir
}
}
task generate_scripts(type: GradleBuild){
buildFile = 'build-db.gradle'
tasks = ['generate_scripts']
}
task test_init(type: GradleBuild){
buildFile = 'build-tests.gradle'
tasks = ['test_init']
}
task init_build{
description 'Initialises the build environment'
init_build.mustRunAfter clean
doFirst{
mkdir ( build_dir)
mkdir ( build_apps_dir)
mkdir ( build_classes_dir)
mkdir ( build_lib_dir)
mkdir ( build_lib_license_dir)
mkdir ( build_log_dir)
mkdir ( build_javadoc_dir)
}
doLast{
//Copy the web files (jsp, css images, web.xml, etc)
copy {
from ("${src_web_dir}/resources", exclude: '**/*.db' )
into build_dir }
copy {
from src_web_inf_dir
into build_web_inf_dir }
copy {
from config_dir + '/c3p0-config.xml'
into build_classes_dir }
copy {
from config_dir + '/ehcache.xml'
into build_classes_dir }
copy {
from config_dir + '/ESAPI.properties'
into build_classes_dir }
copy {
from config_dir + '/validation.properties'
into build_classes_dir }
copy {
from src_dir + '/com/XXXX/jnlp/servlet/resources/strings.properties'
into build_classes_dir + '/com/XXXX/jnlp/servlet/resources/' }
copy {
from lib_dir + '/font'
into build_classes_dir }
//= copy server dependencies
copy {
from lib_compile_dir
into build_lib_dir }
copy {
from lib_runtime_dir
into build_lib_dir }
// copy lib licenses
copy {
from lib_license_dir
into build_lib_license_dir}
}
}
task copyUpgradeScripts(dependsOn:[generate_scripts, init_build]){
// <!-- copy scripts to upgrade directories -->
doFirst{
copy{
from "${database_dir}/setup-data.sql"
into "${mssql_upgrade_dir}"
}
copy{
from ("${database_dir}/XXXXX-mssql-nodrop.sql")
{
rename
{
String fileName -> "${mssql_upgrade_dir}/XXXXX-nodrop.sql"
}
}
into "${mssql_upgrade_dir}"
}
}
//init_build.mustRunAfter generate_scripts
}
compileJava {
description 'Compile the source code'
source sourceSets.main.java
destinationDir = file(build_classes_dir)
options.debug = compile_debug
options.deprecation = compile_deprecation
classpath = compileJava.classpath
options.encoding = compile_encoding
//Copy application resources
doLast{
copy {
from config_dir
into build_classes_dir
}
//Copy hibernate xml files
copy {
from src_dir
include '**/*.hbm.xml'
into build_classes_dir
}
// Copy any image files
println 'Begin copy images'
copy {
from src_dir
include '**/*.png'
include '**/*.gif'
include '**/*.jpeg'
include '**/*.jpg'
into build_classes_dir
}
}
doLast{
delete "${build_classes_dir}/com/XXXX/jnlp/jardiff/resources"
}
}
compileJava.dependsOn init_build
//**Here lay the issue**//
compileTestJava{
compileTestJava.dependsOn(test_init,compileJava)
println "JAVAHOME" + System.getProperty( "java.home" )
source sourceSets.test.java.srcDirs
destinationDir = sourceSets.test.output.classesDir
options.debug = 'true'
options.deprecation = compile_deprecation
classpath = configurations.testCompile
options.encoding = compile_encoding
}
clean{
description 'Removes all generated files'
delete "${build_dir}"
delete "${dist_dir}"
delete "${test_dir}"
}
//Dependencies
dependencies{
compile fileTree(dir: lib_compile_dir, include: '*.jar')
compile fileTree(dir: lib_provided_dir, include: '*.jar')
compile fileTree(dir: lib_dir + '/compile-applet', include: '*.jar')
testCompile fileTree(dir:lib_test_dir, include:'*.jar')
testCompile fileTree(dir: lib_build_dir, include: '*.jar')
testCompile files(build_classes_dir)
testCompile configurations.compile
testRuntime configurations.compile
testRuntime fileTree(dir:lib_test_dir, include:'*.jar', exclude:'ant.jar')
testRuntime fileTree(dir: lib_build_dir, include: '*.jar', exclude:'ant.jar')
testRuntime files(build_classes_dir)
testRuntime fileTree(dir:lib_runtime_dir, include:'*.jar')
testRuntime files(test_dir)
testRuntime files(build_dir)
}
}