2014-05-24 2 views
3

내 앱에는 테스트 할 위치가 필요합니다. 이 속성은 시스템 속성을 통해 전달됩니다.명령 줄에서 내 앱에 gradle을 통해 시스템 속성 전달

명령 행에서 실행하는 경우

가 Gradle을이 값에 전달하지 않습니다 :

./gradlew -Dfoo=bar clean cucumber 

자바 코드 :

System.out.println("**foo(props):"+ System.getProperty("foo")); 

출력 : 내가했습니다

**foo(props):null 

here에 대한 몇 가지 문서를 본 적이 있지만, 내 gradled 스크립트에서 사용하려고하면 다음과 같은 오류가 발생합니다. R :

여기

Creating properties on demand (a.k.a. dynamic properties) has been deprecated and is scheduled to be removed in Gradle 2.0. Please read http://gradle.org/docs/current/dsl/org.gradle.api.plugins.ExtraPropertiesExtension.html for information on the replacement for dynamic properties.

Deprecated dynamic property: "systemProperties" on "task ':cucumber'", value: "{jna.platform.library....".

내 build.gradle의 조각입니다 :

task cucumber() { 
    dependsOn assemble, compileTestJava 
    doLast { 
     systemProperties = System.getProperties() 
     javaexec { 
      main = "cucumber.api.cli.Main" 
      classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output 
      args = ['-f', 'pretty', '--glue', 'steps', 'src/test/resources'] 
     } 
    } 
} 

당신은 어떻게 Gradle을 통해 응용 프로그램에 시스템 속성을 통과합니까?

답변

3

systemProperties 요구는 내부 javaexec 이동 :

task cucumber(type: JavaExec) { 
    dependsOn assemble, compileTestJava 
    main = "cucumber.api.cli.Main" 
    classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output 
    args = ['-f', 'pretty', '--glue', 'steps', 'src/test/resources'] 
    systemProperties = System.getProperties() 
} 

PS를 : 당신이 절대적 방법 (예를 들어, javaexec)를 통해 작업의 유형 (예를 들어, JavaExec) 항상 하나의 작업에 여러 문제를 결합 선호 필요하지 않는 한.

관련 문제