mvn package -DskipTests和mvn package -Dmaven.test.skip有什么不同?

有目标就不怕路远。年轻人.无论你现在身在何方.重要的是你将要向何处去。只有明确的目标才能助你成功。没有目标的航船.任何方向的风对他来说都是逆风。因此,再遥远的旅程,只要有目标.就不怕路远。没有目标,哪来的劲头?一车尔尼雷夫斯基

导读:本篇文章讲解 mvn package -DskipTests和mvn package -Dmaven.test.skip有什么不同?,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

mvn package -DskipTests和mvn package -Dmaven.test.skip有什么不同?

-DskipTests 仅跳过测试,但是不跳过测试代码的编译

-Dmaven.test.skip 跳过测试,跳过编译测试代码(src/test/java里有编译错误可以顺利打包,前者不行!

注意:打出来的包都是一样的,test的资源都不会在jar包里!


从这两个代码的执行日志就可以看到区别,关键词 Tests are skipped.Not compiling test sourcesNot copying test resources

  • mvn package -DskipTests

    [INFO] Scanning for projects...
    [INFO] 
    [INFO] --------------------------< com.example:demo >--------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 1 source file to /Users/stonewang/dev/code2/demo/target/classes
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] skip non existing resourceDirectory /Users/stonewang/dev/code2/demo/src/test/resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 1 source file to /Users/stonewang/dev/code2/demo/target/test-classes
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
    [INFO] Tests are skipped.
    [INFO] 
    [INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ demo ---
    [INFO] Building jar: /Users/stonewang/dev/code2/demo/target/demo-0.0.1-SNAPSHOT.jar
    [INFO] 
    [INFO] --- spring-boot-maven-plugin:2.2.5.RELEASE:repackage (repackage) @ demo ---
    [INFO] Replacing main artifact with repackaged archive
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  3.225 s
    [INFO] Finished at: 2020-03-27T10:15:04+08:00
    [INFO] ------------------------------------------------------------------------
    
  • mvn package -Dmaven.test.skip

    [INFO] Scanning for projects...
    [INFO] 
    [INFO] --------------------------< com.example:demo >--------------------------
    [INFO] Building demo 0.0.1-SNAPSHOT
    [INFO] --------------------------------[ jar ]---------------------------------
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ demo ---
    [INFO] Using 'UTF-8' encoding to copy filtered resources.
    [INFO] Copying 1 resource
    [INFO] Copying 0 resource
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ demo ---
    [INFO] Changes detected - recompiling the module!
    [INFO] Compiling 1 source file to /Users/stonewang/dev/code2/demo/target/classes
    [INFO] 
    [INFO] --- maven-resources-plugin:3.1.0:testResources (default-testResources) @ demo ---
    [INFO] Not copying test resources
    [INFO] 
    [INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) @ demo ---
    [INFO] Not compiling test sources
    [INFO] 
    [INFO] --- maven-surefire-plugin:2.22.2:test (default-test) @ demo ---
    [INFO] Tests are skipped.
    [INFO] 
    [INFO] --- maven-jar-plugin:3.1.2:jar (default-jar) @ demo ---
    [INFO] Building jar: /Users/stonewang/dev/code2/demo/target/demo-0.0.1-SNAPSHOT.jar
    [INFO] 
    [INFO] --- spring-boot-maven-plugin:2.2.5.RELEASE:repackage (repackage) @ demo ---
    [INFO] Replacing main artifact with repackaged archive
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------
    [INFO] Total time:  2.495 s
    [INFO] Finished at: 2020-03-27T10:17:36+08:00
    [INFO] ------------------------------------------------------------------------
    

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/135270.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!