Skip to content

Latest commit

 

History

History
230 lines (156 loc) · 5.55 KB

README.md

File metadata and controls

230 lines (156 loc) · 5.55 KB
The Java Programming Language

Ubuntu-(20.04LTS) GitHub release (latest by date) Java zulu-openjdk:11 GitHub release (latest by date) CircleCI

basic_102

Lesson 102: Hello Gradle!

  • install Gradle on Ubuntu 20.04
  • develop Java application with Gradle

Keywords

  • Gradle Gradle Java Application Gradle tasks
  • Ubuntu Java Testing Jar tutorial example

Step 1: Prerequisites

Step 2: install Gradle on Ubuntu

sudo snap install gradle --classic
gradle -v

Step 3: develop a Java application with Gradle

create a project with two Gradle files

touch settings.gradle
vi settings.gradle
touch build.gradle
vi build.gradle

run Gradle help command

gradle
#gradle help
#gradle :help

add the Java code

mkdir -p src/main/java/ src/test/java/
touch src/main/java/App.java
vi src/main/java/App.java
touch src/test/java/AppTest.java
vi src/test/java/AppTest.java

compile the Java application

gradle compileJava

Result:

BUILD SUCCESSFUL in 305ms
1 actionable task: 1 up-to-date

Run the Java application on project

gradle run
# gradle :run

Result:

Starting a Gradle Daemon, 2 incompatible and 1 stopped Daemons could not be reused, use --status for details

> Task :run
Hello world.

BUILD SUCCESSFUL in 356ms
2 actionable tasks: 1 executed, 1 up-to-date

Package the Java application

build the Java application

./gradlew clean build

run the Java application on different OS System:

unzip build/distributions/_gradle_java.zip
./_gradle_java/bin/basic_102

Result:

Hello world.

Test the Java application

gradle test

Result:

BUILD SUCCESSFUL in 710ms
3 actionable tasks: 3 executed

View Result for Test:

google-chrome build/reports/tests/test/index.html

Download and Use This complete Project

# Download
git clone -b basic_102 https://github.com/cnruby/gradle_java.git basic_102 \
&& cd basic_102
# 1. Usage for the project

# DO (build and run the application `App`)
./gradlew run
# 2. Usage for OS

# DO (Bundle the project as a distribution)
./gradlew distZip

# DO (Unzip the distribution)
unzip build/distributions/_gradle_java.zip

# DO (run the application `App` for Ubuntu OS)
./_gradle_java/bin/basic_102

# DO (run the application `App` for Winsows OS)
./_gradle_java/bin/basic_102.bat

Tip:

  • Do Not use the command java -jar to run the Java application for the project.

Main References

References

References for Tips