有個時候多人多team協(xié)作開發(fā)過程中,會存在臨時修改的二方包,同樣版本需要重新拉取的情況。發(fā)現(xiàn)大部分人包括自己長久以來也是采用最原始的方法,一層層找到對應的目錄刪除對應的文件。某天實在是受不了了,寫了個小工具分享下,小代碼解決小問題。
外部依賴:fastjson,commons-io,commons-lang3,不要嘲笑,有工具干嘛不用呢,非得造輪子嗎。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
import com.alibaba.fastjson.json; import org.apache.commons.io.fileutils; import org.apache.commons.io.ioutils; import org.apache.commons.lang3.stringutils; import java.io.file; import java.io.ioexception; import java.nio.file.path; import java.nio.file.paths; import java.util.hashmap; import java.util.map; /** * @author tjw */ public class mavenlocalrepocleaner { /** * coordinatejson * { * "groupid1":"artifactid1:version1,artifactid2:version2...", * "groupid2":"artifactid:version,..." * } */ public static void main(string[] args) { string coordinatejson= "{" + "\"top.xbynet.xxx\":\"\"" + "}" ; map<string,string> coordinatemap=json.parseobject(coordinatejson,hashmap. class ); path m2repo= paths.get(system.getproperty( "user.home" ), ".m2" , "repository" ); coordinatemap.entryset().stream().foreach(v->{ string groupid=v.getkey(); groupid = groupid.replace( '.' , file.separatorchar); if (stringutils.isblank(v.getvalue())){ path dir = paths.get(m2repo.tostring(), groupid); try { fileutils.deletedirectory(dir.tofile()); } catch (ioexception e) { e.printstacktrace(); } } else { string[] artfactidvers = v.getvalue().split( "," ); for (string str : artfactidvers) { string ver = "" ; if (str.contains( ":" )) { ver = str.split( ":" )[ 1 ]; } string artfactid = str.split( ":" )[ 0 ]; path dir = paths.get(m2repo.tostring(), groupid, artfactid, ver); try { fileutils.deletedirectory(dir.tofile()); } catch (ioexception e) { e.printstacktrace(); } } } }); } } |
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持服務(wù)器之家。
原文鏈接:https://segmentfault.com/a/1190000015079332