mvn -N io.takari:maven:wrapper -Dmaven=3.6.3
Guide to installing 3rd party JARs
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
pom.xml 文件 中 dependency 标记的 scope 属性解释:
compile,缺省值,适用于所有阶段,会随着项目一起发布。
provided,类似 compile,期望 JDK、容器或使用者会提供这个依赖。如 servlet.jar。
runtime,只在运行时使用,如 JDBC 驱动,适用运行和测试阶段。
test,只在测试时使用,用于编译和运行测试代码。不会随项目发布。
system,类似 provided,需要显式提供包含依赖的 jar,Maven 不会在 Repository 中查找它。
1 2 3 4 5 6 7 8
   |    <dependency>       <groupId>com.aqmd</groupId>       <artifactId>aqmd-netty</artifactId>       <version>2.0.1</version>       <scope>system</scope>       <systemPath>${project.basedir}/lib/aqmd-netty-2.0.1.jar</systemPath>   </dependency>
 
  | 
 
一键生成
1
   | mvn archetype:generate -DgroupId=com.lyloou.app -DartifactId=algs4 -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
   | 
 
多模块开发
nexus 安装
nexus2
【原创】Nexus 搭建 Maven 私服
https://help.sonatype.com/repomanager2/installing-and-running/running
注意访问网址是: http://localhost:8081/nexus/
学习建议:mvn 这个东西,就是难者不会,会者不难。基本上按照这样一个路线就问题不大,基本使用 => 了解继承/聚合 => 了解 jar 包冲突机制,并解决冲突 =>了解 mvn 的 3 个默认声明周期 ,生命周期的各个阶段 phase ,各个阶段的目标 goal => mvn 的插件开发 => Nexus 私服搭建及其使用。大致这样一个过程下来,就能非常熟悉 mvn,如果在稍微看看 mvn 的源码,大致看一看,基本上可以说是精通 mvn 了。
nexus3
https://help.sonatype.com/repomanager3/download/download-archives---repository-manager-3
1 2 3 4 5
   | docker volume create --name nexus-data docker run -d -p 8081:8081 --name nexus3 -v nexus-data:/nexus-data sonatype/nexus3
  docker volume inspect nexus-data
 
   | 
 
https://www.cnblogs.com/EasonJim/p/6858333.html
1 2 3 4 5
   | nexus.exe /install <optional-service-name>  nexus.exe /start <optional-service-name>  nexus.exe /stop <optional-service-name>  nexus.exe /uninstall <optional-service-name> 
 
   | 
 
设置 deploy 的地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
   |  <distributionManagement>     <repository>         <id>remote-nexus</id>          <name>Releases</name>         <url>http://localhost:8081/repository/maven-releases/</url>     </repository>     <snapshotRepository>         <id>remote-nexus</id>         <name>Snapshot</name>         <url>http://localhost:8081/repository/maven-snapshots/</url>     </snapshotRepository> </distributionManagement>
 
 
 
    <servers>     <server>       <id>local-nexus</id>       <username>admin</username>       <password>admin123</password>     </server>     <server>       <id>remote-nexus</id>       <username>name</username>       <password>password</password>     </server>   </servers>
 
 
  | 
 
当一个阶段通过 Maven 命令调用时,例如 mvn compile,只有该阶段之前以及包括该阶段在内的所有阶段会被执行。
不同的 maven 目标将根据打包的类型(JAR / WAR / EAR),被绑定到不同的 Maven 生命周期阶段。
maven 中三种 classpath
编译,测试,运行
1.compile:默认范围,编译测试运行都有效
2.provided:在编译和测试时有效
3.runtime:在测试和运行时有效
4.test:只在测试时有效
5.system:在编译和测试时有效,与本机系统关联,可移植性差
multiple conflict
maven 2 - SLF4J: Class path contains multiple SLF4J bindings - Stack Overflow
1 2 3 4 5 6
   | <exclusions>     <exclusion>         <groupId>org.slf4j</groupId>         <artifactId>slf4j-log4j12</artifactId>     </exclusion> </exclusions>
   | 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
   | <build>  <plugins>    <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-source-plugin</artifactId> <executions> 	<execution> 		<id>attach-sources</id> 		<goals> 			<goal>jar</goal> 		</goals> 	</execution> </executions>   </plugin> </plugins> </build>
 
   | 
 
1 2
   |  mvn help:describe -Dplugin=org.apache.maven.plugins:maven-source-plugin:2.1.1 -Ddetail
 
  | 
 
打包的时候,resource 中的文件没有打包进去
Apache Maven Resources Plugin – Filtering
其他镜像
maven 加速
将 maven 源改为国内阿里云镜像 - 知乎
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
   |  <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                       http://maven.apache.org/xsd/settings-1.0.0.xsd">   <localRepository/>   <interactiveMode/>   <usePluginRegistry/>   <offline/>   <pluginGroups/>   <servers/>   <mirrors>     <mirror>      <id>aliyunmaven</id>      <mirrorOf>central</mirrorOf>      <name>阿里云公共仓库</name>      <url>https://maven.aliyun.com/repository/central</url>     </mirror>     <mirror>       <id>repo1</id>       <mirrorOf>central</mirrorOf>       <name>central repo</name>       <url>http://repo1.maven.org/maven2/</url>     </mirror>     <mirror>      <id>aliyunmaven</id>      <mirrorOf>apache snapshots</mirrorOf>      <name>阿里云阿帕奇仓库</name>      <url>https://maven.aliyun.com/repository/apache-snapshots</url>     </mirror>   </mirrors>   <proxies/>   <activeProfiles/>   <profiles>     <profile>         <repositories>            <repository>                 <id>aliyunmaven</id>                 <name>aliyunmaven</name>                 <url>https://maven.aliyun.com/repository/public</url>                 <layout>default</layout>                 <releases>                         <enabled>true</enabled>                 </releases>                 <snapshots>                         <enabled>true</enabled>                 </snapshots>             </repository>             <repository>                 <id>MavenCentral</id>                 <url>http://repo1.maven.org/maven2/</url>             </repository>             <repository>                 <id>aliyunmavenApache</id>                 <url>https://maven.aliyun.com/repository/apache-snapshots</url>             </repository>         </repositories>      </profile>   </profiles> </settings>
 
  | 
 
idea 中调用 compile, package 时跳过测试
1 2 3 4 5 6
   | <properties>     <java.version>8</java.version>     <org.mapstruct.version>1.4.1.Final</org.mapstruct.version>          <maven.test.skip>true</maven.test.skip> </properties>
   | 
 
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
   | <profile>     <id>dev</id>     <activation>         <activeByDefault>true</activeByDefault>     </activation>     <properties>         <runtime.env>src/main/env/dev</runtime.env>         <final.name>webapp</final.name>     </properties>     <dependencies>         <dependency>             <groupId>com.eightqiu</groupId>             <artifactId>CodeCmns</artifactId>             <version>0.0.1-SNAPSHOT</version>         </dependency>     </dependencies> </profile> <profile>     <id>qa</id>     <properties>         <runtime.env>src/main/env/qa</runtime.env>         <final.name>webapp_${buildNumber}</final.name>     </properties>     <build>         <plugins>             <plugin>                 <groupId>org.codehaus.mojo</groupId>                 <artifactId>buildnumber-maven-plugin</artifactId>                 <version>1.1</version>                 <executions>                     <execution>                         <phase>validate</phase>                         <goals>                             <goal>create</goal>                         </goals>                     </execution>                 </executions>                 <configuration>                     <format>{0,date,yyyyMMdd}</format>                     <items>                         <item>timestamp</item>                     </items>                 </configuration>             </plugin>         </plugins>     </build>     <reporting>         <plugins>             <plugin>                 <groupId>org.apache.maven.plugins</groupId>                 <artifactId>maven-javadoc-plugin</artifactId>                 <version>2.8.1</version>             </plugin>         </plugins>     </reporting>     <dependencies>         <dependency>             <groupId>com.eightqiu</groupId>             <artifactId>CodeCmns</artifactId>             <version>0.0.1-SNAPSHOT</version>             <scope>provided</scope>         </dependency>     </dependencies> </profile> <profile>     <id>prod</id>     <properties>         <runtime.env>src/main/env/prod</runtime.env>         <final.name>webapp</final.name>     </properties>     <dependencies>         <dependency>             <groupId>com.eightqiu</groupId>             <artifactId>CodeCmns</artifactId>             <version>0.0.1-SNAPSHOT</version>             <scope>provided</scope>         </dependency>     </dependencies> </profile>
   | 
 
上传到 公网 maven repository
https://maven.apache.org/repository/guide-central-repository-upload.html
https://central.sonatype.org/pages/ossrh-guide.html
https://central.sonatype.org/pages/apache-maven.html
https://central.sonatype.org/publish/requirements/gpg
发布构件到 Maven 中央仓库 - 在风中的个人空间 - OSCHINA - 中文开源技术交流社区
mvn clean deploy -P release -Dgpg.passphrase=密码
mvn clean deploy -Pdeploy
How to Deploy only the sub-modules using maven deploy? - Stack Overflow
mvn deploy -pl SubModuleB