首页 > 解决方案 > gradle docker 文件来构建 jars

问题描述

在构建 docker 映像之前,我需要建议在 docker 文件中包含什么来构建 jar。

最初,我使用这个 test.bat 文件来构建 jar

现在我需要改变这种方式,改为使用 docker compose。

CALL gradlew build 

rem docker build test-query/. -t testquery

rem docker run --name testquery -dit -p 8002:8002 --network lsvc --restart=unless-stopped testquery

rem docker build test-command/. -t testcommand

rem docker run --name testcommand -dit -p 8008:8008 --network lsvc --restart=unless-stopped testcommand

Docker 文件,我修改为下载 gradle docker 然后构建文件

FROM gradle:4.7.0-jdk8-alpine AS build
COPY --chown=gradle:gradle . /test-command/src
ADD --chown=gradle . /app
WORKDIR /app
RUN gradle build test-query/. -t testquery
RUN gradle build test-command/. -t testcommand

FROM ubuntu
FROM openjdk:8-alpine
WORKDIR /app
VOLUME ["/app"]
COPY test-command/build/libs/*.jar /app/test-command.jar
COPY test-command/docker/startup.sh /app/startup.sh
#RUN sh -c 'touch /app/test-command.jar'
RUN chmod +x /app/startup.sh
RUN chmod +x /app/test-command.jar
ENTRYPOINT ["/bin/sh", "/app/startup.sh"]

启动.sh

#!/bin/sh
sleep 150; java -jar /app/test-command.jar

docker-compose up 时出错

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'test'.
> Failed to apply plugin [id 'io.gitlab.arturbosch.detekt']
   > Could not create an instance of type io.gitlab.arturbosch.detekt.extensions.DetektExtension_Decorated.
      > org.gradle.api.file.ProjectLayout.configurableFiles([Ljava/lang/Object;)Lorg/gradle/api/file/ConfigurableFileCollection;

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

标签: dockergradledocker-composebuild.gradle

解决方案


您使用的插件版本与io.gitlab.arturbosch.detekt您使用的旧 Gradle 版本 4.7 不兼容。我假设您已经在 docker 之外测试了 Gradle 构建,因此您可能只是使用了错误版本的 Gradle for Docker。看看是否可以将其升级到 5.x 或 6.x(通常,越新越好)。

否则,您将不得不降级插件(尽管我不知道哪个版本放弃了对 Gradle 4.7 的支持),或者您必须找到与旧版本兼容的替代品。


推荐阅读