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

打成 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值