Lombok 作为 Gitlab CI 中 mevan docker 映像的提供者?

Posted

技术标签:

【中文标题】Lombok 作为 Gitlab CI 中 mevan docker 映像的提供者?【英文标题】:Lombok as provider in mevan docker image in Gitlab CI? 【发布时间】:2021-11-18 05:56:07 【问题描述】:

我已经编写了一个 springboot thymeleaf 应用程序,并且我已经将它推送到了 GitLab。我想从 GitLab 生成 jar 并存储在 respoistory 中。

为此,我使用以下插件

    <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
  
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2-beta-1</version>
                <configuration>
                    <descriptors>
                        <descriptor>src/main/resources/distribution/Dynamic2Static-distribution.xml
                        </descriptor>
                    </descriptors>

                    <finalName>Dynamic2Static-$project.version</finalName>
                </configuration>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Gitlab CI 运行良好并生成了所需的构建。

但是当我为 jdk8 引入 lombok 时,我开始遇到编译错误。 我在本地机器上没有收到错误,因为我在 ide 上添加了 lombok jar

Git Lab CI yml

# This file is a template, and might need editing before it works on your project.
# Build JAVA applications using Apache Maven (http://maven.apache.org)
# For docker image tags see https://hub.docker.com/_/maven/
#
# For general lifecycle information see https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

# This template will build and test your projects
# * Caches downloaded dependencies and plugins between invocation.
# * Verify but don't deploy merge requests.
# * Deploy built artifacts from master branch only.

variables:
  # This will suppress any download for dependencies and plugins or upload messages which would clutter the console log.
  # `showDateTime` will show the passed time in milliseconds. You need to specify `--batch-mode` to make this work.
  MAVEN_OPTS: "-Dhttps.protocols=TLSv1.2 -Dmaven.repo.local=$CI_PROJECT_DIR/.m2/repository -Dorg.slf4j.simpleLogger.log.org.apache.maven.cli.transfer.Slf4jMavenTransferListener=WARN -Dorg.slf4j.simpleLogger.showDateTime=true -Djava.awt.headless=true"
  # As of Maven 3.3.0 instead of this you may define these options in `.mvn/maven.config` so the same config is used
  # when running from the command line.
  # `installAtEnd` and `deployAtEnd` are only effective with recent version of the corresponding plugins.
  MAVEN_CLI_OPTS: "--batch-mode --errors --fail-at-end --show-version -DinstallAtEnd=true -DdeployAtEnd=true"

# This template uses jdk8 for verifying and deploying images
image: maven:3.3.9-jdk-8

# Cache downloaded dependencies and plugins between builds.
# To keep cache across branches add 'key: "$CI_JOB_NAME"'
cache:
  paths:
    - .m2/repository

# For merge requests do not `deploy` but only run `verify`.
# See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
.verify: &verify
  stage: test
  script:
    - 'mvn $MAVEN_CLI_OPTS verify'
  except:
    - master

# Verify merge requests using JDK8
verify:jdk8:
  <<: *verify

# To deploy packages from CI, create a ci_settings.xml file
# For deploying packages to GitLab's Maven Repository: See https://docs.gitlab.com/ee/user/project/packages/maven_repository.html#creating-maven-packages-with-gitlab-cicd for more details.
# Please note: The GitLab Maven Repository is currently only available in GitLab Premium / Ultimate.
# For `master` branch run `mvn deploy` automatically.
deploy:jdk8:
  stage: deploy
  script:
    - if [ ! -f ci_settings.xml ];
        then echo "CI settings missing\! If deploying to GitLab Maven Repository, please see https://docs.gitlab.com/ee/user/project/packages/maven_repository.html#creating-maven-packages-with-gitlab-cicd for instructions.";
      fi
    - 'mvn $MAVEN_CLI_OPTS deploy -s ci_settings.xml'
  only:
    - master
    - merge_requests
    - tags

我在 Git Lab 作业中遇到以下错误

Maven Repository, please see https://docs.gitlab.com/ee/user/project/packages/maven_repository.html#creating-maven-packages-with-gitlab-cicd for instructions."; fi
$ mvn $MAVEN_CLI_OPTS deploy -s ci_settings.xml
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /usr/share/maven
Java version: 1.8.0_121, vendor: Oracle Corporation
Java home: /usr/lib/jvm/java-8-openjdk-amd64/jre
Default locale: en, platform encoding: UTF-8
OS name: "linux", version: "5.4.109+", arch: "amd64", family: "unix"
2016 [INFO] Error stacktraces are turned on.
2127 [INFO] Scanning for projects...
9939 [WARNING] 
9942 [WARNING] Some problems were encountered while building the effective model for com.giriviriajhikers:Dynamic2Static:jar:1.0.0
9943 [WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.webjars:jquery:jar -> version 3.6.0 vs 1.12.4 @ line 109, column 15
9943 [WARNING] 
9943 [WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
9944 [WARNING] 
9944 [WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
9944 [WARNING] 
9973 [INFO]                                                                         
9974 [INFO] ------------------------------------------------------------------------
9974 [INFO] Building Dynamic2Static 1.0.0
9974 [INFO] ------------------------------------------------------------------------
61022 [INFO] 
61023 [INFO] --- maven-resources-plugin:3.1.0:resources (default-resources) @ Dynamic2Static ---
63629 [INFO] Using 'UTF-8' encoding to copy filtered resources.
63662 [INFO] Copying 1 resource
63809 [INFO] Copying 679 resources
64162 [INFO] 
64163 [INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Dynamic2Static ---
67927 [INFO] Changes detected - recompiling the module!
67957 [INFO] Compiling 305 source files to /builds/dynamic-2-static/dynamic2static/target/classes
76777 [INFO] -------------------------------------------------------------
76778 [WARNING] COMPILATION WARNING : 
76778 [INFO] -------------------------------------------------------------
76779 [WARNING] /builds/dynamic-2-static/dynamic2static/src/main/java/com/giriviriajhikers/utils/ConstantsMap.java: /builds/dynamic-2-static/dynamic2static/src/main/java/com/giriviriajhikers/utils/ConstantsMap.java uses unchecked or unsafe operations.
76779 [WARNING] /builds/dynamic-2-static/dynamic2static/src/main/java/com/giriviriajhikers/utils/ConstantsMap.java: Recompile with -Xlint:unchecked for details.
76779 [INFO] 2 warnings 
76780 [INFO] -------------------------------------------------------------
76780 [INFO] -------------------------------------------------------------
76780 [ERROR] COMPILATION ERROR : 
76781 [INFO] -------------------------------------------------------------
76781 [ERROR] /builds/dynamic-2-static/dynamic2static/src/main/java/com/giriviriajhikers/admin/home/ThankYouDataModel.java:[6,8] class ThankyouDataModel is public, should be declared in a file named ThankyouDataModel.java
76781 [ERROR] /builds/dynamic-2-static/dynamic2static/src/main/java/com/giriviriajhikers/admin/climbing/ClimbingController.java:[85,25] cannot find symbol
  symbol:   variable log
  location: class com.giriviriajhikers.admin.climbing.ClimbingController
76785 [ERROR] /builds/dynamic-2-static/dynamic2static/src/main/java/com/giriviriajhikers/admin/climbing/ClimbingController.java:[86,70] cannot find symbol
  symbol:   method getFolderPath()

我在 Pom.xml 中添加了 lombok 依赖项 我想知道如何让 gitlab docker mevan image 中提供的 lombok jar 可用以编译我的代码

【问题讨论】:

你能显示 pom.xml 的部分,你在其中添加了 lombok 作为依赖项吗? 【参考方案1】:

您应该使用maven-compiler-plugin。见

How to configure Lombok with maven-compiler-plugin?

https://projectlombok.org/setup/maven

http://anthonywhitford.com/lombok.maven/lombok-maven-plugin/

关心

JDK 版本和 Java 语言级别的应用程序和 服务器环境的JDK版本。

【讨论】:

我尝试了以上所有选项,但 git lab CI 仍然抛出编译错误

以上是关于Lombok 作为 Gitlab CI 中 mevan docker 映像的提供者?的主要内容,如果未能解决你的问题,请参考以下文章

使用来自 Gitlab Registry 的私有 Docker 镜像作为 CI 的基础镜像

gitlab ci 集成 eslint/prettier/tsc 做代码审查,并使用 eslint 输出作为显示代码质量

如何在 Gitlab CI 中使用 Dockerfile

从 Jenkins Ci 服务迁移到 gitlab-ci.yml

在 Gitlab Ci 中将 RabbitMq 作为 GenerigContainer 启动

GitLab CI 的多行 YAML 字符串 (.gitlab-ci.yml)