Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ RUN curl -L --fail --retry 3 --retry-delay 5 "$LIBWEBP_URL" -O && \

ENV GRADLE_OPTS="-Dorg.gradle.daemon=false"
COPY settings.gradle build.gradle gradlew ./
COPY gradle ./gradle
RUN --mount=type=cache,target=/home/gradle/.gradle/caches ./gradlew dependencies
COPY gradle gradle
RUN --mount=type=cache,target=/root/.gradle ./gradlew dependencies
COPY . .
RUN ./gradlew runtime
RUN --mount=type=cache,target=/root/.gradle ./gradlew jre shadowJar

FROM alpine AS bot

Expand Down
62 changes: 49 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
alias(libs.plugins.runtime)
alias(libs.plugins.shadow)
id 'application'
id 'java'
id 'jacoco'
}
Expand Down Expand Up @@ -53,12 +53,55 @@ tasks.withType(JavaCompile).configureEach {
options.encoding = 'UTF-8'
}

def jreOutputDir = layout.buildDirectory.dir('jre')
tasks.register('jre') {
inputs.property('options', ['--strip-debug', '--no-header-files', '--no-man-pages'])
inputs.property('modules', ['java.desktop', 'java.instrument', 'java.naming', 'java.sql', 'jdk.crypto.ec', 'jdk.unsupported'])

outputs.dir(jreOutputDir)

doFirst {
delete(jreOutputDir)
}

def javaLauncher = javaToolchains.launcherFor(java.toolchain)

doLast {
def installationPath = javaLauncher.get().metadata.installationPath

Comment thread
coderabbitai[bot] marked this conversation as resolved.
def exe = Os.isFamily(Os.FAMILY_WINDOWS) ? 'bin\\jlink.exe' : 'bin/jlink'
def jlink = installationPath.file(exe)
def jmods = installationPath.dir('jmods')

def output = providers.exec {
ignoreExitValue = true
commandLine = [
jlink.toString(), '-v',
*(inputs.properties['options'] as List),
'--module-path', jmods.toString(),
'--add-modules', (inputs.properties['modules'] as List).join(','),
'--output', jreOutputDir.get().toString()
]
}

def result = output.result.get()
if (result.exitValue != 0) {
Comment thread
MartelliEnrico marked this conversation as resolved.
Outdated
logger.log(LogLevel.ERROR, output.standardError.asText.get())
} else {
logger.info(output.standardOutput.asText.get())
}

result.assertNormalExitValue()
result.rethrowFailure()
}
}

test {
dependsOn jre
inputs.dir tasks.jre.jreDir
dependsOn tasks.named('jre')
inputs.dir(jreOutputDir)

def file = DefaultNativePlatform.currentOperatingSystem.isWindows() ? 'java.exe' : 'java'
executable = tasks.jre.jreDir.file('bin/' + file)
def exe = Os.isFamily(Os.FAMILY_WINDOWS) ? 'bin\\java.exe' : 'bin/java'
Comment thread
MartelliEnrico marked this conversation as resolved.
Outdated
executable = jreOutputDir.get().file(exe)

useJUnitPlatform()
finalizedBy jacocoTestReport
Expand Down Expand Up @@ -93,10 +136,3 @@ shadowJar {
exclude('dist_webp_binaries/')
}
}

runtime {
options = ['--strip-debug', '--no-header-files', '--no-man-pages'] // don't compress jre because final docker image will be larger
modules = ['java.desktop', 'java.instrument', 'java.naming', 'java.sql', 'jdk.crypto.ec', 'jdk.unsupported']
}

suggestModules.dependsOn shadowJar
1 change: 0 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ telegram-bot-api = "com.github.pengrad:java-telegram-bot-api:8.3.0"
tika = "org.apache.tika:tika-core:3.2.1"

[plugins]
runtime = "com.dua3.gradle.runtime:1.13.1-patch-1"
shadow = "com.gradleup.shadow:8.3.8"
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.14.3-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading