gradle init --use-defaults --type java-application
The above command will setup a basic gradle project.
To prepare a jar which is executable, we need to setup a manifest property in build.gradle
to identify the Main class to execute.
jar {
manifest {
attributes(
'Main-Class' : 'org.example.Main'
)
}
}
./gradlew build
The above command will build the project.
./gradlew jar
The above command creates a new jar file in the build/libs
folder.
java -jar build/libs/filename.jar
The above command will execute the code.