Skip to content

Can’t pass parameters/sytem properties with gradlew command line

I try to pass parameters with gradlew command line, but can’t. I successfully pass the Optional parameter with XML file, but need have the possibility to pass with gradle CMD

Gradle task:

    task task1(type: Test) {
        useTestNG() {
            suites './src/test/resources/testng/task1.xml'


<!DOCTYPE suite SYSTEM "" >
<suite name="test1">

    <test name="test1">
        <parameter name="ipAmount" value="20"/>
            <class name="tests.traffic.Test1"/>



    @Test(testName = "Name", description = "description")
    public void createTrafficTest(
            @Optional("1") Integer ipAmount
        final String IP_AMOUNT_PARAMETER = System.getProperty("ipAmount");


gradle CMD:

    gradlew clean task1 -DipAmount=2 
    gradlew clean task1 -PipAmount=2 

In both cases I get the same result: ipAmount=20, IP_AMOUNT_PARAMETER = null

How to correctly pass parameters from the gradle cmd?


As explained also in the comment!

All you need to do is:

task task1(type: Test) {
        useTestNG() {
            suites './src/test/resources/testng/task1.xml'

Then you can pass the property using gradlew clean task1 -PipAmount=2

Finally the systemProperties is a map so you can add more variables like ["ipAmount", "anotherParam", "moreParam"]