V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
aatao
V2EX  ›  程序员

[求助] 使用 Jenkins 部署 GitHub 的 SpringBoot 项目出现 lombok 找不到包

  •  
  •   aatao · 2018-12-11 01:06:25 +08:00 · 5841 次点击
    这是一个创建于 2181 天前的主题,其中的信息可能已经有所发展或是发生改变。

    配置的环境是 jdk1.8,本地代码调试编译运行都没问题 但是通过自己的服务器配置的 Jenkins 拉去代码进行 install 的时候一直提示 lombok 相关包找不到 (错误信息在下面有贴出)

    网上说的很多说更改 maven-compiler-plugin 版本,试了很多还是没有效果 Linux 服务器环境是 CentOS 7.4 64 位

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    	<modelVersion>4.0.0</modelVersion>
    
    	<groupId>com.library</groupId>
    	<artifactId>libraryproject</artifactId>
    	<version>0.0.1-SNAPSHOT</version>
    	<packaging>war</packaging>
    
    	<name>libraryproject</name>
    	<description>Demo project for Spring Boot</description>
    
    	<parent>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-parent</artifactId>
    		<version>2.0.4.RELEASE</version>
    		<relativePath/> <!-- lookup parent from repository -->
    	</parent>
    
    	<properties>
    		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    		<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    		<java.version>1.8</java.version>
    		<!-- mybatis 版本号 -->
    		<mybatis.version>3.4.6</mybatis.version>
    	</properties>
    
    	<dependencies>
    		<!-- 引入 Caffeine 本地缓存技术 -->
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-cache</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>com.github.ben-manes.caffeine</groupId>
    			<artifactId>caffeine</artifactId>
    			<version>2.6.2</version>
    		</dependency>
    
    		<!-- FastJson -->
    		<dependency>
    			<groupId>com.alibaba</groupId>
    			<artifactId>fastjson</artifactId>
    			<version>1.2.47</version>
    		</dependency>
    
    		<!-- mybatis 核心包 -->
    		<dependency>
    			<groupId>org.mybatis</groupId>
    			<artifactId>mybatis</artifactId>
    			<version>${mybatis.version}</version>
    		</dependency>
    		<!-- druid 数据库连接池 -->
    		<dependency>
    			<groupId>com.alibaba</groupId>
    			<artifactId>druid-spring-boot-starter</artifactId>
    			<version>1.1.0</version>
    		</dependency>
    
    		<!-- 解决 @mapper 注解问题 -->
    		<dependency>
    			<groupId>org.mybatis.spring.boot</groupId>
    			<artifactId>mybatis-spring-boot-starter</artifactId>
    			<version>1.3.2</version>
    		</dependency>
    		<!-- lombok 快捷开发包 -->
    		<dependency>
    			<groupId>org.projectlombok</groupId>
    			<artifactId>lombok</artifactId>
    			<version>1.16.10</version>
    			<scope>provided</scope>
    		</dependency>
    		<!-- easypoi 工具包 -->
    		<dependency>
    			<groupId>cn.afterturn</groupId>
    			<artifactId>easypoi-base</artifactId>
    			<version>3.2.0</version>
    		</dependency>
    		<dependency>
    			<groupId>cn.afterturn</groupId>
    			<artifactId>easypoi-web</artifactId>
    			<version>3.2.0</version>
    		</dependency>
    		<dependency>
    			<groupId>cn.afterturn</groupId>
    			<artifactId>easypoi-annotation</artifactId>
    			<version>3.2.0</version>
    		</dependency>
    
    
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-jdbc</artifactId>
    		</dependency>
    		<dependency>
    			<groupId>org.mybatis.generator</groupId>
    			<artifactId>mybatis-generator-core</artifactId>
    			<version>1.3.2</version>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-web</artifactId>
    		</dependency>
    
    		<dependency>
    			<groupId>mysql</groupId>
    			<artifactId>mysql-connector-java</artifactId>
    			<scope>runtime</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.springframework.boot</groupId>
    			<artifactId>spring-boot-starter-test</artifactId>
    			<scope>test</scope>
    		</dependency>
    		<dependency>
    			<groupId>org.xmlunit</groupId>
    			<artifactId>xmlunit-core</artifactId>
    		</dependency>
    		<!-- 工具包 -->
    		<dependency>
    			<groupId>commons-lang</groupId>
    			<artifactId>commons-lang</artifactId>
    			<version>2.6</version>
    		</dependency>
    	</dependencies>
    
    	<build>
    		<plugins>
    			<plugin>
    				<groupId>org.apache.maven.plugins</groupId>
    				<artifactId>maven-compiler-plugin</artifactId>
    				<version>3.6.2</version>
    				<configuration>
    					<source>1.8</source>
    					<target>1.8</target>
    				</configuration>
    			</plugin>
    		</plugins>
    	</build>
    </project>
    
    
    
    大致的错误信息如下:
    ~~~执行 Maven:-B -f /root/.jenkins/workspace/LibrayProject/pom.xml 安装
    [INFO]扫描项目......
    [信息] 
    [INFO] --------------------- <com.library:libraryproject> ------------------- - 
    [INFO]构建 libraryproject 0.0.1-SNAPSHOT
    [INFO] -------------------------------- [war] ------------ ---------------------
    [信息] 
    [INFO] --- maven-resources-plugin:3.0.2:resources ( default-resources )@ libraryproject ---
     [INFO]使用'UTF-8'编码复制过滤后的资源。
    [INFO]复制 1 个资源
    [INFO]复制 6 个资源
    [信息] 
    [INFO] --- maven-compiler-plugin:3.6.2:compile ( default-compile )@ libraryproject ---
     [INFO]检测到更改 - 重新编译模块!
    [INFO]将 38 个源文件编译到 /root/.jenkins/workspace/LibrayProject/target/classes
    [INFO] ----------------------------------------------- --------------
    [ERROR]编译错误: 
     [INFO] ----------------------------------------- --------------------
     [ERROR] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/SeatLocation.java:[3,14]包 lombok 不存在
     [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/SeatLocation.java:[4,14]包 lombok 不存在
     [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/SeatLocation.java:[5,14]包 lombok 不存在
     [ERROR] / root /。jenkins / workspace / LibrayProject / src / main / java / com / library / libraryproject / entity / SeatLocation.java:[6,14]包 lombok 不存在
    [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/SeatLocation.java:[13,2]找不到符号
       符号:class Data
     [ERROR] / root /。jenkins / workspace / LibrayProject / src / main / java / com / library / libraryproject / entity / SeatLocation.java:[14,2]找不到符号
       符号:class Builder
     [ERROR] /root/.jenkins/workspace/LibrayProject/src /main/java/com/library/libraryproject/entity/SeatLocation.java:[15,2]找不到符号
       符号:class AllArgsConstructor
     [ERROR] /root/.jenkins/workspace/LibrayProject/src/main/java/com/ library / libraryproject / entity / SeatLocation.java:[16,2]找不到符号
       符号:class NoArgsConstructor
    [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/controller/ManagerController.java:[7,27]包 lombok.extern.slf4j 不存在
     [ERROR] / root /.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/controller/ManagerController.java:[8,52]包 org.springframework.beans.factory.annotation 不存在
     [ERROR] / root / .jenkins / workspace / LibrayProject / src / main / java / com / library / libraryproject / controller / ManagerController.java:[9,38] package org.springframework.stereotype 不存在
     [ERROR] /root/.jenkins/workspace/ LibrayProject / src / main / java / com / library / libraryproject / controller / ManagerController.java:[10,47]包 org.springframework.web.bind.annotation 不存在
    [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/controller/ManagerController.java:[11,47]包 org.springframework.web.bind.annotation 不存在
     [ ERROR] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/controller/ManagerController.java:[18,2]找不到符号
       符号:class Slf4j
     [ERROR] /root/.jenkins /workspace/LibrayProject/src/main/java/com/library/libraryproject/controller/ManagerController.java:[19,2]找不到符号
       符号:class Controller
     [ERROR] /root/.jenkins/workspace/LibrayProject/src/ main / java / com / library / libraryproject / controller / ManagerController.java:[20,2]找不到符号
       符号:class RequestMapping
    [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/Manager.java:[3,14]包 lombok 不存在
     [ERROR] /root/.jenkins/ workspace / LibrayProject / src / main / java / com / library / libraryproject / entity / Manager.java:[4,14] package lombok 不存在
     [ERROR] /root/.jenkins/workspace/LibrayProject/src/main/java /com/library/libraryproject/entity/Manager.java:[5,14]包 lombok 不存在
     [ERROR] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/ Manager.java:[6,14]包 lombok 不存在
     [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/Manager.java:[13,2]找不到符号
       符号:class Data
    [错误] /root/.jenkins/workspace/LibrayProject/src/main/java/com/library/libraryproject/entity/Manager.java:[14,2]找不到符号
       符号:class Builder
    
    12 条回复    2019-08-15 10:47:02 +08:00
    alvinbone88
        1
    alvinbone88  
       2018-12-11 08:39:56 +08:00 via Android
    先在 Jenkins 上跑一遍 mvn compile --debug,然后检查 javac 的配置,重点关注-classpath, -proc, -processorpath -processor 这几个的值
    defunct9
        2
    defunct9  
       2018-12-11 08:58:19 +08:00
    开 ssh,让我上去看看
    biggates
        3
    biggates  
       2018-12-11 09:02:53 +08:00
    你项目里的 lombok 的 scope 是 provided,但是又没有配置 delombok 所以就会缺了。解决方法要么是在 classpath 里加 lombok,要么改 scope 为默认,要么配置 delombok。
    paragon
        4
    paragon  
       2018-12-11 11:01:16 +08:00
    @biggates 正解
    aatao
        5
    aatao  
    OP
       2018-12-12 01:02:59 +08:00
    @biggates
    配置 delombok 是引入这个嘛?
    <plugin>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-maven-plugin</artifactId>
    <version>${lombok.plugin.version}</version>
    <executions>
    <execution>
    <phase>generate-sources</phase>
    <goals>
    <goal>delombok</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    aatao
        6
    aatao  
    OP
       2018-12-12 09:54:53 +08:00
    我把 scope 删了,也就是改成默认了,试了一把,还是不行

    然后尝试下载 lombok.jar 添加到服务器的 classpath 里面,但是仍然木有效果……

    delomok 我在网上搜了搜,就看到楼上那种配置的… but 还是木有用
    aatao
        7
    aatao  
    OP
       2018-12-12 23:31:17 +08:00
    @paragon
    @biggates
    求教怎么配置 delombok, (加入 classpath 是 eclipse 项目?我看 idea 的 project structure 是存在 lombok 的 maven 依赖的)
    aatao
        8
    aatao  
    OP
       2018-12-12 23:32:17 +08:00
    <groupId>com.library</groupId>
    <artifactId>libraryproject</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>

    <name>libraryproject</name>
    <description>Demo project for Spring Boot</description>

    <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.4.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <properties>
    <lombok.version>1.16.16</lombok.version>
    <lombok.plugin.version>1.16.16.0</lombok.plugin.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <!-- mybatis 版本号 -->
    <mybatis.version>3.4.6</mybatis.version>
    </properties>

    <dependencies>
    <!-- 引入 Caffeine 本地缓存技术 -->
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-cache</artifactId>
    </dependency>
    <dependency>
    <groupId>com.github.ben-manes.caffeine</groupId>
    <artifactId>caffeine</artifactId>
    <version>2.6.2</version>
    </dependency>

    <!-- FastJson -->
    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>fastjson</artifactId>
    <version>1.2.47</version>
    </dependency>

    <!-- mybatis 核心包 -->
    <dependency>
    <groupId>org.mybatis</groupId>
    <artifactId>mybatis</artifactId>
    <version>${mybatis.version}</version>
    </dependency>
    <!-- druid 数据库连接池 -->
    <dependency>
    <groupId>com.alibaba</groupId>
    <artifactId>druid-spring-boot-starter</artifactId>
    <version>1.1.0</version>
    </dependency>

    <!-- 解决 @mapper 注解问题 -->
    <dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.2</version>
    </dependency>
    <!-- lombok 快捷开发包 -->
    <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <version>${lombok.version}</version>
    <scope>provided</scope>
    </dependency>

    <!-- easypoi 工具包 -->
    <dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-base</artifactId>
    <version>3.2.0</version>
    </dependency>
    <dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-web</artifactId>
    <version>3.2.0</version>
    </dependency>
    <dependency>
    <groupId>cn.afterturn</groupId>
    <artifactId>easypoi-annotation</artifactId>
    <version>3.2.0</version>
    </dependency>


    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
    <groupId>org.mybatis.generator</groupId>
    <artifactId>mybatis-generator-core</artifactId>
    <version>1.3.2</version>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
    </dependency>
    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
    </dependency>
    <dependency>
    <groupId>org.xmlunit</groupId>
    <artifactId>xmlunit-core</artifactId>
    </dependency>
    <!-- 工具包 -->
    <dependency>
    <groupId>commons-lang</groupId>
    <artifactId>commons-lang</artifactId>
    <version>2.6</version>
    </dependency>
    </dependencies>

    <build>
    <plugins>
    <plugin>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok-maven-plugin</artifactId>
    <version>${lombok.plugin.version}</version>
    <executions>
    <execution>
    <phase>generate-sources</phase>
    <goals>
    <goal>delombok</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.6.2</version>
    <configuration>
    <source>1.8</source>
    <target>1.8</target>
    </configuration>
    </plugin>
    </plugins>
    </build>
    </project>
    aatao
        9
    aatao  
    OP
       2018-12-13 00:36:02 +08:00
    我在本地跑了 lombok:delombok 但是在 jenkins 上仍然没有效果
    biggates
        10
    biggates  
       2018-12-13 09:48:13 +08:00
    @aatao 我这边的项目 lombok 都是默认打进去的,没试过 delombok。另外 jenkins 的 classpath 可能是一个额外的配置(因为他可以自动从 sun 下载,还可以指定具体的版本号,这意味着不一定是调用了系统的 jdk )。如果一定要 delombok 的话你可以在 jenkins 里面 Global Tool Configuration -> JDK 研究一下。

    另:如果你要跑 delombok 的话,注意如果默认配置的话,只有 `src/main/lombok` 目录下的 java 文件才会进行 delombok。具体查阅 http://awhitford.github.io/lombok.maven/lombok-maven-plugin/usage.html
    biggates
        11
    biggates  
       2018-12-13 09:50:21 +08:00
    aatao
        12
    aatao  
    OP
       2019-08-15 10:47:02 +08:00
    老坑回看....
    问题解决:重新配置服务器上的 maven
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2809 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 106ms · UTC 05:50 · PVG 13:50 · LAX 21:50 · JFK 00:50
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.