[Maven] Explore maven code by code

Maven项目构建流程解析
本文介绍了Maven作为基于生命周期的项目构建、部署和管理工具的工作原理。详细讲解了Maven如何通过plexus核心库加载类及配置,解析命令行参数,并通过MavenCli类执行项目的构建过程。

maven is life-cycle based project build, deploy and management tools.After you download and install maven fromApachesite, you use mvn plus option commands to manage your projects. In fact, following code is executed in linux system.

exec "$JAVACMD" \
  $MAVEN_OPTS \
  -classpath "${M2_HOME}"/boot/plexus-classworlds-*.jar \
  "-Dclassworlds.conf=${M2_HOME}/bin/m2.conf" \
  "-Dmaven.home=${M2_HOME}"  \
  ${CLASSWORLDS_LAUNCHER} "$@"
In maven, plexus project from codehaus is depended library. maven makes use of plexus'sclass-loaderandXMLparser tools.According to m2.conf, plexusclass-worldlaunchesorg.apache.maven.cli.MavenCli to do the whole work.

main is org.apache.maven.cli.MavenCli from plexus.core

set maven.home default ${user.home}/m2

[plexus.core]
optionally ${maven.home}/lib/ext/*.jar
load       ${maven.home}/lib/*.jar
MavenCli is an important class as it is the entry point for maven world. This class takes advantage of Apache common command line package and parse the argument from $@ into CommandLine object.

public class MavenCli {

public static int main( String  [] args, ClassWorld classWorld ){
 CLIManager cliManager = new CLIManager();
 CommandLine commandLine;
 commandLine = cliManager.parse( args );
}

}

After that, setting related to build are build up andMavenExecutionRequest and Maven instance are created.MavenExecutionRequest object is common java bean or JOPO which holds the information about the project like pom file name,ArtifactRepository, Goals and etc. class Maven is the man who carries out the build work further.

maven = createMavenInstance( settings.isInteractiveMode() );
maven.execute( request );
Maven class is glanced as below and some features are worthy of being highlighted.

  • RegisterEventDispatcher and Monitor;
  • Parse pom XML file usingorg.codehaus.plexus.util.xml.Xpp3Dom;
  • Use data from pom XML file to fill into Project and Model,Repository, Extension, Plugin objects;
  • Loop each project and callDefaultLifecycleExecutor to run each project.
List   projects = getProjects( request, globalProfileManager );
rm = new ReactorManager( projects );
MavenSession session = createSession( request, rm );
session.setUsingPOMsFromFilesystem( foundProjects );
lifecycleExecutor.execute( session, rm, dispatcher );

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值