How to programmatically call a Maven-task

前端 未结 4 1536
孤独总比滥情好
孤独总比滥情好 2021-02-05 08:34

I\'m using Maven in the context of another build-tool (leiningen for Clojure, but this should not matter), and I would like to know how I would call a plugin like dependency:bui

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-05 08:54

    Use the Maven Invoker API. Its quick and easy.

    InvocationRequest request = new DefaultInvocationRequest();
    request.setPomFile( new File( "/path/to/pom.xml" ) );
    request.setGoals( Collections.singletonList( "install" ) );
    
    Invoker invoker = new DefaultInvoker();
    invoker.setMavenHome(new File("/usr"));
    
    try
    {
      invoker.execute( request );
    }
    catch (MavenInvocationException e)
    {
      e.printStackTrace();
    }
    

    pom.xml:

    
        org.apache.maven.shared
        maven-invoker
        2.1.1
    
    

提交回复
热议问题