您当前的位置: 首页 >  maven

liaowenxiong

暂无认证

  • 3浏览

    0关注

    1171博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Maven的maven-compiler-plugin插件详解

liaowenxiong 发布时间:2022-01-27 08:49:23 ,浏览量:3

文章目录
  • mvn compile
  • mvn test-compile
  • 编译插件的配置

mvn compile

mvn compile 命令会将 src/main/resources 下的资源文件复制到编译输出目录下;接着会将 src/main/java 目录下源代码编译输出到编译输出目录下。编译输出目录默认是 target/classes 目录。

打开命令终端,切换到 pom.xml 所在目录下,执行下面的命令:

[~/documents/IdeaProjects/demo02]$ mvn compile
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------------------------------
[INFO] Building demo02 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo02 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo02 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 1 source file to /Users/liaowenxiong/Documents/IdeaProjects/demo02/target/classes
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  3.094 s
[INFO] Finished at: 2022-01-27T08:25:03+08:00
[INFO] ------------------------------------------------------------------------

从上述的执行结果可以得知,执行 mvn compile 之后会先后调用 maven-resources-plugin 插件和 maven-compiler-plugin 插件,两个插件分别先后完成对应的任务。

mvn compile 也属于生命周期命令,默认不需要你在 pom.xml 文件中配置。

mvn test-compile

mvn compile 命令会将 src/test/resources 下的资源文件复制到编译输出目录下;接着会将 src/test/java 目录下源代码编译输出到编译输出目录下。这里的编译输出目录默认是 target/test-classes 目录。

打开命令终端,切换到 pom.xml 所在目录下,执行下面的命令:

[~/documents/IdeaProjects/demo02]$ mvn test-compile
[INFO] Scanning for projects...
[INFO] 
[INFO] --------------------------------------------------
[INFO] Building demo02 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ demo02 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 3 resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ demo02 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ demo02 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 1 resource
[INFO] 
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ demo02 ---
[INFO] Nothing to compile - all classes are up to date
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  1.755 s
[INFO] Finished at: 2022-01-27T08:53:47+08:00
[INFO] ------------------------------------------------------------------------

从上面的执行结果可以得知,执行 mvn test-compile 会去调用 maven-resources-plugin 插件和 maven-compiler-plugin,而且还分别调用了两次,说明执行 mvn test-compile 命令不仅会编译 src/test/ 目录下的源码文件还会编译 src/main 目录下的源码文件。

编译插件的配置

maven-compiler-plugin 指定编译源文件的 JDK 版本和项目的编码方式。


	
		 
            
              org.apache.maven.plugins 
              maven-compiler-plugin 
               
                  9.0.4 
                  9.0.4 
                  UTF-8 
               
            
		 
	

关注
打赏
1661566967
查看更多评论
立即登录/注册

微信扫码登录

0.0512s