Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a gradle project using gitlab's CI, unforunately using any Swing classes results in:

(我有一个使用gitlab的CI的gradle项目,不幸的是,使用任何Swing类都会导致:)
java.awt.AWTException: headless environment

(java.awt.AWTException:无头环境)

I found one answer at Easiest way to unit test SWT and Swing apps in a headless environment?

(我找到了在无头环境中对SWT和Swing应用程序进行单元测试的最简单方法的一个答案)

that mentioned using Xvfb, which seems like it would work, but didn't elaborate because there was a tool-specific simpler option.

(提到使用Xvfb似乎有效,但由于存在特定于工具的更简单选项而没有详细说明。)

If Xvfb would work, how does it need to be configured in my project?

(如果Xvfb可以工作,则如何在我的项目中对其进行配置?)

I couldn't find any resources for gitlab/gradle.

(我找不到gitlab / gradle的任何资源。)

Is there a simpler option specific to gitlab?

(是否有特定于gitlab的简单选项?)

  ask by jeffrey.d.m translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
448 views
Welcome To Ask or Share your Answers For Others

1 Answer

So I was able to find a solution that has just worked.

(因此,我能够找到一个可行的解决方案。)

I ended up creating my own Docker image:

(我最终创建了自己的Docker映像:)

FROM alpine:3.10
RUN apk update
RUN apk --no-cache add openjdk11 --repository=http://dl-cdn.alpinelinux.org/alpine/edge/community
RUN apk add xvfb-run

and then I just had to update my .gitlab-ci.yml to use that image:

(然后我只需要更新.gitlab-ci.yml以使用该图像:)

image: jeffreydm/xvfb-java:v0.1

and lastly, I updated my script from:

(最后,我从以下位置更新了脚本:)

build:
  stage: build
  script:
    - ./gradlew build

to:

(至:)

build:
  stage: build
  script:
    - xvfb-run ./gradlew build

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...