mvn -Dmaven.test.skip=true -U clean install
mvn clean package -U
(强制拉一次)
mvn archetype:create-from-project
mvn archetype:generate -DarchetypeCatalog=local
mvn dependency:tree
mvn clean package -Dmaven.test.skip=true -Ptest
https://maven.apache.org/down...
maven-model-builder-3.6.0.jar/org/apache/maven/model
自己的classloader
所有自己的仓库配置
超级父pom
Linux .bash_profile
export M2_HOME=/Users/xx/tools/apache/apache-maven-3.6.0
配置setting.xml
<mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> <mirror> <id>ui</id> <mirrorOf>central</mirrorOf> <name>Human Readable Name for this Mirror.</name> <url>http://uk.maven.org/maven2/</url> </mirror> <mirror> <id>osc</id> <mirrorOf>central</mirrorOf> <url>http://maven.oschina.net/content/groups/public/</url> </mirror> <mirror> <id>osc_thirdparty</id> <mirrorOf>thirdparty</mirrorOf> <url>http://maven.oschina.net/content/repositories/thirdparty/</url> </mirror>
一般是域名反写
com.zzjson
功能命名
版本号
打包方式 默认是jar
只能出现在父pom
统一版本号
声明 (子POM里用到再引)
Type 默认jar
默认
编译(maven编译整个项目)
例如spring-core
测试
编译 例如 servlet,tomcat已经有了
打包不会打进去,相当于compile但是在打包阶段做了exclude操作
运行时 例如JDBC驱动实现
本地一些jar 例如短信jar
compile:编译依赖范围,在编译,测试,运行时都需要。
test: 测试依赖范围,测试时需要。编译和运行不需要。如Junit
runtime: 运行时依赖范围,测试和运行时需要。编译不需要。如JDBC驱动包
provided:已提供依赖范围,编译和测试时需要。运行时不需要。如servlet-api
system:系统依赖范围。本地依赖,不在maven中央仓库。
第一列表示直接依赖的scope,第一行表示间接依赖的scope
compile | test | provided | runtime | |
---|---|---|---|---|
compile | compile | - | - | runtime |
test | test | - | - | test |
provided | provided | - | provided | provided |
runtime | runtime | - | - | runtime |
mvn dependency:tree
如果都定义了版本,那么以最近的为准
最短路径原则
加载先后原则
排除包
clean 清理项目
pre-clean clean post-clean
lifecycle/phase/goal
1.A Build Lifecycle is Made Up of Phases
一个生命周期由多个phase组成的
2.A Build Phase is Made Up of Plugin Goals
一个phases是由多个goals组成的
生命周期运行会从前往后
1.0-SNAPSHOT
i. repository 删除
ii. mvn clean package -U
(强制拉一次)
主版本号.次版本号.增量版本号-<里程碑版本>
1.0.0-RELAESE
<plugins> <plugin> <artifactId>plugin</artifactId> <groupId>com.zzjson</groupId> <version>1.1</version> <configuration> <msg> ddd </msg> <list> <list> d </list> <list> d1 </list> </list> </configuration> <executions> <execution> <phase>package</phase> <goals> <goal>myplugin</goal> </goals> </execution> </executions> </plugin> </plugins>
<plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>versions-maven-plugin</artifactId> <version>2.3</version> </plugin>
http://www.mojohaus.org/versions-maven-plugin/index.html
mvn versions:set -DnewVersion=1.1-SNAPSHOT
<plugin> <artifactId>maven-source-plugin</artifactId> <version>2.3</version> <executions> <execution> <id>attach-sources</id> <phase>install</phase> <goals> <goal>jar-no-fork</goal> </goals> </execution> </executions> </plugin>
<plugin> <artifactId>maven-assembly-plugin</artifactId> <version>3.1.0</version> <configuration> <archive> <manifest> <mainClass>shuncom.dubbo.task.main.BootStrap</mainClass> </manifest> </archive> <descriptorRefs>jar-with-dependencies</descriptorRefs> </configuration> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
<plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>8080</port> <path>/</path> </configuration> </plugin>
<packaging>maven-plugin</packaging>
导入依赖
<dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> <version>3.5.0</version> </dependency> <dependency> <groupId>org.apache.maven.plugin-tools</groupId> <artifactId>maven-plugin-annotations</artifactId> <version>3.5</version> </dependency>
extends AbstractMojo
mvn install
参数传递
Profile
使用场景 dev/test/pro
setting.xml 家和公司两套
http://books.sonatype.com/nex...
http://lohost:8081/nexus (自带jetty)
admin/admin123
Type:
依赖jar包的方式
把group作为合集提供,挨个jar去仓库查找
本地的
三方的
阿里短信jar包
released
snapshosts
当maven dependce本地仓库没有找到,私服也没有,则去下载,从远端下载到私服
在pom.xml配置
<distributionManagement> <repository> <id>repo-mirrors</id> <name>center-repository</name> <url>http://uk.maven.org/maven2</url> </repository> <snapshotRepository> <id>repo-mirrors</id> <name>center-repository</name> <url>http://uk.maven.org/maven2</url> </snapshotRepository> </distributionManagement>
mvn deploy
也需要验证用户名密码,id需要和pom中一致
mvn archetype:create-from-project
cd /target/generated-sources/archetype
mvn install
b) 从archetype创建项目
mvn archetype:generate -DarchetypeCatalog=local
配置文件
<profiles> <profile> <id>dev</id> <properties> <profiles.active>dev</profiles.active> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> <profile> <id>prod</id> <properties> <profiles.active>prod</profiles.active> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> <profile> <id>test</id> <properties> <profiles.active>test</profiles.active> </properties> <activation> <activeByDefault>false</activeByDefault> </activation> </profile> </profiles>
<resources> <resource> <directory>${basedir}/src/main/resources</directory> <excludes> <exclude>conf/**</exclude> </excludes> </resource> <resource> <directory>src/main/resources/conf/${profiles.active}</directory> </resource> </resources>
代码,指定不同的环境
<profile> <id>ali</id> <repositories> <repository> <id>nexus</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>fail</checksumPolicy> </snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases> <enabled>true</enabled> <updatePolicy>always</updatePolicy> <checksumPolicy>warn</checksumPolicy> </releases> <snapshots> <enabled>true</enabled> <checksumPolicy>fail</checksumPolicy> <updatePolicy>always</updatePolicy> </snapshots> </pluginRepository> </pluginRepositories> </profile> <profile> <id>external</id> <repositories> <repository> <id>repo-mirrors</id> <url>http://uk.maven.org/maven2</url> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>plugin-repo-mirror</id> <url>http://uk.maven.org/maven2</url> </pluginRepository> </pluginRepositories> </profile>
mvn clean package -Dmaven.test.skip=true -Ptest
[root@snails ~]# wget http://download.sonatype.com/nexus/3/latest-unix.tar.gz
dependencyManagement使用能够帮助我们进行子项目的版本号管理
<dependencyManagement> <dependencies> <dependency> <groupId>com.zzjson.dubbo.order</groupId> <artifactId>order-api</artifactId> <version>1.0-SNAPSHOT</version> </dependency> </dependencies> </dependencyManagement>
版本会替换仓库中的jar
版本不会替换