내가 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]
을 나는 또한뿐만 아니라 작업 설명 이상으로 설정 속성 정보를 사용하는 작업을 설명해야 "프로젝트"작업에는 많은 반복과 관련없는 정보가 있기 때문에 "작업"작업이 필요하며, 여기에는 속성 설명도 추가됩니다. 누군가에게 도움이되기를 바랍니다.
포럼 질문에 대한 링크 : http : //forums.gradle.org/gradle/topics/how-to -document-project-properties-in-gradle –