2017-05-30 71 views
1

我正在將Java庫遷移到Gradle​​,我遇到了下面定義的集成任務的一些問題。Gradle 4.0-milestone2上的集成測試

這個任務讓我有兩種不同的源目錄src/testsrc/integration,並有獨立的gradle這個任務來運行它們,./gradlew test./gradlew integration

build.gradle

apply plugin: 'java-library' 
apply plugin: 'idea' 

apply from: './integration.gradle' 

targetCompatibility = '1.7' 
sourceCompatibility = '1.7' 

dependencies { 

    api 'com.github.ihsanbal:LoggingInterceptor:2.0.0' 
    api 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0' 
    api 'com.squareup.retrofit2:retrofit:2.0.2' 
    api 'com.squareup.retrofit2:converter-gson:2.0.2' 
    api 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 

    testImplementation 'junit:junit:4.12' 
} 

test { 
    testLogging.showStandardStreams = true 
} 


task copyTestResources(type: Copy) { 
    from sourceSets.test.resources 
    into sourceSets.test.output.classesDir 
} 
processTestResources.dependsOn copyTestResources 

integration.gradle

sourceSets { 
    integration { 
    java { 
     compileClasspath += main.output + test.output 
     runtimeClasspath += main.output + test.output 
     srcDir file('src/integration/java') 
    } 
    resources.srcDir file('src/integration/resources') 
    } 
} 
configurations { 
    integrationCompile.extendsFrom testCompile 
    integrationRuntime.extendsFrom testRuntime 
} 
idea { 
    module { 
    testSourceDirs += file('src/integration/java') 
    scopes.TEST.plus += [configurations.integrationCompile] 
    } 
} 
task integration(type: Test) { 
    testClassesDir = sourceSets.integration.output.classesDir 
    classpath = sourceSets.integration.runtimeClasspath 
} 

integration.mustRunAfter test 

內容內容有兩個問題與此配置。

1)copyTestResources任務不起作用classesDir已棄用且classesDirs不兼容。

2)類路徑不包括庫依賴關係。 編譯失敗完全以下錯誤

error: cannot find symbol 
error: package SOMETHING does not exist 

關於如何解決這個問題的任何線索?謝謝

回答

1

經過一些tips on the Gradle forum,我有它的工作。

build.gradle

apply plugin: 'java-library' 
apply plugin: 'idea' 

apply from: './integration.gradle' 

targetCompatibility = '1.7' 
sourceCompatibility = '1.7' 

dependencies { 

    api 'com.github.ihsanbal:LoggingInterceptor:2.0.0' 
    api 'com.squareup.okhttp3:okhttp-urlconnection:3.2.0' 
    api 'com.squareup.retrofit2:retrofit:2.0.2' 
    api 'com.squareup.retrofit2:converter-gson:2.0.2' 
    api 'com.squareup.retrofit2:adapter-rxjava:2.0.2' 

    testImplementation 'junit:junit:4.12' 
} 
test { 
    testLogging.showStandardStreams = true 
} 

integration.gradle

sourceSets { 
    integration { 
    java { 
     compileClasspath += main.output + test.output 
     runtimeClasspath += main.output + test.output 
     srcDir file('src/integration/java') 

     integration.runtimeClasspath += integration.output 
    } 
    resources.srcDir file('src/integration/resources') 
    } 
} 
configurations { 
    integrationImplementation.extendsFrom testImplementation 
    integrationRuntimeOnly.extendsFrom testRuntimeOnly 
} 
idea { 
    module { 
    testSourceDirs += file('src/integration/java') 
    scopes.TEST.plus += [configurations.integrationRuntimeClasspath, configurations.integrationCompileClasspath] 
    } 
} 
task integration(type: Test) { 
    testClassesDirs += sourceSets.integration.output.classesDirs 
    classpath = sourceSets.integration.runtimeClasspath 
} 
integration.mustRunAfter test 

仍需要弄清楚如何在IDE中運行它們,因爲它是目前沒有工作,但至少我可以再有CI。