2014-09-26 2 views
4

예를 들어, 이름이 반대로 테스트 할 때 사용되는 DB 이라는 속성을 허용하고 사용할 수있는 gradle 파일이있는 경우gradle에서 프로젝트 속성을 문서화하는 방법은 무엇입니까?

gradle test

gradle test -PDB=asd1 특정 인스턴스에 대해 실행됩니다 몇 가지 기본에 대해 실행됩니다

하지만 특정 속성이 사용자 I로

처리되는 사용자에 대해 표시하는 쉬운 방법이 없습니다 gradle tasks 출력에서 ​​기대할 것입니다

예를 들어 advancedOptions과 같은 일부 작업을 정의하고 해당 작업의 출력에 나열해야합니까? 티?

답변

1

지금은 속성을 자체 문서화하는 좋은 방법이 없습니다. 그래도 좋은 질문입니다. 이 질문을 Gradle forum에 아이디어로 게시 하시겠습니까? 이것은 확실히 Gradle 코어에서 갖는 데 도움이 될만한 것입니다. 현재 사용자는 프로젝트의 문서에 의존해야합니다.

+0

포럼 질문에 대한 링크 : http : //forums.gradle.org/gradle/topics/how-to -document-project-properties-in-gradle –

0

나는 당신이 작업 rules를 사용할 수있다 (하지만 난 그게 gradle tasks) 어떻게 작동하는지 모르겠어요 또는 가능한 테스트 환경의 경우 목록을 준비하고 모든 위치에 대한 작업을 생성한다고 가정

의사 코드 :.

def envs = ['e1', 'e2', 'e3'] 

envs.each { e -> 
    projects.task(e) << { 
     //TODO 
    } 
} 

두 번째 생각은 모든 작업의 ​​목록을 인쇄합니다.

+0

나는이 방법을 시도해 봤지만, 각 작업에 대해 3-4 개의 인수를 가졌으며 때로는 긴밀하게 연결된 params가 없었습니다. 이 경우에는 depenendency가 수행 될 수 있지만 또 다른 고통이 있습니다. –

+0

예상되는 입출력을 갖춘 좋은 예를 준비하십시오. – Opal

+0

각각의 가능한 변형에 대해 별도의 작업을 추가하면 무의미한 대규모 작업 목록이 생성됩니다 (유지 보수 동안 엄청난 오버 헤드가 발생합니다). 나는 이것이 열려있는 질문이기 때문에 정말로 예제를 줄 수 없다 ... 나는 어떤 아이디어라도 주셔서 감사합니다. –

0

을 당신 수 "문서"그 작업에 대한 설명입니다.

task test { 
    description = "Does stuff against thing declared by property 'db'. Ex: gradle test -Ddb=foo' 
} 

그러면 gradle tasks을 실행할 때 작업 이름 옆에이 정보가 표시됩니다.

CLI를 통해 작업에 인수를 전달하는 또 다른 방법은 Gradle의 @Option 주석을 사용하는 것이지만이 방법은 변경할 수있는 내부 API입니다.

+0

작업 설명이 좋습니다. 예를 들어 모든 테스트 작업의 동작을 변경할 수있는 속성과 같은 교차 절단 속성의 경우 @Option을 살펴볼 것입니다. –

+0

전역 동작이있는 속성을 문서화하는 것은 약간 까다 롭습니다. 그런 것들은'gradle.properties' 파일에 배치하여 주석을 달 수 있습니다. –

+0

이러한 속성에는 모두 실행 가능한 기본값이 있습니다. gradle.properties가 VCS에 있습니다. 속성은 플러그인에 의해 처리됩니다. 나는 새로운 속성을 추가했기 때문에 모든 모듈 속성 파일을 업데이트하고 싶지 않습니다. –

2
내가 ANT에서 Gradle을에 와서 내 프로젝트는 자바를 기반으로하지 않는 말함으로써 시작해야한다, 그래서 나는 항상 최적의 Gradle을 나 그루비 방법으로 일을하고 있지 않다 가능성이

...

말했다 , 커맨드 라인 속성을 문서화하고 값과 함께 입력 된 것들의 유효성을 검사하기를 원했습니다 (특정 값 목록 만 허용 한 경우). 내 접근 방식은 가능한 값의 목록을 포함하는 개체에 가능한 명령 줄 속성의 맵을 갖는 것입니다. 첫 번째는 기본값이고 나머지는 허용되는 다른 값이므로 명령 줄에 설정된 속성의 유효성을 검사 할 수 있습니다. 이 개체에는 작업 설명 필드와 마찬가지로 속성을 문서화하는 데 사용하는 설명 필드도 있습니다. 명령 줄 속성을 자동으로 설정하는 것 외에도 명령 줄 속성의 유효성을 검사하고 사용자 지정 "설명"작업의 주요 작업 설명과 함께이 정보를 표시 할 수 있습니다 (도움이 예약되어 있으므로)

그래서

task setCommandLineDefaults() { 
    description 'set defaults for missing command line properties, and defines the possible values for each' 
    project.ext.cmdLineDefaults = [ 
     _platform: new CmdLineInfo(values:["ios", "googleplay", "kyowon", "k_ios", "fuhu", "air", "awe"], description: "k_ios is for kyowon on ios - we may want to use this prop for just the OS target and have the partnerID separate down the road...") 
     , _debug: new CmdLineInfo(values:["true", "false"], description:"if true, sets compiler-directives so that debug code (e.g., logging) can be excluded from the compiled code") 
     , _showStats: new CmdLineInfo(values:["true", "false"], description: "if not set on the command line, the setting of _debug is used for the default") 
     , _connect: new CmdLineInfo(values:["false", "true"], description: "only is relevant for DEBUG true, looks for an IP debug connection on startup if true") 
     , _buildType: new CmdLineInfo(values:["dev", "adhoc", "release"], description: "(adhoc is ios only)") 
     , _buildLevel: new CmdLineInfo(values:["", "alpha", "beta", "release"], description: "default is value in version.properties") 
     ... 
    ] 
    // create the 'documentation' text for the properties 
    project.ext.cmdLineInfo = "Command line info: this list comprises the only command line settings allowed, the first item in values is the default, if more than one, then those are the only valid values" 
    cmdLineDefaults.each() { prop, value -> 
     cmdLineInfo += "\n$prop: $value" 
    } 
    // verify that any command line properties set are expected 
    def cmdLineProps = cmdLineDefaults.keySet() as String[] 
    String errStr = "" 
    def alts 
    gradle.startParameter.projectProperties.each() { prop, value -> 
     def values = cmdLineDefaults[prop]?.values 
     if (!values) { 
      alts = getClosestStrings(cmdLineProps, prop, 3) // this uses fuzzy string comparison to get at most 3 of the properites the user might have intended 
      errStr += "Command line property '${prop}' not known, did you mean one of these? $alts \n" 
     } 
    } 
    if (errStr) { 
     throw new InvalidUserDataException("$errStr ${cmdLineInfo}") 
    } 
} 

: 여기에 몇 가지 예제 코드는 빌드 명령 줄 속성을 확인하기 시작할 때,이 명령 줄 속성 정보 및 실행을 설정 (간결하게, 나는 값 여기에 표시된 검사를하지 않아도됩니다) 명령 행 :

gradle compile -P_platfrm=ios

같은 오류 반환 :

task describe() {} 
describe << { 
    // tasks to leave out of description list (as I mentioned, my project is not Java, so a lot of built in stuff is not relevant) 
    def excludeTasks = ["buildDependents","buildNeeded","check","checkForFatalErrors","classes","compileJava","compileTestJava","jar","javadoc","processResources","processTestResources","test","testClasses"] 
    project.tasks.each { 
     if (it.description && !excludeTasks.contains(it.name)) { 
      println "task ${it.name}: ${it.description}" 
     } 
    } 
    println "\n${cmdLineInfo}" 
} 

난 그냥 이상이 더 좋아 : 다음

Command line property '_platfrm' not known, did you mean one of these? [_platform]

을 나는 또한뿐만 아니라 작업 설명 이상으로 설정 속성 정보를 사용하는 작업을 설명해야 "프로젝트"작업에는 많은 반복과 관련없는 정보가 있기 때문에 "작업"작업이 필요하며, 여기에는 속성 설명도 추가됩니다. 누군가에게 도움이되기를 바랍니다.

관련 문제