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