在项目中遇到的 maven 插件常用的配置

来源:互联网 发布:淘宝网购物女装外套妮子风衣 编辑:程序博客网 时间:2024/04/25 22:36

打成 war 包时候,自动更改 war 包名字的配置

说明:在 maven 官网的 maven 插件那个网页找 war 插件就可以。
pom 代码:

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-war-plugin</artifactId>    <configuration>        <warName>yemao</warName>    </configuration></plugin>

编译指定编码插件

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-compiler-plugin</artifactId>    <configuration>        <source>${java.version}</source>        <target>${java.version}</target>        <encoding>${project.build.sourceEncoding}</encoding>    </configuration></plugin>

其中,属性列表为:

<properties>    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>    <maven.compiler.source>1.8</maven.compiler.source>    <maven.compiler.target>1.8</maven.compiler.target>    <java.version>1.8</java.version></properties>

将源代码进行打包的插件

以下插件将 jar-no-fork 这个目标绑定到了 depoly 这个阶段。

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-source-plugin</artifactId>    <executions>        <execution>            <id>attach-sources</id>            <phase>deploy</phase>            <goals>                <goal>jar-no-fork</goal>            </goals>        </execution>    </executions></plugin>

将文档也进行打包的插件

以下片段将 jar 这个目标绑定到了 deploy 这个阶段。
pom 文件代码片段:

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-javadoc-plugin</artifactId>    <executions>        <execution>            <id>attach-javadocs</id>            <phase>deploy</phase>            <goals>                <goal>jar</goal>            </goals>        </execution>    </executions></plugin>

发布到 nexus 服务器的插件

pom 文件代码:

<plugin>    <groupId>org.apache.maven.plugins</groupId>    <artifactId>maven-deploy-plugin</artifactId>    <executions>        <execution>            <id>deploy</id>            <phase>deploy</phase>            <goals>                <goal>deploy</goal>            </goals>        </execution>    </executions></plugin>

说明:还要配置一下发布的仓库。
pom 文件代码片段:

<distributionManagement>    <repository>        <id>(公司内部的 nexus 私服 id)</id>        <name>(公司内部的 nexus 私服 name)</name>    <url>(公司内部的 nexus 私服地址)</url>    </repository></distributionManagement>

部署源码、javadoc至nexus服务器。命令:mvn clean source:jar javadoc:jar deploy

0 0