10年 Java程序员,硬核人生!勇往直前,永不退缩!

欢迎围观我的git:https://github.com/R1310328554/spring_security_learn 寻找志同道合的有志于研究技术的朋友,关注本人微信公众号: 觉醒的码农,或Q群 165874185

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

maven日志观察

观察--- maven- 开头的行,可以看到打包的过程:
首先是 Scanning for projects...
然后下载一下 xx-maven-metadata.xml
 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ accr-service ---
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ accr-service ---
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ accr-service ---
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ accr-service ---
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ accr-service ---
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ accr-service ---
[INFO] --- spring-boot-maven-plugin:2.2.0.RELEASE:repackage (repackage) @ accr-service ---
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ accr-service ---
 
 
resources 是拷贝resources目录下的文件到 classes,他们不需要
compile 是编译src目录下的java文件(如果不是.java文件则直接拷贝)为class,同时放置到 classes
testResources 、testCompile 针对test 目录,具体类似,
test 是测试,不过,从日志来看, 是被skip了
jar 是打包为jar格式,默认名为: artifactId-version.jar,放置到 target目录
 
—— 前面几个的id (括号里面的是id )都是 default-阶段名 , 也就是maven自带的插件
repackage 是重新打包,也就是把原jar重命名为 xxx.jar.original,然后打一个fatjar,使用默认名
 
install 是Installing 其实就是拷贝 artifactId-version.jar、pom.xml(重命名为artifactId-version.pom) 到本地仓库对应目录 。
 
repackage 是重新打包,具体是怎么样打包的呢?repackage 是怎么绑定的呢? 得看源码,
 
 
"C:\Program Files\Java\jdk1.8.0_231\bin\java.exe" -Dmaven.multiModuleProjectDirectory=C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql "-Dmaven.home=C:\Program Files\JetBrains2\IntelliJ IDEA 2019.1.2\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains2\IntelliJ IDEA 2019.1.2\plugins\maven\lib\maven3\bin\m2.conf" "-javaagent:C:\Program Files\JetBrains2\IntelliJ IDEA 2019.1.2\lib\idea_rt.jar=50463:C:\Program Files\JetBrains2\IntelliJ IDEA 2019.1.2\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files\JetBrains2\IntelliJ IDEA 2019.1.2\plugins\maven\lib\maven3\boot\plexus-classworlds-2.5.2.jar" org.codehaus.classworlds.Launcher -Didea.version2019.1.2 install -P dev
[INFO] Scanning for projects...
Downloading: http://112.74.110.95:8081/repository/maven-public/com/forezp/sleuth/0.0.111-SNAPSHOT/maven-metadata.xml
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building accr-service 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
Downloading: http://112.74.110.95:8081/repository/maven-public/org/springframework/cloud/spring-cloud-starter-eureka/maven-metadata.xml
Downloading: http://112.74.110.95:8081/repository/maven-public/com/lk/testAuto-starter/0.0.1-SNAPSHOT/maven-metadata.xml
Downloading: http://112.74.110.95:8081/repository/maven-public/org/springframework/cloud/spring-cloud-starter-feign/maven-metadata.xml
Downloading: http://112.74.110.95:8081/repository/maven-public/org/springframework/cloud/spring-cloud-starter-hystrix/maven-metadata.xml
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ accr-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ accr-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 20 source files to C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\target\classes
[WARNING] /C:/Users/admin/Downloads/SpringCloudLearning-master/chapter-sleuth-mysql/accr-service/src/main/java/com/forezp/RedisConfig.java:[52,11] com.fasterxml.jackson.databind.ObjectMapper中的enableDefaultTyping(com.fasterxml.jackson.databind.ObjectMapper.DefaultTyping)已过时
[INFO] /C:/Users/admin/Downloads/SpringCloudLearning-master/chapter-sleuth-mysql/accr-service/src/main/java/com/forezp/RedisConfig.java: 某些输入文件使用了未经检查或不安全的操作。
[INFO] /C:/Users/admin/Downloads/SpringCloudLearning-master/chapter-sleuth-mysql/accr-service/src/main/java/com/forezp/RedisConfig.java: 有关详细信息, 请使用 -Xlint:unchecked 重新编译。
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ accr-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ accr-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ accr-service ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ accr-service ---
[INFO] Building jar: C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\target\accr-service-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.0.RELEASE:repackage (repackage) @ accr-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO]
[INFO] --- maven-install-plugin:2.5.2:install (default-install) @ accr-service ---
[INFO] Installing C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\target\accr-service-0.0.1-SNAPSHOT.jar to C:\Users\admin\.m2\repository\com\forezp\accr-service\0.0.1-SNAPSHOT\accr-service-0.0.1-SNAPSHOT.jar
[INFO] Installing C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\pom.xml to C:\Users\admin\.m2\repository\com\forezp\accr-service\0.0.1-SNAPSHOT\accr-service-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 34.641 s
[INFO] Finished at: 2021-02-15T10:34:32+08:00
[INFO] Final Memory: 60M/620M
[INFO] ------------------------------------------------------------------------
 
 
Changes detected - recompiling the module! —— 哪里有change?
 

我没有做任何代码的改动,为什么每次 都重新编译?

 
overwrite 也没用!
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<overwrite>true</overwrite>
</configuration>
</plugin>
 
 
[INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ accr-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ accr-service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ accr-service ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.5.1:testCompile (default-testCompile) @ accr-service ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ accr-service ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ accr-service ---
[INFO] Building jar: C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\target\accr-service-0.0.1-SNAPSHOT.jar
[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.0.RELEASE:repackage (repackage) @ accr-service ---
[INFO] Replacing main artifact with repackaged archive
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
 
为什么Copying x resources 两次?观察发现 分别是 properties、yml 文件,为什么它们没有任何改动都每次 拷贝?
 
 
加上这个: -Xpkginfo:always ? 试过, 无效!
 
 
This is a known problem in maven-compiler-plugin 3.1. It is being tracked in https://issues.apache.org/jira/browse/MCOMPILER-209 (the useIncrementalCompilation flag is broken).
The problem is unrelated to another 3.1 bug, https://issues.apache.org/jira/browse/MCOMPILER-205 (where files that do not produce .class outputs are always flagged as 'stale').
After testing further, going back to 3.0 did not actually fix the problem (it only works until the next mvn clean compile. However, as Michael Lemke suggests in comments, marking useIncrementalCompilation to false is a workable substitute; now, only the offending package gets recompiled each time (instead of the whole code-base).
 
 
结果发现是因为存在 全注释掉的 java文件,因为它们导致了每次,全部编译。。把它们改造为正常java文件就好了!
Because you have an empty java file (or all commented out) in the project that never compiles into a class file.
 
 
但是。没有文件改动还好,但是只要一个java 文件改动,则全部重新编译.. 也不太好!
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ accr-service ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 18 source files to C:\Users\admin\Downloads\Test-master\Lk-mysql\accr-service\target\classes
 
 
  • I was experiencing same issue with v3.7.0. This is the best answer. If you run mvn -X you will see: [DEBUG] useIncrementalCompilation enabled followed by ... [DEBUG] Stale source detected: ${filePath} and it was 2x empty source files in my project. BRILLIANT! – kevinarpe Apr 10 '18 at 11:36
 
后面发现这个是有用的:
<useIncrementalCompilation>false</useIncrementalCompilation
 
 
这样之后, 改动一个java,那就只有一次compile:
[INFO] --- maven-compiler-plugin:3.5.1:compile (default-compile) @ accr-service ---
[INFO] Compiling 1 source file to C:\Users\admin\Downloads\SpringCloudLearning-master\chapter-sleuth-mysql\accr-service\target\classes
 
最终:
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<staleMillis>1</staleMillis>
<useIncrementalCompilation>false</useIncrementalCompilation>
 
<compilerArgs>
<arg>-Xpkginfo:always</arg>
<!-- 过期的方法的警告-->
<arg>-Xlint:deprecation</arg>
</compilerArgs>
...
 
 
 
 
 
 

posted on 2021-02-20 06:31  CanntBelieve  阅读(1009)  评论(0编辑  收藏  举报