上期回顾
java开发中常见的一些命令:
jar相关操作
maven相关
查看项目结构
mvn dependency:tree
例子如下:
可查看树结构:
[INFO] com.secusoft:bayonet:jar:0.0.1-20210826-SNAPSHOT
[INFO] +- org.springframework.boot:spring-boot-starter:jar:2.5.4:compile
[INFO] | +- org.springframework.boot:spring-boot:jar:2.5.4:compile
[INFO] | | \- org.springframework:spring-context:jar:5.3.9:compile
[INFO] | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.5.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-logging:jar:2.5.4:compile
[INFO] | | +- ch.qos.logback:logback-classic:jar:1.2.5:compile
[INFO] | | | \- ch.qos.logback:logback-core:jar:1.2.5:compile
[INFO] | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.14.1:compile
[INFO] | | | \- org.apache.logging.log4j:log4j-api:jar:2.14.1:compile
[INFO] | | \- org.slf4j:jul-to-slf4j:jar:1.7.32:compile
[INFO] | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | +- org.springframework:spring-core:jar:5.3.9:compile
[INFO] | | \- org.springframework:spring-jcl:jar:5.3.9:compile
[INFO] | \- org.yaml:snakeyaml:jar:1.28:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.5.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.5.4:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.12.4:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.12.4:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.12.4:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.5.4:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.52:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.52:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.52:compile
[INFO] | +- org.springframework:spring-web:jar:5.3.9:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.3.9:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.3.9:compile
[INFO] | \- org.springframework:spring-expression:jar:5.3.9:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.9.4:compile
[INFO] | +- commons-logging:commons-logging:jar:1.2:compile
[INFO] | \- commons-collections:commons-collections:jar:3.2.2:compile
[INFO] +- org.springframework.boot:spring-boot-starter-aop:jar:2.5.4:compile
[INFO] | +- org.springframework:spring-aop:jar:5.3.9:compile
[INFO] | \- org.aspectj:aspectjweaver:jar:1.9.7:compile
[INFO] +- com.aliyun.openservices:ons-client:jar:1.8.8.Final:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.32:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.20:compile (optional)
[INFO] +- org.springframework.boot:spring-boot-starter-test:jar:2.5.4:test
[INFO] | +- org.springframework.boot:spring-boot-test:jar:2.5.4:test
[INFO] | +- org.springframework.boot:spring-boot-test-autoconfigure:jar:2.5.4:test
[INFO] | +- com.jayway.jsonpath:json-path:jar:2.5.0:test
[INFO] | | \- net.minidev:json-smart:jar:2.4.7:test
[INFO] | | \- net.minidev:accessors-smart:jar:2.4.7:test
[INFO] | | \- org.ow2.asm:asm:jar:9.1:test
[INFO] | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:test
[INFO] | | \- jakarta.activation:jakarta.activation-api:jar:1.2.2:test
[INFO] | +- org.assertj:assertj-core:jar:3.19.0:test
[INFO] | +- org.hamcrest:hamcrest:jar:2.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter:jar:5.7.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-api:jar:5.7.2:test
[INFO] | | | +- org.apiguardian:apiguardian-api:jar:1.1.0:test
[INFO] | | | +- org.opentest4j:opentest4j:jar:1.2.0:test
[INFO] | | | \- org.junit.platform:junit-platform-commons:jar:1.7.2:test
[INFO] | | +- org.junit.jupiter:junit-jupiter-params:jar:5.7.2:test
[INFO] | | \- org.junit.jupiter:junit-jupiter-engine:jar:5.7.2:test
[INFO] | | \- org.junit.platform:junit-platform-engine:jar:1.7.2:test
[INFO] | +- org.mockito:mockito-core:jar:3.9.0:test
[INFO] | | +- net.bytebuddy:byte-buddy:jar:1.10.22:test
[INFO] | | +- net.bytebuddy:byte-buddy-agent:jar:1.10.22:test
[INFO] | | \- org.objenesis:objenesis:jar:3.2:test
[INFO] | +- org.mockito:mockito-junit-jupiter:jar:3.9.0:test
[INFO] | +- org.skyscreamer:jsonassert:jar:1.5.0:test
[INFO] | | \- com.vaadin.external.google:android-json:jar:0.0.20131108.vaadin1:test
[INFO] | +- org.springframework:spring-test:jar:5.3.9:test
[INFO] | \- org.xmlunit:xmlunit-core:jar:2.8.2:test
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.5.13:compile
[INFO] | +- org.apache.httpcomponents:httpcore:jar:4.4.14:compile
[INFO] | \- commons-codec:commons-codec:jar:1.15:compile
[INFO] +- com.aliyun.oss:aliyun-sdk-oss:jar:3.8.0:compile
[INFO] | +- org.jdom:jdom:jar:1.1:compile
[INFO] | +- org.codehaus.jettison:jettison:jar:1.1:compile
[INFO] | | \- stax:stax-api:jar:1.0.1:compile
[INFO] | +- com.aliyun:aliyun-java-sdk-core:jar:3.4.0:compile
[INFO] | +- com.aliyun:aliyun-java-sdk-ram:jar:3.0.0:compile
[INFO] | +- com.aliyun:aliyun-java-sdk-sts:jar:3.0.0:compile
[INFO] | \- com.aliyun:aliyun-java-sdk-ecs:jar:4.2.0:compile
[INFO] +- io.minio:minio:jar:8.3.0:compile
[INFO] | +- com.carrotsearch.thirdparty:simple-xml-safe:jar:2.7.1:compile
[INFO] | +- com.google.guava:guava:jar:30.0-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:3.5.0:compile
[INFO] | | +- com.google.errorprone:error_prone_annotations:jar:2.3.4:compile
[INFO] | | \- com.google.j2objc:j2objc-annotations:jar:1.3:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-annotations:jar:2.12.4:compile
[INFO] | +- com.fasterxml.jackson.core:jackson-core:jar:2.12.4:compile
[INFO] | \- com.fasterxml.jackson.core:jackson-databind:jar:2.12.4:compile
[INFO] \- com.squareup.okhttp3:okhttp:jar:4.8.1:compile
[INFO] +- com.squareup.okio:okio:jar:2.7.0:compile
[INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-common:jar:1.5.21:compile
[INFO] \- org.jetbrains.kotlin:kotlin-stdlib:jar:1.5.21:compile
[INFO] \- org.jetbrains:annotations:jar:13.0:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.317 s
[INFO] Finished at: 2021-10-01T08:24:16+08:00
[INFO] ------------------------------------------------------------------------
移除某个库中的某个依赖版本
<exclusions>
<exclusion>
<groupId>xx.xx.xx</groupId>
<artifactId>xx</artifactId>
</exclusion>
</exclusions>
例子:
在minio中移除okhttp依赖
<dependency>
<groupId>io.minio</groupId>
<artifactId>minio</artifactId>
<version>8.3.0</version>
<exclusions>
<exclusion>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</exclusion>
</exclusions>
</dependency>
maven下载过慢优化
使用阿里云的中央仓库:
在E:\maven\apache-maven-3.6.1\conf (你maven所在conf文件夹)标签后增加以下代码
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
maven 编译默认jdk 1.8
在E:\maven\apache-maven-3.6.1\conf (你maven所在conf文件夹)标签后增加以下代码
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</profile>
maven 更改下载保存的地方
maven仓库默认保存位为:
我们进行对应的更改。
<localRepository>E:\repository</localRepository>
去掉注释,最终配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<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>E:\repository</localRepository>
<pluginGroups>
</pluginGroups>
<proxies>
</proxies>
<servers>
</servers>
<mirrors>
<mirror>
<id>alimaven</id>
<name>aliyun maven</name>
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles>
<profile>
<id>jdk-1.8</id>
<activation>
<activeByDefault>true</activeByDefault>
<jdk>1.8</jdk>
</activation>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
</profile>
</profiles>
</settings>
如何跳过测试打包
有的时候我们打包的话,可能会比较慢。
不跳过测试打包。
命令:mvn package
用了16s
跳过测试打包。
只用了3s
方法一 使用mvn package -Dmaven.test.skip=true
命令
方法二 在idea中将test关闭也可以。
方法三 在pom文件中标签中增加
<skipTests>true</skipTests>
如图: