gradle docker 构建 jar 的文件
gradle docker file to build 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"]
startup.sh
#!/bin/sh
sleep 150; java -jar /app/test-command.jar
docker-组合时出错
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
您正在使用的 io.gitlab.arturbosch.detekt
插件版本与您正在使用的旧 Gradle 版本 4.7 不兼容。我假设您已经在 docker 之外测试了 Gradle 构建,因此您可能只是为 Docker 使用了错误版本的 Gradle。看看能不能升级到5.x或者6.x(一般来说,越新越好)。
否则,您将不得不降级插件(虽然我不知道哪个版本放弃了对 Gradle 4.7 的支持),或者您必须找到适用于旧版本的替代品。
我需要建议在 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"]
startup.sh
#!/bin/sh
sleep 150; java -jar /app/test-command.jar
docker-组合时出错
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
您正在使用的 io.gitlab.arturbosch.detekt
插件版本与您正在使用的旧 Gradle 版本 4.7 不兼容。我假设您已经在 docker 之外测试了 Gradle 构建,因此您可能只是为 Docker 使用了错误版本的 Gradle。看看能不能升级到5.x或者6.x(一般来说,越新越好)。
否则,您将不得不降级插件(虽然我不知道哪个版本放弃了对 Gradle 4.7 的支持),或者您必须找到适用于旧版本的替代品。