今天来讲讲Maven
的基本概念 - 新手村
首先看一条常用命令的执行输出
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn clean package -DskipTests
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hymvn 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ hymvn ---
[INFO] Deleting C:\idea\workspace\hymvn\target
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:resources (default-resources) @ hymvn ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\idea\workspace\hymvn\src\main\resources
[INFO] skip non existing resourceDirectory C:\idea\workspace\hymvn\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:compile (default-compile) @ hymvn ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to C:\idea\workspace\hymvn\target\classes
[INFO]
[INFO] --- maven-resources-plugin:3.0.1:testResources (default-testResources) @ hymvn ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\idea\workspace\hymvn\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.7.0:testCompile (default-testCompile) @ hymvn ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\idea\workspace\hymvn\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ hymvn ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.0.2:jar (default-jar) @ hymvn ---
[INFO] Building jar: C:\idea\workspace\hymvn\target\hymvn-1.0-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.0.2.RELEASE:repackage (default) @ hymvn ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.668 s
[INFO] Finished at: 2019-12-19T21:02:17+08:00
[INFO] Final Memory: 31M/237M
[INFO] ------------------------------------------------------------------------
sunyelw@windows:hymvn$
-
你知道输出的这一大串是什么东西吗?
-
[INFO] --- maven-clean-plugin:3.0.0:clean (default-clean) @ hymvn ---
这一行的意义是什么你清楚吗?
带着这些问题开始我们的探险.
一、基本概念
-
maven
自身的核心功能就是解析XML
文档、管理生命周期与插件 - 将主要的职责委派给一组
maven
插件执行,这些插件可以影响maven
的生命周期,提供对目标的访问
二、插件与目标
1. 插件<plugin
>
- 由一个或一组目标组成,供阶段
phase
<compile
/package
/install
/deploy
等> 调用
Plugins are artifacts that provide goals to Maven. (插件是为
Maven
提供功能的 构件 <artifacts
> )
举例
-
Compiler
插件, 负责编译成二进制文件 -
Jar
插件, 打一些可执行JAR
包
这些插件都是开源的,可以在
github
上找到源码
2. 目标<goal
>
-
maven
具体执行的任务,可以单独执行,也可以与其他目标组合执行 - 这些目标可以设置一些具体的参数,比如打包时是否跳过测试以减少打包时间(
-Dmaven.test.skip=true
/-DskipTests
)、编译时指定JDK
版本等
说到这里,可能还是不知道插件与目标是个什么玩意,还好Maven
提供了一个很有用的插件来让我们切身感受一下那个世界的样子~
三、help
插件详述
maven
插件列表中有一个特殊的插件,可以用于帮助获取一些有用的信息,这个插件的名字就叫 help
。
help
既然是一个插件,那么它也是由目标组成, 看看其有哪些目标
对于初学者来说最重要的一个目标就是
describe
, 通过这个目标可以获取其他的插件的用法(激动一会......)
我们用help
插件的describe
目标来描述它本身
mvn help:describe -Dplugin=help -Dgoal=describe -Ddetail
看看输出
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn help:describe -Dplugin=help -Dgoal=describe -Ddetail
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hymvn 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ hymvn ---
[INFO] Mojo: 'help:describe'
help:describe
Description: Displays a list of the attributes for a Maven Plugin and/or
goals (aka Mojo - Maven plain Old Java Object).
Implementation: org.apache.maven.plugins.help.DescribeMojo
Language: java
Available parameters:
artifactId
User property: artifactId
The Maven Plugin artifactId to describe.
Note: Should be used with groupId parameter.
cmd
User property: cmd
A Maven command like a single goal or a single phase following the Maven
command line:
mvn [options] [<goal(s)>] [<phase(s)>]
detail (Default: false)
User property: detail
This flag specifies that a detailed (verbose) list of goal (Mojo)
information should be given.
goal
User property: goal
The goal name of a Mojo to describe within the specified Maven Plugin. If
this parameter is specified, only the corresponding goal (Mojo) will be
described, rather than the whole Plugin.
groupId
User property: groupId
The Maven Plugin groupId to describe.
Note: Should be used with artifactId parameter.
minimal (Default: false)
User property: minimal
This flag specifies that a minimal list of goal (Mojo) information should
be given.
output
User property: output
Optional parameter to write the output of this help in a given file,
instead of writing to the console.
Note: Could be a relative path.
plugin
User property: plugin
The Maven Plugin to describe. This must be specified in one of three
ways:
1. plugin-prefix, i.e. 'help'
2. groupId:artifactId, i.e. 'org.apache.maven.plugins:maven-help-plugin'
3. groupId:artifactId:version, i.e.
'org.apache.maven.plugins:maven-help-plugin:2.0'
version
User property: version
The Maven Plugin version to describe.
Note: Should be used with groupId/artifactId parameters.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 6.392 s
[INFO] Finished at: 2019-12-19T21:20:39+08:00
[INFO] Final Memory: 17M/155M
[INFO] ------------------------------------------------------------------------
sunyelw@windows:hymvn$
-
-Dplugin=help
指定需要描述的插件名称,上面输出中给了-Dplugin
的三种写法 -
-Dgoal=describe
执行插件目标,不加会显示所有可用目标,help
插件共有 8 个目标 -
-Ddetail
是否显示详细插件使用信息,加了会显示具体如何使用及一些说明,不加就一个简单介绍
有了这个插件,其他插件的用法就都可以获知了,激动一会~
看下插件dependency
的tree
目标
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn help:describe -Dplugin=dependency -Dgoal=tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hymvn 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:describe (default-cli) @ hymvn ---
[INFO] Mojo: 'dependency:tree'
dependency:tree
Description: Displays the dependency tree for this project.
For more information, run 'mvn help:describe [...] -Ddetail'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.228 s
[INFO] Finished at: 2019-12-19T21:24:37+08:00
[INFO] Final Memory: 22M/220M
[INFO] ------------------------------------------------------------------------
sunyelw@windows:hymvn$
展示项目的依赖树,执行一下看看效果
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hymvn 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.0.2:tree (default-cli) @ hymvn ---
[INFO] com.hy.demo:hymvn:jar:1.0-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.0.2.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.0.2.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:2.0.2.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.0.2.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.0.2.RELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | | | +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | | | \- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.10.0:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.10.0:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.25:compile
[INFO] | | +- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] | | +- org.springframework:spring-core:jar:5.0.6.RELEASE:compile
[INFO] | | | \- org.springframework:spring-jcl:jar:5.0.6.RELEASE:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.19:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.0.2.RELEASE:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.9.5:compile
[INFO] | | | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.9.0:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-core:jar:2.9.5:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.9.5:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.9.5:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.9.5:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.0.2.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:8.5.31:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:8.5.31:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:8.5.31:compile
[INFO] | +- org.hibernate.validator:hibernate-validator:jar:6.0.9.Final:compile
[INFO] | | +- javax.validation:validation-api:jar:2.0.1.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.3.2.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.3.4:compile
[INFO] | +- org.springframework:spring-web:jar:5.0.6.RELEASE:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.0.6.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.0.6.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:5.0.6.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.0.6.RELEASE:compile
[INFO] +- org.springframework:spring-context-indexer:jar:5.0.6.RELEASE:compile (optional)
[INFO] \- org.springframework.boot:spring-boot-loader:jar:2.0.2.RELEASE:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 8.499 s
[INFO] Finished at: 2019-12-19T21:26:42+08:00
[INFO] Final Memory: 21M/228M
[INFO] ------------------------------------------------------------------------
sunyelw@windows:hymvn$
很好,完全符合预期效果~
然后我们会用插件了,但插件又是定义在哪的呢?
4. 插件来源
执行一个不存在的插件命令试试
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn 1:2
[INFO] Scanning for projects...
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-metadata.xml
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/mojo/maven-metadata.xml
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/sun/yelw/maven-metadata.xml
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-metadata.xml (9.7 kB at 4.5 kB/s)
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/mojo/maven-metadata.xml (21 kB at 9.5 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.839 s
[INFO] Finished at: 2019-12-19T21:28:18+08:00
[INFO] Final Memory: 22M/192M
[INFO] ------------------------------------------------------------------------
[ERROR] No plugin found for prefix '1' in the current project and in the plugin groups [com.sun.yelw, org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (F:\repository), alimaven (http://maven.aliyun.com/nexus/content/groups/public/)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException
sunyelw@windows:hymvn$
可以看到一个下载过程,说明如果本地插件库中没找到就会去配置好的远程仓库去下载,这里配的alimaven
的镜像,故输出如下:
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-metadata.xml
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/mojo/maven-metadata.xml
Downloading from alimaven: http://maven.aliyun.com/nexus/content/groups/public/com/sun/yelw/maven-metadata.xml
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/apache/maven/plugins/maven-metadata.xml (9.7 kB at 4.5 kB/s)
Downloaded from alimaven: http://maven.aliyun.com/nexus/content/groups/public/org/codehaus/mojo/maven-metadata.xml (21 kB at 9.5 kB/s)
中间的那个是用户级别的插件仓库,忽略
真正下载的就俩文件
org/apache/maven/maven-metadata.xml
org/codehaus/mojo/maven-metadata.xml
在本地仓库中找到这俩文件,打开来看下:
<plugin>
<prefix>dependency</prefix>
<artifactId>maven-dependency-plugin</artifactId>
<name>Apache Maven Dependency Plugin</name>
</plugin>
<plugin>
<prefix>deploy</prefix>
<artifactId>maven-deploy-plugin</artifactId>
<name>Apache Maven Deploy Plugin</name>
</plugin>
这里面配置的全是插件,我们上面执行的插件都能在里面找到。
还有一个东西挺好玩, 他的文件名会加上仓库的name
, 比如 alimaven
的就是 maven-metadata-alimaven.xml
- 如果从其他仓库下载过, 那么同级目录下还有其他名称的, 比如中央仓库的
maven-metadata-central.xml
上面报错还有一个地方需要注意
[ERROR] No plugin found for prefix '1' in the current project
and in the plugin groups
[com.sun.yelw, org.apache.maven.plugins, org.codehaus.mojo]
available from the repositories
[local (F:\repository),
alimaven (http://maven.aliyun.com/nexus/content/groups/public/)]
-> [Help 1]
- 插件都是配置在文件
maven-metadata-name.xml
[name
是仓库id
] -
mvn
命令的搜索范围 在com.sun.yelw
,org.apache.maven.plugins
,org.codehaus.mojo
这三个路径中的配置文件中(前面加上local-repository
的路径) - 后缀是 [
local
,alimaven
], 这里说明只有local
与alimaven
后缀的文件生效,也就说明当前只有一个alimaven
远程仓库生效
5. 生命周期<lifecycle
>
Maven
一共有三个生命周期
-
clean
进行真正的构建之前进行一些清理工作 -
default
构建的核心部分,编译,测试,打包,部署等 -
site
生成项目报告,站点,发布站点
这三套生命周期是独立的,是线性的,是互不影响的,详细参见完整生命周期的阶段组成
本地汇总了一张图
![](https://img.haomeiwen.com/i15085536/30c88b14240c16d6.png)
6. 一些错综复杂的关系
- 生命周期(
lifecycle
)- 阶段(
phase
) -
default
>package
/clean
>clean
/site
>site
- 阶段(
- 插件(
plugin
)- 目标(
goal
) -
help:effective-settings
/jar:jar
- 目标(
-
lifecycle
由一组phase
组成, 这些phase
是有顺序的 - 后面的
phase
依赖于前面的phase
,也就是说如果你运行了某个生命周期的某个阶段,那么此生命周期在这个阶段之前的阶段都会得到运行
注意不是之前的所有阶段都会运行,后文再细说
注意两点
-
phase
由一组目标组成, 有些目标(goal
)可以不执行(参数控制)
[INFO]
[INFO] --- maven-surefire-plugin:2.21.0:test (default-test) @ hymvn ---
[INFO] Tests are skipped.
[INFO]
-
phase
由一组目标组成, 这组目标的数量可以是0
, 比如下面的validate
就没有绑定任何目标
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn validate
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hymvn 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.899 s
[INFO] Finished at: 2019-12-19T21:48:48+08:00
[INFO] Final Memory: 10M/155M
[INFO] ------------------------------------------------------------------------
sunyelw@windows:hymvn$
是生命周期(
lifecycle
)的阶段(phase
)和插件(plugin
)的目标(goal
)相互绑定,以完成某个具体的构建任务
那么default
生命周期的其他阶段都没有绑定目标, 这些生命周期是否执行了呢?
官方文档中有一句话
Moreover, if a goal is bound to one or more build phases, that goal will be called in all those phases.
Furthermore, a build phase can also have zero or more goals bound to it.
If a build phase has no goals bound to it, that build phase will not execute.
But if it has one or more goals bound to it, it will execute all those goals.
- 如果一个目标被绑定到多个阶段, 那么所有阶段都会执行这个目标
- 如果一个阶段没有绑定任何目标, 那么此阶段不会被执行
- 如果一个阶段绑定了多个目标, 那么此阶段会执行所有目标
- 阶段是否绑定目标 取决于默认 (也可以自定义添加或创建)
A goal not bound to any build phase could be executed
outside of the build lifecycle by direct invocation.
- 可以在构建生命周期之外直接调用没有绑定到任何阶段的目标
7. packaging
属性的重要性
生命周期的阶段与目标的绑定关系 取决于 packaging
属性, 比如在 jar
模式下
<phases>
<process-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:resources
</process-resources>
<compile>
org.apache.maven.plugins:maven-compiler-plugin:3.1:compile
</compile>
<process-test-resources>
org.apache.maven.plugins:maven-resources-plugin:2.6:testResources
</process-test-resources>
<test-compile>
org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile
</test-compile>
<test>
org.apache.maven.plugins:maven-surefire-plugin:2.12.4:test
</test>
<package>
org.apache.maven.plugins:maven-jar-plugin:2.4:jar
</package>
<install>
org.apache.maven.plugins:maven-install-plugin:2.4:install
</install>
<deploy>
org.apache.maven.plugins:maven-deploy-plugin:2.7:deploy
</deploy>
</phases>
阶段 | 插件:目标 |
---|---|
process-resources |
resources:resources |
compile |
compiler:compile |
process-test-resources |
resources:testResources |
test-compile |
compiler:testCompile |
test |
surefire:test |
package |
ejb:ejb or ejb3:ejb3 or jar:jar or par:par or rar:rar or war:war
|
install |
install:install |
deploy |
deploy:deploy |
可以看到如果执行 package
会执行以下目标
resources
compile
testResources
testCompile
test
jar
install
跟 deploy
就是后面再加两个,详情请参见默认绑定配置
8. mvn
创建项目
mvn archetype:generate -DgroupId=com.hy.demo -DartifactId=hymvn -DarchetypeArtifactId=maven-archetype-quickstart -Dpackage=com.hy.demo -DinteractiveMode=false
-
archetype:generate
插件与目标的组合执行
9. mvn
命令报错定位
这里列几种我个人常用的方法,比较实用,当然要看问题具体类型。
- 检查配置文件,查看当前生效的配置
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn help:effective-settings
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building hymvn 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-help-plugin:2.2:effective-settings (default-cli) @ hymvn ---
[INFO]
Effective user-specific configuration settings:
<?xml version="1.0" encoding="UTF-8"?>
<!-- ====================================================================== -->
<!-- -->
<!-- Generated by Maven Help Plugin on 2019-12-19T10:19:16 -->
<!-- See: http://maven.apache.org/plugins/maven-help-plugin/ -->
<!-- -->
<!-- ====================================================================== -->
<!-- ====================================================================== -->
<!-- -->
<!-- Effective Settings for 'yello' on 'DESKTOP-S0L3088' -->
<!-- -->
<!-- ====================================================================== -->
<settings xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 http://maven.apache.org/xsd/settings-1.1.0.xsd">
<localRepository xmlns="http://maven.apache.org/SETTINGS/1.1.0">F:\repository</localRepository>
<mirrors xmlns="http://maven.apache.org/SETTINGS/1.1.0">
<mirror>
<mirrorOf>central</mirrorOf>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<id>alimaven</id>
</mirror>
</mirrors>
<pluginGroups xmlns="http://maven.apache.org/SETTINGS/1.1.0">
<pluginGroup>com.sun.yelw</pluginGroup>
<pluginGroup>org.apache.maven.plugins</pluginGroup>
<pluginGroup>org.codehaus.mojo</pluginGroup>
</pluginGroups>
</settings>
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.007 s
[INFO] Finished at: 2019-12-19T22:19:16+08:00
[INFO] Final Memory: 16M/155M
[INFO] ------------------------------------------------------------------------
sunyelw@windows:hymvn$
- 检查生效的
POM
设置,这里只是简单看下central
仓库配的地址
sunyelw@windows:hymvn$
sunyelw@windows:hymvn$ mvn help:effective-pom | grep 'central' -7
</dependency>
</dependencies>
<repositories>
<repository>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<releases>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<id>central</id>
<name>Central Repository</name>
<url>https://repo.maven.apache.org/maven2</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>C:\idea\workspace\hymvn\src\main\java</sourceDirectory>
<scriptSourceDirectory>C:\idea\workspace\hymvn\src\main\scripts</scriptSourceDirectory>
sunyelw@windows:hymvn$
发现一个依赖仓库,一个构件仓库,地址都是https://repo.maven.apache.org/maven2
- 还可以加
-X
参数查看运行过程,注意会特别多,拿打包举例
mvn clean package -DskipTests -X > mvn_package_x.log
下面列出部分内容
开头是Maven
的版本信息
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T15:58:13+08:00)
Maven home: E:\apache-maven-3.5.2
Java version: 1.8.0_151, vendor: Oracle Corporation
Java home: E:\Java\jdk1.8.0_151\jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
然后是一些导包
[DEBUG] Created new class realm maven.api
[DEBUG] Importing foreign packages into class realm maven.api
[DEBUG] Imported: javax.annotation.* < plexus.core
...
[DEBUG] Imported: org.slf4j.helpers.* < plexus.core
[DEBUG] Imported: org.slf4j.spi.* < plexus.core
下面有两行非常重要的信息
[DEBUG] Reading global settings from E:\apache-maven-3.5.2\conf\settings.xml
[DEBUG] Reading user settings from C:\Users\yello\.m2\settings.xml
最终生效的settings.xml
文件原来是由两个文件构成的,一个是用户目录${USER_HOME}\.m2\settings.xml
, 还有一个安装目录${M2_HOME}\conf\settings.xml
,所以如果你用户的设置文件没问题而又多了些配置时不妨考虑下安装目录下的配置。
还有很多信息
本地仓库地址
[DEBUG] Using local repository at F:\repository
镜像使用情况
[DEBUG] Using mirror alimaven (http://maven.aliyun.com/nexus/content/groups/public/) for central (https://repo.maven.apache.org/maven2).
执行计划
[DEBUG] === REACTOR BUILD PLAN ================================================
[DEBUG] Project: com.hy.demo:hymvn:jar:1.0-SNAPSHOT
[DEBUG] Tasks: [clean, package]
[DEBUG] Style: Regular
[DEBUG] =======================================================================
还有详细的执行过程与配置信息, 比如clean
[DEBUG] Goal: org.apache.maven.plugins:maven-clean-plugin:3.0.0:clean (default-clean)
[DEBUG] Style: Regular
[DEBUG] Configuration: <?xml version="1.0" encoding="UTF-8"?>
<configuration>
<directory default-value="${project.build.directory}"/>
<excludeDefaultDirectories default-value="false">${maven.clean.excludeDefaultDirectories}</excludeDefaultDirectories>
<failOnError default-value="true">${maven.clean.failOnError}</failOnError>
<followSymLinks default-value="false">${maven.clean.followSymLinks}</followSymLinks>
<outputDirectory default-value="${project.build.outputDirectory}"/>
<reportDirectory default-value="${project.build.outputDirectory}"/>
<retryOnError default-value="true">${maven.clean.retryOnError}</retryOnError>
<skip default-value="false">${maven.clean.skip}</skip>
<testOutputDirectory default-value="${project.build.testOutputDirectory}"/>
<verbose>${maven.clean.verbose}</verbose>
</configuration>
后面还有很多详细的输出,就不一一列举了。
现在你看到开篇的输出能解答出Maven
做了什么吗?
`
网友评论