使用Maven的assembly插件实现自定义打包

pom.xml增加以下内容:assembly

 

  <profiles>

        <profile>

            <id>dev</id>

            <properties>

                <env>dev</env>

            </properties>

            <activation>

            <!--     默认启用的环境配置 -->

                <activeByDefault>true</activeByDefault>

            </activation>

        </profile>

        <profile>

            <id>test</id>

            <properties>

                <env>test</env>

            </properties>

        </profile>

        <profile>

            <id>oa</id>

            <properties>

                <env>oa</env>

            </properties>

        </profile>

        <profile>

            <id>pre</id>

            <properties>

                <env>pre</env>

            </properties>

        </profile>

        <profile>

            <id>gray</id>

            <properties>

                <env>gray</env>

            </properties>

        </profile>

        <profile>

            <id>prod</id>

            <properties>

                <env>prod</env>

            </properties>

        </profile>

    </profiles> 

<build>

<!-- 主资源目录 -->

         <resources>

            <resource>

              <!--   设定主资源目录 -->

                <directory>src/main/resources</directory>

            </resource>

        </resources>

        <finalName>${project.artifactId}-${env}-${project.version}</finalName> 

<plugins>

 

  <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-jar-plugin</artifactId>

                <version>2.4</version>

                <configuration>

                    <excludes>

                        <exclude>**/*.properties</exclude>

                        <exclude>**/*.xml</exclude>

                    </excludes>

                </configuration>

            </plugin>

            

                <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-compiler-plugin</artifactId>

                <version>3.1</version>

                <configuration>

                    <showDeprecation>true</showDeprecation>

                    <showWarnings>true</showWarnings>

                    <source>1.8</source>

                    <target>1.8</target>

                    <testSource>1.8</testSource>

                    <testTarget>1.8</testTarget>

                </configuration>

            </plugin>

            

              <plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-surefire-plugin</artifactId>

                <version>2.18.1</version>

                <configuration>

                    <skipTests>true</skipTests>

                </configuration>

            </plugin>

<plugin>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-maven-plugin</artifactId>

</plugin>

<plugin>

                <groupId>org.apache.maven.plugins</groupId>

                <artifactId>maven-assembly-plugin</artifactId>

                <version>3.0.0</version>

                <configuration>

                   <!--  not append assembly id in release file name -->

                    <appendAssemblyId>false</appendAssemblyId>

                    <descriptors>

                        <descriptor>assembly/assembly.xml</descriptor>

                    </descriptors>

                </configuration>

 

                <executions>

                    <execution>

                        <id>make-assembly</id>

                        <phase>package</phase>

                        <goals>

                            <goal>single</goal>

                        </goals>

                    </execution>

                </executions>

            </plugin> 

 

 

</plugins>

</build>

 

 

 

 

在主文件夹下新建文件assembly,并增加以下文件assembly.xml:

内容:

<!-- - Copyright 1999-2011 Alibaba Group. - - Licensed under the Apache License,

Version 2.0 (the "License"); - you may not use this file except in compliance

with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0

- - Unless required by applicable law or agreed to in writing, software -

distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT

WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the

License for the specific language governing permissions and - limitations

under the License. -->

<assembly>

    <id>assembly</id>

    <formats>

        <format>tar.gz</format>

    </formats>

    <includeBaseDirectory>true</includeBaseDirectory>

    <fileSets>

 

        <fileSet>

            <directory>assembly/${env}/bin</directory>

            <outputDirectory>bin</outputDirectory>

            <fileMode>0755</fileMode>

        </fileSet>

        <fileSet>

            <directory>assembly/${env}/conf</directory>

            <outputDirectory>conf</outputDirectory>

            <fileMode>0644</fileMode>

        </fileSet>

        <fileSet>

            <directory>src/main/resources</directory>

            <outputDirectory>conf</outputDirectory>

            <fileMode>0644</fileMode>

            <excludes>

                <!-- 业务相关-->

                <exclude>testFiles/**/*</exclude>

                <!-- 系统相关-->

                <exclude>application.properties</exclude>

                <exclude>application-dev1.properties</exclude>

                <exclude>application-prod.properties</exclude>

                <exclude>application-test.properties</exclude>

                <exclude>application-dev.properties</exclude>

            </excludes>

        </fileSet>

    </fileSets>

    <dependencySets>

        <dependencySet>

            <outputDirectory>lib</outputDirectory>

            <!-- 去除框架相关jar包 -->

           <!--  <excludes>

                <exclude>com.alibaba:dubbo</exclude>

            </excludes> -->

        </dependencySet>

    </dependencySets>

</assembly>

 

转载于:https://my.oschina.net/u/2548090/blog/2253932

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值