Gradle 빌드 스크립트가 처음입니다 . 내 파일 시스템에 두 개의 속성 파일이 있습니다. 두 속성 파일의 모든 필드를 읽고 새 속성 파일에 쓰고 싶습니다. Gradle에서 이것을 달성하는 방법은 무엇입니까?
예를 들어, file1.properties 에는 다음이 포함됩니다.
name = John
age = 30
file2.properties 에는 다음이 포함됩니다.
gender = male
내 빌드 스크립트가 두 파일의 모든 필드를 읽고 다른 위치의 새 파일에 쓰고 싶습니다. 의 그 새 파일이 포함되어 있습니다 :
name = John
age = 30
gender = male
Gradle에서 수행하는 방법?
groovy에서이 간단한 스크립트를 시도 할 수 있습니다.
def targetFile = new File("<combinedFileWithPath>")
// Create directory structure of the target file before writing the file
targetFile.parentFile.mkdirs()
// Create target file using writer
targetFile.withWriter { w ->
// List of input files
["<firstFilePath>", "<secondFilePath", "<thirdFilePath>"].each { f ->
// Use reader on current file
new File(f).withReader { r ->
// Append data from each file to the writer of the combined file
w << r << "\n"
}
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다