How to get programmatically the highest version for a Maven artifact from my local repository? -
in many posts saw aether project helps in working artifact repositories. retrieve highest version specified groupid , artifactid only.
in aether wiki present case org.apache.maven:maven-profile:2.2.1 artifact specify version:
dependency dependency = new dependency( new defaultartifact("org.apache.maven:maven-profile:2.2.1"), "compile" );
but need version, highest version artifact. how this?
if can read pom.xml file, can bare xml parsing.
public static string getversionof(file pomfile) throws parserconfigurationexception, ioexception, saxexception { string version = ""; documentbuilderfactory dbfactory = documentbuilderfactory.newinstance(); documentbuilder dbuilder = dbfactory.newdocumentbuilder(); document doc = dbuilder.parse(pomfile); nodelist nodelist = doc.getelementsbytagname("project"); for(int = 0; < nodelist.getlength(); i++) { element node = (element) nodelist.item(i); version = node.getelementsbytagname("version").item(0).gettextcontent(); } return version; }
Comments
Post a Comment