【问题标题】:gradle.properties not taking values from command linegradle.properties 不从命令行获取值
【发布时间】:2019-12-05 12:52:34
【问题描述】:

我有 gradle.properties 文件,我正在从命令行传递值,如下所示,但不获取值。

gradle 测试 -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke

我的build.gradle文件代码如下-

import java.util.concurrent.TimeUnit
buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath "io.spring.gradle:dependency-management-plugin:1.0.3.RELEASE"
        classpath group: 'org.testng', name: 'testng', version: '6.8.+'
    }
}
plugins {
    id 'java'
}
apply plugin: 'java'
group 'org.csp.xxxx'
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
    mavenCentral()
}

test {

    systemProperty "RunnerApplication",System.getProperty("RunnerApplication")

    reports {
        junitXml.enabled = true
        html.enabled = true
        reports.junitXml.destination = file("test-output/reports/")
    }
    def Coregroups = System.getProperty('groups','Core-Smoke \n CSP-Smoke')
    useTestNG()
            {
                includeGroups Coregroups
                useDefaultListeners = true
                options.suites("src/test/java/TestAPISuite.xml")
                //options.listeners << 'com.ddddd.smsApi.qa.framework.listener.CustomListener'
                //options.listeners << 'com.dddd.smsApi.qa.framework.listener.EmailListener'
                options.listeners << 'org.uncommons.reportng.HTMLReporter'
                options.listeners << 'org.uncommons.reportng.JUnitXMLReporter'
                systemProperty 'org.uncommons.reportng.title', 'csp_api_automation_results'
            }
    testLogging.events "passed", "skipped", "failed"
    testLogging.exceptionFormat = "full"
    //Interceptors
    beforeTest { desc ->
        println "\n*** Starting execution of test ${desc.className}.${desc.name} ***"
    }
    afterTest { descriptor, result ->
        println "<<< Test ${descriptor.name} resulted in ${result.resultType} and took "+getElaspedTime(result.endTime - result.startTime)+" >>>\n"
    }
    //Modify the test logging
    testLogging {
        showStandardStreams = true
        exceptionFormat "full"
    }
}
sourceSets {
    main {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
    test {
        runtimeClasspath = files(output.resourcesDir) + runtimeClasspath
    }
}
dependencies {
    compile group: 'io.rest-assured', name: 'rest-assured', version: '3.0.2'
    testCompile group: 'org.testng', name: 'testng', version: '6.8.+'
    //An assertion library that is better than JUnit defaults
    testCompile 'org.easytesting:fest-assert-core:2.0M10'
    //Better reporting for testng.  It outputs a nice html report
    testCompile 'org.uncommons:reportng:1.1.4'
    compile group: 'org.apache.poi', name: 'poi-ooxml', version: '3.15'
    compile group: 'net.sourceforge.jexcelapi', name: 'jxl', version: '2.6.12'
    compile group: 'commons-lang', name: 'commons-lang', version: '2.6'
    compile group: 'com.googlecode.htmlcompressor', name: 'htmlcompressor', version: '1.5.2'
    compile group: 'commons-dbutils', name: 'commons-dbutils', version: '1.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.8.6'
    compile group: 'mysql', name: 'mysql-connector-java', version: '6.0.5'
    compile group: "com.github.fge", name: "json-schema-validator", version: "2.2.6"
    compile group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
    compile group: 'org.json', name: 'json', version: '20160810'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'com.google.code.guice-repository', name: 'guice-repository', version: '2.1.0'
    compile group: 'org.easytesting', name: 'fest-assert-core', version: '2.0M10'
    compile group: 'org.uncommons', name: 'reportng', version: '1.1.4'
    compile group: 'org.apache.commons', name: 'commons-csv', version: '1.5'
    compile group: 'org.apache.commons', name: 'commons-exec', version: '1.3'
    compile group: 'com.opencsv', name: 'opencsv', version: '4.1'
    compile group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.0'
    compile group: 'org.slf4j', name: 'slf4j-simple', version: '1.6.1'
    compile group: 'com.sun.mail', name: 'javax.mail', version: '1.6.0'
    compile group: 'javax.mail', name: 'javax.mail-api', version: '1.6.2'
    compileClasspath group: 'org.testng', name: 'testng', version: '6.8.+'
    // https://mvnrepository.com/artifact/com.cedarsoftware/json-io
    compile group: 'com.cedarsoftware', name: 'json-io', version: '2.6.0'
    // https://mvnrepository.com/artifact/org.apache.poi/poi
    compile group: 'org.apache.poi', name: 'poi', version: '3.17'
    // https://mvnrepository.com/artifact/com.aventstack/extentreports
    compile group: 'com.aventstack', name: 'extentreports', version: '4.0.9'
}
def getElaspedTime(def time) {
    if(time / 1000 < 1)
    {
        return String.format("0 min, %.3f sec", time/1000)
    }
    else
    {
        return String.format("%d min, %d sec",
                TimeUnit.MILLISECONDS.toMinutes(time),
                TimeUnit.MILLISECONDS.toSeconds(time) -
                        TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(time))
        )
    }
}

systemProp.RunnerApplication=dev 是保存在我的 gradle.properties 中的键和值。 这里我想以 RunnerApplication=QAEnv 运行,以便自动化可以在不同的环境中运行

但它总是在 dev 上运行,即使在命令行中传递 QAEnv。

非常感谢您的帮助。

【问题讨论】:

  • 您的问题有解决方案吗?因为我也是 gradle 的新手,并尝试了很多方法来解决我的问题。
  • 您能在 gmail 上取得联系以进一步讨论:baluzen@gmail.com 手机:8884479958
  • 是的,我已经解决了这个问题。有连接链接吗?
  • 没有,没有链接。您能否分享相同的内容,如果提供,请通过电话讨论相同的内容。
  • 你能否告诉我如何通过 gradle build 执行/运行黄瓜运行程序文件,就像我们通常使用 maven 一样,或者我们就像通常在 IntelliJ /eclipse 中运行 TestNGCucumberRunner.java 一样正确-单击它并成功运行。我的意图是在 gradle 中调用 TestNGCucumberRunner.java 并在 gradle 中调用所有功能,最后生成报告

标签: jenkins gradle command-line system-properties gradle-properties


【解决方案1】:

您正在传递两个系统属性。一个以systemProp. 为前缀,而另一个则没有。这应该向您表明其中一个是错误的。是前者:)

systemProp. 前缀可以使用,但仅在通过gradle.properties 文件声明系统属性时使用。在这里,您是从命令行声明它们。

所以而不是:

gradle test -DsystemProp.RunnerApplication=QAEnv -Dgroups=CSP-Smoke

运行:

gradle test -DRunnerApplication=QAEnv -Dgroups=CSP-Smoke

【讨论】:

  • 我使用了 gradle test -DRunnerApplication=QAEnv -Dgroups=CSP-Smoke,没用。仍然在 dev 而不是 QAEnv 上运行。 gradle.properties 还包含-systemProp.RunnerApplication=dev
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-12-20
  • 2015-09-20
  • 2014-01-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多