ToB企服应用市场:ToB评测及商务社交产业平台
标题:
Maven的常用插件
[打印本页]
作者:
愛在花開的季節
时间:
2024-9-1 18:31
标题:
Maven的常用插件
Apache Maven
Clean
Apache Maven Clean Plugin
清理编译期在如下目次内生成的文件。
project.build.directory
project.build.outputDirectory
project.build.testOutputDirectory
project.reporting.outputDirectory
Plugin Documentation
Usage
在下令行中执行如下下令:
mvn clean:clean
复制代码
或者
mvn clean
复制代码
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<executions>
<execution>
<id>auto-clean</id>
<phase>initialize</phase>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Dependency Information
代码仓库
Compiler
Apache Maven Compiler Plugin
对于Java项目来说,源码的默认路径为src/main/java,测试代码的默认路径为src/test/java。
Plugin Documentation
Usage
在下令行中执行如下下令:
mvn compile
复制代码
或者
mvn test-compile
复制代码
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Compiling Sources Using A Different JDK
Setting the -source and -target of the Java Compiler
修改pom.xml,增长如下配置:
<project>
[...]
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
[...]
</project>
复制代码
Setting the --release of the Java Compiler
使用Java 9及以后的版本编译、构建时,可以指定编译的版本号。
修改pom.xml,增长如下配置:
<project>
[...]
<properties>
<maven.compiler.release>8</maven.compiler.release>
</properties>
[...]
</project>
复制代码
Compile Using Memory Allocation Enhancements
修改pom.xml,增长如下配置,即使用单独的javac历程,初始内存指定为128MiB,最大内存指定为512MiB。
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<fork>true</fork>
<meminitial>128m</meminitial>
<maxmem>512m</maxmem>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
复制代码
Pass Compiler Arguments
修改pom.xml,增长如下配置:
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerArgs>
<arg>-verbose</arg>
<arg>-Xlint:all,-options,-path</arg>
</compilerArgs>
</configuration>
</plugin>
</plugins>
[...]
</build>
[...]
</project>
复制代码
相关参数,可以参考
javac
。
JAR
Apache Maven JAR Plugin
构建jar文件。
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<modelVersion>4.0.0</modelVersion>
<groupId>net.jackieathome.studio</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
WAR
Apache Maven WAR Plugin
构建war文件。
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<modelVersion>4.0.0</modelVersion>
<groupId>net.jackieathome.studio</groupId>
<artifactId>core</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.4.0</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Shade
Apache Maven Shade Plugin
构建uber jar文件。
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.6.0</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Assembly
Apache Maven Assembly Plugin
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.7.1</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Deploy
Apache Maven Deploy Plugin
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>3.1.3</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Frequently Asked Questions
代码仓库
Install
Apache Maven Install Plugin
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.3</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Resources
Apache Maven Resources Plugin
源码资源的默认路径为src/main/resources,测试代码的资源的默认路径为src/test/resources。
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Specifying a character encoding scheme
修改pom.xml,增长如下配置:
<project ...>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
...
</properties>
..
</project>
复制代码
Filtering
Filtering Properties Files
Including and excluding files and directories
Binary filtering
Surefire
Maven Surefire Plugin
执行单元测试代码。
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.0</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
Failsafe
Maven Failsafe Plugin
运行集成测试用例的插件。
Plugin Documentation
Usage
修改pom.xml,增长如下配置:
<project>
...
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.0</version>
</plugin>
...
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
...
</plugins>
</build>
...
</project>
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/)
Powered by Discuz! X3.4