简体   繁体   中英

The use Gradle properties in build.gradle

I read through this , official Gradle reference and migration guide , and I still cannot figure out why the following build script doesn't work.

apply plugin: 'java-library'

repositories {
    jcenter()
}

dependencies {
    testImplementation group: 'org.testng', name: 'testng', version: '6.14.3'    
}

def t_threads = test_threads

test {
    useTestNG() {
        setParallel('methods');
        setThreadCount(t_threads)
    }
    maxParallelForks = t_threads
}

task printProps {
        println test_threads
}

My gradle.properties file:

test_threads = 1

gradle printProps fails on the line setThreadCount(t_threads) with the exception: Could not find method setThreadCount() for arguments 1 on object of type org.gradle.api.tasks.testing.testng.TestNGOptions . If I change my code to def t_threads = 1 , then gradle printProps finishes without an error displaying 1 .

Answer is quite simple. setThreadCount expects Integer as a parameter, but property is a String , so all I had to do is convert String to Integer using test_threads as Integer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM