GKalnytskyi
GKalnytskyi

Reputation: 629

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.

Upvotes: 1

Views: 1655

Answers (1)

GKalnytskyi
GKalnytskyi

Reputation: 629

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.

Upvotes: 3

Related Questions