Testing Java Application

This script is setting up Java 17, Maven, and SonarQube to test a Java project stored in a GitHub repository. Here's a step-by-step breakdown:


1️⃣ Install Java 17 and Maven 3.9.2

apt install openjdk-17-jdk -y
  • Installs Java 17 (JDK) on a Linux system.

wget https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.2/apache-maven-3.9.2-bin.tar.gz
tar xzf apache-maven-3.9.2-bin.tar.gz
  • Downloads and extracts Maven 3.9.2, a popular Java build automation tool.

mkdir /usr/share/maven
cd apache-maven-3.9.2
cp -R * /usr/share/maven
  • Creates a Maven installation directory (/usr/share/maven) and copies extracted files.

touch /etc/profile.d/maven.sh
echo 'export M2_HOME=/usr/share/maven' >>/etc/profile.d/maven.sh
echo 'export MAVEN_HOME=/usr/share/maven' >>/etc/profile.d/maven.sh
echo 'export PATH=${M2_HOME}/bin:${PATH}' >>/etc/profile.d/maven.sh
source /etc/profile.d/maven.sh
  • Configures Maven by setting environment variables M2_HOME, MAVEN_HOME, and PATH.

  • Runs source to apply changes immediately.

  • Verifies that Maven is installed correctly.


2️⃣ Clone the Java Project from GitHub

  • Downloads the sonardemo repository, which contains a Java project.

  • Builds the Java project using Maven:

    • clean → Removes old build files.

    • install → Compiles and packages the project.


3️⃣ Generate a SonarQube Token

  • The instructions mention SonarQube, a tool for static code analysis.

  • The user is asked to:

    1. Go to User > My Account > Security in SonarQube.

    2. Generate a new token named "Github_Token".

    3. Copy the generated token.


4️⃣ Run Code Quality Analysis with SonarQube

  • Runs SonarQube static analysis on the project.

  • The -Dsonar.token option provides authentication to SonarQube.

  • The analysis checks for bugs, code smells, security vulnerabilities, and maintainability issues.


💡 Summary

Installs Java 17 and MavenClones a Java project from GitHubBuilds the project using MavenGenerates a SonarQube token for authenticationRuns a SonarQube analysis on the project

🔹 Why is this important? This setup ensures proper software quality control by checking the Java project's build status and code quality before deploying it.

Would you like help automating this setup in a script? 🚀

TOKEN EXPIRED IN 30 MIN

squ_bc4ce2ce1468415a6d43cbc1206d0eebbc1b3dce

Test project

ACCESS TOEKN FOR SONRQUBE REPO

Demo@123

Last updated