/gradle-webdemo

https://guides.gradle.org/building-java-web-applications

Primary LanguageJava

Building Java Web Applications

https://guides.gradle.org/building-java-web-applications/

What you’ll need

Install Java distribution on Ubuntu

$ sudo apt install default-jre default-jdk
$ java --version
$ javac --version
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
$ sudo echo 'JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64/bin/"' >> /etc/environment

Install Gradle distribution

$ curl -s "https://get.sdkman.io" | bash
$ sdk version
SDKMAN 5.7.4+362
$ sdk install gradle 6.3

Create the structure of a web application

https://docs.gradle.org/4.10.3/userguide/war_plugin.html

mkdir -p webdemo/src/main/java
mkdir -p webdemo/src/main/webapp
mkdir -p webdemo/src/test/java

Add a Gradle build file

$ touch webdemo/build.gradle.kts
$ gradle wrapper --gradle-version=6.3

Run the application

  • Add a servlet and metadata to the project
  • JSP pages to the demo application
  • Add gretty plugin and run the app

gradle/gradle#11843

Unit test the servlet using Mockito

https://site.mockito.org/

$ ./gradlew test
$ ./gradlew build

Add a functional test