- java application openjdk 17
- gradle 8.7
install gradle
# apt-get install gradle vlc
create folder project example
$ mkdir example
$ cd example
create init project
wrap gradle version for your project
$ gradle wrapper --gradle-version 8.7
openjdk version "17.0.16" 2025-07-15
OpenJDK Runtime Environment (build 17.0.16+8-Debian-1deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.16+8-Debian-1deb12u1, mixed mode, sharing)
init using gradle 8.7 debian 13 uses old 4.4
$ ./gradlew init \
--type java-application \
--dsl groovy \
--test-framework junit-jupiter \
--package com.dedetok \
--project-name example
openjdk version "17.0.16" 2025-07-15
OpenJDK Runtime Environment (build 17.0.16+8-Debian-1deb12u1)
OpenJDK 64-Bit Server VM (build 17.0.16+8-Debian-1deb12u1, mixed mode, sharing)
Downloading https://services.gradle.org/distributions/gradle-8.7-bin.zip
...............................................................................................................................
Unzipping ~/.gradle/wrapper/dists/gradle-8.7-bin/bhs2wmbdwecv87pi65oeuq5iu/gradle-8.7-bin.zip to ~/.gradle/wrapper/dists/gradle-8.7-bin/bhs2wmbdwecv87pi65oeuq5iu
Set executable permissions for: ~/.gradle/wrapper/dists/gradle-8.7-bin/bhs2wmbdwecv87pi65oeuq5iu/gradle-8.7/bin/gradle
Welcome to Gradle 8.7!
Here are the highlights of this release:
- Compiling and testing with Java 22
- Cacheable Groovy script compilation
- New methods in lazy collection properties
For more details see https://docs.gradle.org/8.7/release-notes.html
Starting a Gradle Daemon, 1 incompatible Daemon could not be reused, use --status for details
Enter target Java version (min: 7, default: 21): 17
Select application structure:
1: Single application project
2: Application and library project
Enter selection (default: Single application project) [1..2] 1
Generate build using new APIs and behavior (some features may change in the next minor release)? (default: no) [yes, no] no
> Task :init
To learn more about Gradle by exploring our Samples at https://docs.gradle.org/8.7/samples/sample_building_java_applications_multi_project.html
BUILD SUCCESSFUL in 5m 12s
1 actionable task: 1 executed
settings.gradle
plugins {
// Apply the foojay-resolver plugin to allow automatic download of JDKs
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.8.0'
}
rootProject.name = 'example'
include('app')
~/app/build.gradle
plugins {
// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
}
repositories {
// Use Maven Central for resolving dependencies.
mavenCentral()
}
dependencies {
// Use JUnit Jupiter for testing.
testImplementation libs.junit.jupiter
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
// This dependency is used by the application.
implementation libs.guava
}
// Apply a specific Java toolchain to ease working on different environments.
java {
toolchain {
languageVersion = JavaLanguageVersion.of(17)
}
}
application {
// Define the main class for the application.
mainClass = 'com.dedetok.App'
}
tasks.named('test') {
// Use JUnit Platform for unit tests.
useJUnitPlatform()
}
~/gradle/libs.versions.toml
[versions]
guava = "32.1.3-jre"
junit-jupiter = "5.10.1"
[libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
To show current gradle version
$ ./gradlew --version
------------------------------------------------------------
Gradle 8.7
------------------------------------------------------------
Build time: 2024-03-22 15:52:46 UTC
Revision: 650af14d7653aa949fce5e886e685efc9cf97c10
Kotlin: 1.9.22
Groovy: 3.0.17
Ant: Apache Ant(TM) version 1.10.13 compiled on January 4 2023
JVM: 17.0.16 (Debian 17.0.16+8-Debian-1deb12u1)
OS: Linux 6.12.57+deb13-amd64 amd64
Test run
$ ./gradlew run
Path for java installation '/usr/lib/jvm/openjdk-17' (Common Linux Locations) does not contain a java executable
> Task :app:run
Hello World!
BUILD SUCCESSFUL in 473ms
2 actionable tasks: 1 executed, 1 up-to-date
or you can run using style $ ./gradlew :app:run
Now add maridb jcoonect into project, using Traditional Groovy Approach. edit ~/app/build.gradle
...
dependencies {
// Use JUnit Jupiter for testing.
testImplementation libs.junit.jupiter
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
// This dependency is used by the application.
implementation libs.guava
// mariadb jconnector (single file no need change libs.versions.toml
implementation 'org.mariadb.jdbc:mariadb-java-client:3.3.3'
// using libs.versions.toml must editing this file
//implementation libs.mariadb.client
}
...
If you wish to useing Version Catalog Approach, use 2nd option for ~/app/build.gradle and edit libs.version.toml
[versions]
guava = "32.1.3-jre"
junit-jupiter = "5.10.1"
mariadb = "3.3.3"
[libraries]
guava = { module = "com.google.guava:guava", version.ref = "guava" }
junit-jupiter = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit-jupiter" }
mariadb-client = { group = "org.mariadb.jdbc", name = "mariadb-java-client", version.ref = "mariadb" }
use Version Catalog Approach for complex project and involving multiple developers.
To generate single file jar for your project, edit ~/app/build.gradle
...
jar {
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
// change with yours
manifest {
attributes "Main-Class": "com.dedetok.App"
}
from {
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
}
...
You can run directly using java command
$ java -jar ./app/build/libs/app.jar
Hello World!
Your jar file location is ~/app/build/libs/
Now you can edit ~/app/src/main/java/com/dedetok/App.java finish your project. Use any text editor if you wish.