Using maven programmatically -


i need make small program downloads maven projects , prints dependencies

something this:

mavenartifactrepository repository = new mavenartifactrepository("typesafe", "http://repo.typesafe.com/typesafe/releases/", ..., ..., ...); downloadandprintdependencies(repository, "org.hsqldb", "hsqldb", "2.2.9");  void downloadandprintdependencies(repository, groupid, artifactid, version) {   mavenproject projectdescription = new mavenproject("org.hsqldb", "hsqldb", "2.2.9");   artifact artifact = repository.getproject(projectdescription);  // download artificat in local repository if necessary    list<dependency> dependecies = artifact.getdependencies();   ... } 

and, can execute goals on maven project, this:

string pomxmlfile = "/tmp/myproject/pom.xml"; reader reader = new filereader(pomxmlfile); mavenxpp3reader xpp3reader = new mavenxpp3reader(); model model = xpp3reader.read(reader);  projectartifact projectartifact = new projectartifact(model); projectartifact.clean(); projectartifact.install(); 

any feedback on pseudo-code?

what correct class , function fetches artifact repository?

what correct class , function executes goals (such clean , install) on maven projects?

the good

i have a project, naether, wrapper maven's dependency resolution lib aether.

using naether, can resolve dependencies

import com.tobedevoured.naether.api.naether; import com.tobedevoured.naether.impl.naetherimpl;  naether naether = new naetherimpl(); naether.adddependency( "ch.qos.logback:logback-classic:jar:0.9.29" ); naether.adddependency( "junit:junit:jar:4.8.2" ); naether.resolvedependencies(); system.out.println( naether.getdependenciesnotation().tostring() ); 

will output:

["ch.qos.logback:logback-core:jar:0.9.29",  "ch.qos.logback:logback-classic:jar:0.9.29",  "junit:junit:jar:4.8.2",  "org.slf4j:slf4j-api:jar:1.6.1" ] 

the bad

i have no idea how build (such compile source) pom.xml via java. have searched around little, have not found concrete example. projectartifact artifact descriptor maven uses resolve pom, such parent pom. not expose build actions. since there million ways build maven project, there no simple install method. have start lifecycle of install process somehow.

what naether can do, build project first , have naether install it:

import com.tobedevoured.naether.api.naether; import com.tobedevoured.naether.impl.naetherimpl;  naether naether = new naetherimpl(); naether.install( "com.example:sample:0.0.1", "/tmp/myproject/pom.xml", "/tmp/myproject/target/sample-0.0.1.jar" ) 

update - how fit together?

building, deploy, installing, etc project complicated. maven pretty job of simplifying it. though maven task install, there numerous steps involved work. simple java project, means populating class path, compiling source, packaging jar, , installing in local maven repository. things more complicated when talk other ways package java project, war.

the folk @ maven did hard work , spun off dependency resolution own library, aether. heavy lifting of working artifacts. aether lets figuring out dependencies project, download dependencies. aether lets install artifact locally or deploy remote repo.

what aether not manage project. not clean target dir or compile source.

what have created naether simplified way access aether.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -