Springboot工程打包部署和jenkins多分支部署

摘要 springboot打包部署,lib与jar分离, 多git部署流程

属于 :API 标签: springboot,jenkins 发布于:2021-07-13 20:32:15

springboot打包生成可执行jar

pom.xml

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins></build>


lib单独打包, 执行 java -jar target.jar -Dloader.path=/target/lib,/target/classes

layout:ZIP 很重要,否则 -Dloader.path参数可能不生效

上面的plugin
<plugin>
...
<configuration>
<mainClass>com.teen.BootApplication</mainClass>
<layout>ZIP</layout>
</configuration>
</plugin>


<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <id>copy-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>target/lib</outputDirectory>
                            <excludeTransitive>false</excludeTransitive>
                            <stripVersion>false</stripVersion>
                            <includeScope>runtime</includeScope>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

jar中lib排除

<plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <configuration>
                    <layout>ZIP</layout>
                    <includes>
                        <include>
                            <groupId>non-exists</groupId>
                            <artifactId>non-exists</artifactId>
                        </include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                        <configuration>
                            <classifier>classes</classifier>
                            <attach>false</attach>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

includes 包含哪些jar, 还有一种方法是excludeGroupIds, 然后用逗号分隔需要排除的jar的groupId


* jenkins多git部署

jenkins安装

Multiple SCMs

插件, 可以下载.hpi文件,然后离线安装。

source code Manage的时候,选择 multiple-scms

添加多个git, 注意要加上save to subfolder (保存到子文件夹中)

其他的步骤和单git打包操作相同。