0
如何解析maven文件名到工件和版本中?解析Maven文件名
的文件名看起來像這樣:
test-file-12.2.2-SNAPSHOT.jar
test-lookup-1.0.16.jar
我需要得到
test-file
12.2.2-SNAPSHOT
test-lookup
1.0.16
所以artifactId的是一個破折號和一個號碼和版本的第一個實例之前文本的文本在數字的第一個實例之後達到.jar。
我大概可以做到這一點與分裂和幾個循環和檢查,但它感覺應該有一個更簡單的方法。
編輯:
實際上,正則表達式並不複雜,因爲我想!
new File("test").eachFile() { file ->
String fileName = file.name[0..file.name.lastIndexOf('.') - 1]
//Split at the first instance of a dash and a number
def split = fileName.split("-[\\d]")
String artifactId = split[0]
String version = fileName.substring(artifactId.length() + 1, fileName.length())
println(artifactId)
println(version)
}
編輯2:嗯。它失敗上的例子,如本:
http://mvnrepository.com/artifact/org.xhtmlrenderer/core-renderer/R8
core-renderer-R8.jar
讓我想起了什麼,我需要做的。謝謝! – opticyclic 2014-11-03 21:40:22