基于KubeSphere在K8S发布微服务ruoyi----8.可视化Pipeline:2项目编译

配置maven阿里云镜像加速地址

使用admin登陆k8s

进入配置----配置字典

找到配置

ks-devops-agent

修改这个配置。加入maven阿里云镜像加速地址

   

修改maven配置,不要从中央仓库下载,而是从阿里云镜像仓库下载

<mirrors></mirrors>标签中添加 mirror 子节点

<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>

   

   

参考:Maven之阿里云镜像

来自 <https://zhuanlan.zhihu.com/p/580566433>

 

   

流水线----编译代码

mvn clean package -Dmaven.test.skip=true  

  

   第二阶段报错:

[ERROR] The goal you specified requires a project to execute but there is no POM in this directory (/home/jenkins/agent/workspace/demo-devopszmf97/ruoyi). Please verify you invoked Maven from the correct directory. -> [Help 1]  

排错过程,在第二阶段增加一个嵌套步骤pwdls -al,可以看到目录为空!

   

  

     

第一阶段明明有数据  

原因:第二阶段设置了阶段代理引起,两个阶段是相互独立的!

都设置为none才正常 

     

   

     

第一次编译大约花了6分钟。  

编译好了之后,检查一下某个微服务下有没生成target目录及jar

ls ruoyi-auth

ls ruoyi-auth/target

   

        

   无法编译打包  

[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:3.0.0:repackage (default) on project ruoyi-auth: Execution default of goal org.springframework.boot:spring-boot-maven-plugin:3.0.0:repackage failed: Unable to load the mojo 'repackage' in the plugin 'org.springframework.boot:spring-boot-maven-plugin:3.0.0' due to an API incompatibility: org.codehaus.plexus.component.repository.exception.ComponentLookupException: org/springframework/boot/maven/RepackageMojo has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 52.0

        

     

原因

原因是maven在编译打包过程中没有指定spring-boot-maven-plugin的版本,默认会从nexus仓库中拉取最新的打包插件版本,而最新的3.0.0版本不被jdk8支持,无法执行编译。  

解决方案

需要用户在pom.xml文件中手动指定spring-boot-maven-plugin该插件的打包版本。  

解决方法:

pom.xml新增红色部分

<build>

<plugins>

<plugin>

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

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

<version>2.7.3</version>

</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>

</plugins>

</build>

   

   未增加前截图

     

添加后

 

后记:如果是拉取2022.11.25之后的master代码,带有以下spring-boot-maven-plugin  

修复没有指定spring-boot-maven-plugin 的版本号默认去拉取基于 JDK17 编译的 3.0 版本导致打包失败的问题

来自 <https://gitee.com/y_project/RuoYi-Cloud/commit/04a042c585fd9c4ea1b7d61163d77c5f72a757f9>     

  


其他参考资料

spring-boot-maven-plugin未指定版本导致的编译错误

https://blog.csdn.net/A434534658/article/details/124967619

   

解决通过spring-boot-maven-plugin package失败问题

https://cloud.tencent.com/developer/article/1941876

   

maven-compiler-plugin spring-boot-maven-plugin 区别

maven-compiler-plugin 是用于在编译(compile)阶段加入定制化参数,而 spring-boot-maven-plugin 是用于 spring boot 项目的打包(package)阶段,两者没什么关系

使用 maven-compiler-plugin 可以指定编译时候使用的java版本和字符集编码

https://blog.csdn.net/sinat_37792529/article/details/122855459

   

spring-boot-maven-plugin maven-compiler-plugin有什么区别?

https://www.likecs.com/ask-483937.html#sc=300

  

   

本地打开项目测试

Cannot resolve plugin org.apache.maven.pluginsmaven-compiler-pluginunknown

爆红但不影响项目启动

https://blog.csdn.net/m0_67393413/article/details/126080771  

Maven Repository沾了最新版的版本进来,发现并不能治好我的项目

不如就试试使用最多的一版瞧瞧吧,谁曾想,居然好了!

   

<version>3.8.1</version>

        

关于spring-boot-maven-plugin爆红问题的解决  

来自 <https://blog.csdn.net/qq_42704130/article/details/124952510>  

   

   

posted @ 2023-02-01 21:09  ST运维  阅读(443)  评论(0编辑  收藏  举报