zoukankan      html  css  js  c++  java
  • maven: 我没有做任何代码的改动,为什么每次 都重新编译?

    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 FilesJavajdk1.8.0_231injava.exe" -Dmaven.multiModuleProjectDirectory=C:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysql "-Dmaven.home=C:Program FilesJetBrains2IntelliJ IDEA 2019.1.2pluginsmavenlibmaven3" "-Dclassworlds.conf=C:Program FilesJetBrains2IntelliJ IDEA 2019.1.2pluginsmavenlibmaven3inm2.conf" "-javaagent:C:Program FilesJetBrains2IntelliJ IDEA 2019.1.2libidea_rt.jar=50463:C:Program FilesJetBrains2IntelliJ IDEA 2019.1.2in" -Dfile.encoding=UTF-8 -classpath "C:Program FilesJetBrains2IntelliJ IDEA 2019.1.2pluginsmavenlibmaven3ootplexus-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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-service argetclasses
    [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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-servicesrc est esources
    [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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-service arget est-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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-service argetaccr-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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-service argetaccr-service-0.0.1-SNAPSHOT.jar to C:Usersadmin.m2 epositorycomforezpaccr-service.0.1-SNAPSHOTaccr-service-0.0.1-SNAPSHOT.jar
    [INFO] Installing C:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-servicepom.xml to C:Usersadmin.m2 epositorycomforezpaccr-service.0.1-SNAPSHOTaccr-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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-servicesrc est esources
    [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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-service argetaccr-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:UsersadminDownloadsTest-masterLk-mysqlaccr-service argetclasses
     
     
    • 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:UsersadminDownloadsSpringCloudLearning-masterchapter-sleuth-mysqlaccr-service argetclasses
     
    最终:
    <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>
    ...
     
     
     
     
     
     


    版权声明
    本文原创发表于 博客园,作者为 阿K .     本文欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则视为侵权。
    欢迎关注本人微信公众号:觉醒的码农,或者扫码进群:

  • 相关阅读:
    udhcpd配置及使用
    射频全网通笔记(附全球频段划分及主要运营商对应表)
    Source Insight教程
    关于学习
    一次OGG ERROR OGG-01091 Unable to open file "./dirdat/th079817" 的问题解决
    mysql建立的一个自动更新组织树案案例
    1055
    了解一个A*数据库的数据
    mysql安装
    通过CONTRAB 执行脚本进行监控
  • 原文地址:https://www.cnblogs.com/FlyAway2013/p/14418946.html
Copyright © 2011-2022 走看看