[英]How can I scan a maven repository?
我正在為eclipse開發一個代碼共享插件(用於學士論文項目)。
目前我正在嘗試掃描maven存儲庫並生成包列表。
我可以使用maven.model類下載和解析pom.xml,但我無法確定哪些maven類負責解析archetype-catalog.xml
有非maven解析器嗎?
我可以只掃描整個存儲庫樹中的pom.xml文件嗎?
編輯:我發現nexus索引器,但我不知道熱使用它:(
花了很長時間,但我終於找到了一個有效的例子
PlexusContainer plexus = new DefaultPlexusContainer(); NexusIndexer n = (NexusIndexer) plexus.lookup(NexusIndexer.class); IndexUpdater iu = (IndexUpdater) plexus.lookup(IndexUpdater.class); // DefaultNexusIndexer n = new DefaultNexusIndexer(); List indexCreators=new ArrayList(); // IndexingContext c = n.addIndexingContext("test", "test",new File( "/home/tomas/Desktop/test"),new File( "/home/tomas/Desktop/index"), "http://repository.jboss.org/", null); Directory tempIndexDirectory = new RAMDirectory(); // IndexCreator min = new MinimalArtifactInfoIndexCreator(); // MavenPluginArtifactInfoIndexCreator mavenPlugin = new MavenPluginArtifactInfoIndexCreator(); // MavenArchetypeArtifactInfoIndexCreator mavenArchetype = new MavenArchetypeArtifactInfoIndexCreator(); // JarFileContentsIndexCreator jar = new JarFileContentsIndexCreator(); // IndexCreator min = plexus.lookup( IndexCreator.class, MinimalArtifactInfoIndexCreator.ID ); IndexCreator mavenPlugin = plexus.lookup( IndexCreator.class, MavenPluginArtifactInfoIndexCreator.ID ); IndexCreator mavenArchetype = plexus.lookup( IndexCreator.class, MavenArchetypeArtifactInfoIndexCreator.ID ); IndexCreator jar = plexus.lookup( IndexCreator.class, JarFileContentsIndexCreator.ID ); indexCreators.add(min); indexCreators.add(mavenPlugin); indexCreators.add(mavenArchetype); indexCreators.add(jar); IndexingContext c = n.addIndexingContext( "temp", "test", new File("/home/tomas/Desktop/mavenTest"), tempIndexDirectory, "http://repository.jboss.org/maven2/", null, indexCreators ); IndexUpdateRequest ur=new IndexUpdateRequest(c); ur.setForceFullUpdate(true); iu.fetchAndUpdateIndex(ur); // for (String s : c.getAllGroups()) { // System.out.println(s); // } BooleanQuery q = new BooleanQuery(); q.add(n.constructQuery(ArtifactInfo.GROUP_ID, "*"), Occur.SHOULD); FlatSearchRequest request = new FlatSearchRequest(q); FlatSearchResponse response = n.searchFlat(request); for (ArtifactInfo a : response.getResults()) { String bUrl=url+a `enter code here`.groupId+"/"+a.artifactId+"/"+a.version+"/"; String fileName=a.artifactId+"-"+a.version; System.out.println(bUrl+fileName+"."+a.packaging); )}
為了將來參考, nexus-indexer
已經捐贈給Apache Foundation ,現在稱為maven-indexer
。 有一個github鏡像 ,該項目也在Apache Git頁面上列出
掃描我的本地存儲庫以獲取軟件包非常靈活。 在分享任何內容之前,我需要考慮大量重復的軟件包。 從昨天開始,我正在構建版本1.1.1-SNAPSHOT到我的存儲庫,今天我正在構建版本1.1.2-SNAPSHOT,兩個版本的目錄將共享相同的包。
現在,如果您想要顯示項目中使用的工件,您可以使用依賴項插件。 在maven項目開始時我最喜歡的兩個命令是:
mvn dependency:tree
和
mvn dependency:resolve
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.