1. maven-jar-plugin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <classpathPrefix>my-lib/</classpathPrefix> <mainClass>com.demo.Hellow</mainClass> </manifest> </archive> <includes> <include>io/geekidea/springboot/**</include> </includes> </configuration> </plugin>
|
2. maven-dependency-plugin
将所有依赖包全部打到指定目录,结果为一个个的小包
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-dependency-plugin</artifactId> <version>2.10</version> <executions> <execution> <id>copy-dependencies</id> <phase>package</phase> <goals> <goal>copy-dependencies</goal> </goals> <configuration> <outputDirectory>${project.build.directory}/my-lib</outputDirectory> <excludeTransitive>false</excludeTransitive> <stripVersion>true</stripVersion> </configuration> </execution> </executions> </plugin>
|
3. maven-shade-plugin
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <executions> <execution> <id>shade-flink</id> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <relocations> <relocation> <pattern>org.apache.flume</pattern> <shadedPattern>com.shaded.org.apache.flume</shadedPattern> </relocation> <relocation> <pattern>org.apache.commons</pattern> <shadedPattern>com.shaded.org.apache.commons</shadedPattern> </relocation> </relocations> <artifactSet> <includes> <include>*:*</include> </includes> <excludes> <exclude>org.apache.flink:*</exclude> </excludes> </artifactSet> </configuration> </execution> </executions> </plugin> </plugins>
|
4. maven-assembly-plugin
assembly
配置分为两部分,一部分是 assembly
的配置文件,一部分是在 pom.xml
中的配置。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
| <assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd http://maven.apache.org/ASSEMBLY/2.0.0 ">
<id>assembly_test</id>
<formats> <format>tar.gz</format> <format>dir</format> <format>zip</format> </formats>
<dependencySets> <dependencySet> <outputDirectory>lib</outputDirectory> <useProjectArtifact>false</useProjectArtifact> <scope>runtime</scope> <excludes> <exclude>log4j:log4j</exclude> <exclude>org.slf4j:slf4j-log4j12</exclude> </excludes> </dependencySet> </dependencySets>
<fileSets> <fileSet> <directory>src/main/bin/</directory> <includes> <include>*.*</include> </includes> <excludes> <exclude>*.no_need</exclude> </excludes> <fileMode>0755</fileMode> <outputDirectory>bin</outputDirectory> <directoryMode>0755</directoryMode> </fileSet> </fileSets>
<files> <file> <source>pom.xml</source> <outputDirectory>.</outputDirectory> <fileMode>0755</fileMode> <destName>pom.xml</destName> </file> </files>
</assembly>
<plugins> <plugin>
<artifactId>maven-assembly-plugin</artifactId> <version>3.0.0</version> <finalName>${project.name}</finalName> <executions> <execution> <id>assembly_test</id> <phase>package</phase> <goals> <goal>single</goal> </goals> <configuration> <descriptors> <descriptor>src/main/assembly/assembly.xml</descriptor> </descriptors> </configuration> </execution> </executions> </plugin> </plugins>
|
打包成一个 jar, 使用命令 mvn clean package
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-assembly-plugin</artifactId> <version>2.5.5</version> <configuration> <archive> <manifest> <mainClass>x.x.x.Main</mainClass> </manifest> </archive> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> </configuration> <executions> <execution> <phase>clean</phase> </execution> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals> </execution> </executions> </plugin>
|
5. git-commit-id-plugin
将打包时的 git 信息生成文件在包中,官方文档地址
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| <plugin> <groupId>pl.project13.maven</groupId> <artifactId>git-commit-id-plugin</artifactId> <version>4.0.0</version> <executions> <execution> <id>get-the-git-infos</id> <goals> <goal>revision</goal> </goals> <phase>initialize</phase> </execution> <execution> <id>validate-the-git-infos</id> <goals> <goal>validateRevision</goal> </goals> <phase>package</phase> </execution> </executions> <configuration> <verbose>false</verbose> <generateGitPropertiesFile>true</generateGitPropertiesFile> <injectAllReactorProjects>false</injectAllReactorProjects> <offline>false</offline> </configuration> </plugin>
|
其他可选 <configuration>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
| <dotGitDirectory>${project.basedir}/.git</dotGitDirectory>
<prefix>git</prefix>
<dateFormat>yyyy-MM-dd'T'HH:mm:ssZ</dateFormat>
<dateFormatTimeZone>${user.timezone}</dateFormatTimeZone>
<generateGitPropertiesFilename>${project.build.outputDirectory}/git.properties</generateGitPropertiesFilename>
<format>properties</format>
<skipPoms>true</skipPoms>
<failOnNoGitDirectory>true</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>true</failOnUnableToExtractRepoInfo>
<skip>false</skip>
<runOnlyOnce>false</runOnlyOnce>
<excludeProperties> <excludeProperty>git.user.*</excludeProperty> </excludeProperties>
<includeOnlyProperties> <includeOnlyProperty>^git.commit.id.full$</includeOnlyProperty> </includeOnlyProperties>
<replacementProperties> <replacementProperty> <property>git.branch</property> <propertyOutputSuffix>something</propertyOutputSuffix> <token>^([^\/]*)\/([^\/]*)$</token> <value>$1-$2</value> <regex>true</regex> <forceValueEvaluation>false</forceValueEvaluation> <transformationRules> <transformationRule> <apply>BEFORE</apply> <action>UPPER_CASE</action> </transformationRule> <transformationRule> <apply>AFTER</apply> <action>LOWER_CASE</action> </transformationRule> </transformationRules> </replacementProperty> </replacementProperties>
<useNativeGit>false</useNativeGit>
<nativeGitTimeoutInMs>30000</nativeGitTimeoutInMs>
<abbrevLength>7</abbrevLength>
<commitIdGenerationMode>flat</commitIdGenerationMode>
<gitDescribe> <skip>false</skip> <always>true</always> <abbrev>7</abbrev> <dirty>-dirty</dirty> <match>*</match> <tags>false</tags> <forceLongFormat>false</forceLongFormat> </gitDescribe>
<validationProperties> <validationProperty> <name>validating project version</name> <value>${project.version}</value> <shouldMatchTo><![CDATA[^.*(?<!-SNAPSHOT)$]]></shouldMatchTo> </validationProperty> </validationProperties>
<validationShouldFailIfNoMatch>true</validationShouldFailIfNoMatch>
<evaluateOnCommit>HEAD</evaluateOnCommit>
<useBranchNameFromBuildEnvironment>true</useBranchNameFromBuildEnvironment>
<injectIntoSysProperties>true</injectIntoSysProperties>
|