Maven是Java项目的实时标准,掌握其使用技巧,可以提高工作效率
配置阿里巴巴源
settings.xml
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>
http://maven.aliyun.com/nexus/content/groups/public/
</url>
<mirrorOf>central</mirrorOf>
</mirror>
配置本地存储位置
settings.xml
<localRepository>E:\m2_repository</localRepository>
只发布子模块
<properties>
<maven.deploy.skip>true</maven.deploy.skip>
</properties>
因为子模块会继承属性,所以需要发布的模块就要修改为true
<properties>
<maven.deploy.skip>false</maven.deploy.skip>
</properties>
只编译子模块
mvn clean package -pl mybaits-util
只发布父Pom
maven deploy -N(不会发布子module)
分析Jar包使用情况
mvn dependency:analyze
[WARNING] Used undeclared dependencies found:
[WARNING] io.swagger:swagger-annotations:jar:1.5.20:provided
[WARNING] io.springfox:springfox-schema:jar:2.9.2:provided
[WARNING] io.springfox:springfox-swagger-common:jar:2.9.2:provided
[WARNING] io.springfox:springfox-spi:jar:2.9.2:provided
[WARNING] com.google.guava:guava:jar:27.0.1-jre:provided
[WARNING] com.fasterxml:classmate:jar:1.4.0:provided
[WARNING] io.springfox:springfox-core:jar:2.9.2:provided
[WARNING] Unused declared dependencies found:
[WARNING] io.springfox:springfox-swagger2:jar:2.9.2:provided
[WARNING] junit:junit:jar:4.12:compile
分析Jar包传递依赖
mvn dependency:tree -X
[INFO] +- org.reflections:reflections:jar:0.9.11:compile
[INFO] | +- com.google.guava:guava:jar:27.0.1-jre:compile
[INFO] | | +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] | | +- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] | | +- com.google.code.findbugs:jsr305:jar:3.0.2:compile
[INFO] | | +- org.checkerframework:checker-qual:jar:2.5.2:compile
[INFO] | | +- com.google.errorprone:error_prone_annotations:jar:2.2.0:compile
[INFO] | | +- com.google.j2objc:j2objc-annotations:jar:1.1:compile
[INFO] | | \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.17:compile
本地安装包
mvn install:install-file -Dfile=D:\projects\deep_learning\text-matching\text-matching-1.0-SNAPSHOT.jar -DgroupId=com.tenmao.dp -DartifactId=text-matching -Dversion=1.0-SNAPSHOT -Dpackaging=jar
maven helper插件
maven helper是Intellij IDEA必备插件,可以很方便的定位Jar包依赖关系和Jar包冲突