先对父工程进行 mvn clean
再对子工程执行 install wagon:upload-single wagon:sshexec
使用wagon前提:
本地maven 的settings.xml 中加入如下配置,配置ssh主机用户名密码
<servers>
<server>
<id>linux-server-dev</id>
<username>root</username>
<password>123456</password>
</server>
</servers>
本地需要打包的maven工程的pom中加入如下配置:
<build> <extensions> <extension> <groupId>org.apache.maven.wagon</groupId> <artifactId>wagon-ssh</artifactId> <version>2.8</version> </extension> </extensions> <finalName>ayzfm8111</finalName> <plugins> <!--解决SpringBoot打包成jar后运行提示没有主清单属性--> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> <executions> <execution> <goals> <goal>repackage</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>wagon-maven-plugin</artifactId> <version>1.0</version> <configuration> <serverId>linux-server-dev</serverId> <fromFile>target/ayzfm8111.jar</fromFile> <toFile>ayzfm8111.jar</toFile> <url>scp://root@192.168.1.15/var/jenkins_home</url> <commands> <command>docker restart ayzfm8111</command> </commands> <!-- 显示运行命令的输出结果 --> <displayCommandOutputs>true</displayCommandOutputs> </configuration> </plugin> </plugins> </build>
执行命令 install wagon:upload-single wagon:sshexec