# syntax=docker/dockerfile-upstream:1-labs # ^ the above is needed to use the <<-EOF feature syntaxt see: # https://github.com/moby/moby/issues/16058#issuecomment-881901519 FROM openjdk:11 # Download latest gradle (at the time of writing) and check its sha256 # and check it is running by getting its version RUN mkdir --parents /opt/gradle WORKDIR /opt/gradle RUN wget https://services.gradle.org/distributions/gradle-7.3.1-bin.zip RUN wget https://services.gradle.org/distributions/gradle-7.3.1-bin.zip.sha256 RUN echo -n ' gradle-7.3.1-bin.zip' >> gradle-7.3.1-bin.zip.sha256 RUN sha256sum --check gradle-7.3.1-bin.zip.sha256 RUN unzip -d /opt/gradle gradle-7.3.1-bin.zip ENV PATH="/opt/gradle/gradle-7.3.1/bin/:${PATH}" RUN gradle --version # setup up a demo gradle app RUN mkdir --parents /usr/src/app WORKDIR /usr/src/app RUN gradle init --type java-application --dsl groovy # This "fun" Docker hack builds use-compile.sh script that can be invoked as # $ docker run -it log4j-docs ./use-compile.sh # it is not necesary, but prevents someone from running the script _outside_ # of a docker container # # The script use-compile.sh uses the oficial instructions shown here: # https://logging.apache.org/log4j/2.x/maven-artifacts.html#Using_Log4j_in_your_Gradle_build RUN <<-DOCKER_EOF cat < use-compile.sh #!/usr/bin/env bash cat <> app/build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.15.0' compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.15.0' } SCRIPT_EOF ./gradlew build INLINE_EOF DOCKER_EOF RUN chmod +x use-compile.sh # This uses the newer "directive" implementation. RUN <<-DOCKER_EOF cat < use-implementation.sh #!/usr/bin/env bash cat <> app/build.gradle dependencies { implementation 'org.apache.logging.log4j:log4j-api:2.15.0' implementation 'org.apache.logging.log4j:log4j-core:2.15.0' } EOF ./gradlew build INLINE_EOF DOCKER_EOF RUN chmod +x use-implementation.sh