Building SonarQube - linux-on-ibm-z/docs GitHub Wiki

Building SonarQube

The instructions provided below specify the steps to run SonarQube 26.7.0 on Linux on IBM Z for the following distributions:

  • RHEL (8.10, 9.6, 9.7, 9.8, 10.0, 10.1, 10.2)
  • SLES (15 SP7, 16)
  • Ubuntu (22.04, 24.04)

General Notes:

  • When following the steps below please use a standard permission user unless otherwise specified.
  • A directory /<source_root>/ will be referred to in these instructions, this is a temporary writable directory anywhere you'd like to place it.

1. Build and Install SonarQube

1.1. Build using script

If you want to build SonarQube using manual steps, go to STEP 1.2.

Use the following commands to build sonarqube using the build script. Please make sure you have wget installed.

wget -q https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/SonarQube/26.7.0/build_sonarqube.sh

# Build sonarqube
bash build_sonarqube.sh  [Provide -t option for executing build with tests, -j option to use Java from (Temurin_21, OpenJDK_21). If no -j specified, Temurin_21 will be installed]

If the build completes successfully, go to STEP 3. In case of error, check logs for more details or go to STEP 1.2 to follow manual build steps.

1.2. Install dependencies

export SOURCE_ROOT=/<source_root>/
  • RHEL (8.10, 9.6, 9.7, 9.8, 10.0, 10.1, 10.2)
sudo yum install -y wget git unzip tar which net-tools curl gzip patch make gcc gcc-c++ xz jq procps iproute
  • SLES (15 SP7, 16)
sudo zypper install -y git wget unzip tar which gzip xz net-tools curl patch make gcc gcc-c++ jq procps gawk iproute2
  • Ubuntu (22.04, 24.04)
sudo apt-get update
sudo apt-get install -y wget git unzip tar net-tools xz-utils curl gzip patch locales make gcc g++ jq procps iproute2
sudo locale-gen en_US.UTF-8

1.3. Install Java

  • With Eclipse Adoptium Temurin Runtime

    • Download and install Eclipse Adoptium Temurin Runtime (Java 21) from here.
  • With OpenJDK 21

    • RHEL (8.10, 9.6, 9.7, 10.0, 10.1)
      sudo yum install -y java-21-openjdk-devel
    • SLES (15 SP7, 16 SP0)
      sudo zypper install -y java-21-openjdk java-21-openjdk-devel
    • Ubuntu (22.04, 24.04)
      sudo apt-get install -y openjdk-21-jdk

Note:

  • Environment variable JAVA_HOME and PATH needs to be updated for the installed Java version.
  • At the time of creating these build instructions, SonarQube was verified with: Eclipse Adoptium Temurin Runtime (build jdk-21.0.11+10).
  • SonarQube supports Temurin 21 and OpenJDK 21. However, Elasticsearch must be built using Temurin 21.

2. Build Elasticsearch

The Elasticsearch component bundled with SonarQube is not compatible with the s390x architecture. Therefore, it is necessary to build Elasticsearch from source for s390x and replace the pre-packaged binary to ensure proper functionality.

Note: Elasticsearch 8.19.x requires JDK 17 as the Gradle build toolchain. Before building Elasticsearch, install Java 17 from here and set the RUNTIME_JAVA_HOME environment variable to the JDK 17 installation path.

cd $SOURCE_ROOT
PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/SonarQube/26.7.0/patch"
export LANG="en_US.UTF-8"
export ES8_OPTS="-x libs:entitlement:qa:entitlement-test-plugin:compileMain19Java -x :libs:entitlement:compileMain19Java -x :libs:entitlement:compileMain20Java -x :libs:entitlement:qa:entitlement-test-plugin:compileMain20Java -x :libs:native:compileMain20Java -x :libs:native:compileMain22Java -x :libs:simdvec:compileMain22Java -x :libs:entitlement:compileMain25Java -x :libs:entitlement:qa:entitlement-test-plugin:compileMain25Java -x :libs:entitlement:compileMain26Java -x :libs:entitlement:qa:entitlement-test-plugin:compileMain26Java"
export ES_JAVA_HOME=$JAVA_HOME

#Install Zstd
wget -q https://github.com/facebook/zstd/archive/refs/tags/v1.5.5.tar.gz
tar -xzf v1.5.5.tar.gz
cd zstd-1.5.5
make -j$(nproc) lib
make DESTDIR=$(pwd)/_build install

#Clone and build elasticsearch 
git clone -b v8.19.16 https://github.com/elastic/elasticsearch
cd elasticsearch

curl -sSL $PATCH_URL/elasticsearch.diff | git apply -

git fetch --tags
latest_tag=$(git tag | sort -V | tail -n1)
latest_tag="${latest_tag:1}-SNAPSHOT"
sed -i 's|${project.version}|'"${latest_tag}"'|g' $SOURCE_ROOT/elasticsearch/x-pack/plugin/ml/build.gradle

mkdir -p $SOURCE_ROOT/elasticsearch/distribution/packages/s390x-rpm/
mkdir -p $SOURCE_ROOT/elasticsearch/distribution/packages/s390x-deb/
mkdir -p $SOURCE_ROOT/elasticsearch/distribution/archives/linux-s390x-tar/
mkdir -p $SOURCE_ROOT/elasticsearch/distribution/docker/ubi-docker-s390x-export/
mkdir -p $SOURCE_ROOT/elasticsearch/distribution/docker/cloud-docker-s390x-export/
mkdir -p $SOURCE_ROOT/elasticsearch/distribution/docker/cloud-ess-docker-s390x-export/
mkdir -p $SOURCE_ROOT/elasticsearch/distribution/docker/docker-s390x-export/
mkdir -p $SOURCE_ROOT/elasticsearch/distribution/docker/ironbank-docker-s390x-export/
./gradlew :distribution:archives:linux-s390x-tar:assemble $ES8_OPTS --max-workers=`nproc`  --parallel

# save the artifact link to an env variable.
export elasticsearch=`pwd`/distribution/archives/linux-s390x-tar/build/distributions/elasticsearch-8.19.16-SNAPSHOT-linux-s390x.tar.gz

# make sure the file exists:
ls -l $elasticsearch

3. Download and extract SonarQube and sonar-scanner-cli

cd $SOURCE_ROOT
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-26.7.0.124771.zip
unzip -q sonarqube-26.7.0.124771.zip
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-8.1.0.6389-linux-x64.zip
unzip -q sonar-scanner-cli-8.1.0.6389-linux-x64.zip

4. Replace elasticsearch in SonarQube package

rm $SOURCE_ROOT/sonarqube-26.7.0.124771/bin/elasticsearch
rm -rfd $SOURCE_ROOT/sonarqube-26.7.0.124771/elasticsearch/*
tar -xzf $elasticsearch -C $SOURCE_ROOT/sonarqube-26.7.0.124771/elasticsearch --strip-components 1
rm -rf $SOURCE_ROOT/sonarqube-26.7.0.124771/elasticsearch/modules/x-pack-ml $SOURCE_ROOT/sonarqube-26.7.0.124771/elasticsearch/modules/x-pack-esql
rm -rf $SOURCE_ROOT/sonarqube-26.7.0.124771/elasticsearch/modules/blob-cache $SOURCE_ROOT/sonarqube-26.7.0.124771/elasticsearch/modules/searchable-snapshots
cp $SOURCE_ROOT/sonarqube-26.7.0.124771/elasticsearch/bin/elasticsearch $SOURCE_ROOT/sonarqube-26.7.0.124771/bin/

5. Run SonarQube (Optional)

# for SLES 16
sudo /usr/sbin/groupadd sonarqube
sudo /usr/sbin/usermod -aG sonarqube $(whoami)

# for other distros
sudo groupadd sonarqube      # If group is not already created
sudo usermod -aG sonarqube $(whoami)

sudo chown $(whoami):sonarqube -R $SOURCE_ROOT/sonarqube-26.7.0.124771
export PATH=$PATH:$SOURCE_ROOT/sonarqube-26.7.0.124771/bin/linux-x86-64
export SONAR_JAVA_PATH=$JAVA_HOME/bin/java
sonar.sh start
echo 'use `sonar.sh stop` to stop sonarqube'

Note: SonarQube cannot be run as root on Unix-based systems, so create a dedicated user account to use for SonarQube if necessary which has standard permission rights, hence we have changed the owner in the above step. Click here to know more about configuration.

6. Run Testcases which cover Java, JavaScript, Python, PHP and more (Optional)

Modify $SOURCE_ROOT/sonar-scanner-8.1.0.6389-linux-x64/bin/sonar-scanner to use system JVM.

sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' $SOURCE_ROOT/sonar-scanner-8.1.0.6389-linux-x64/bin/sonar-scanner

Modify SonarScanner CLI settings:

echo 'sonar.host.url=http://localhost:9000' >> "$SOURCE_ROOT"/sonar-scanner-8.1.0.6389-linux-x64/conf/sonar-scanner.properties
echo 'sonar.scanner.skipJreProvisioning=true' >> "$SOURCE_ROOT"/sonar-scanner-8.1.0.6389-linux-x64/conf/sonar-scanner.properties

Clone sample test cases

cd $SOURCE_ROOT/
git clone https://github.com/SonarSource/sonar-scanning-examples.git

Generate sonar token. A token named my-token can be generated by using below command.

SONAR_TOKEN=$(curl -u admin:admin -X POST "http://localhost:9000/api/user_tokens/generate" -d "name=my-token" | jq -r .token)

For other languages, you can follow the following. For instance, for python, you can do:

cd $SOURCE_ROOT/sonar-scanning-examples/sonar-scanner/src/python
sed -i '6isonar.sources=.' sonar-project.properties
sed -i '7isonar.exclusions=tests/**' sonar-project.properties
$SOURCE_ROOT/sonar-scanner-8.1.0.6389-linux-x64/bin/sonar-scanner -Dsonar.projectKey=myproject -Dsonar.sources=. -Dsonar.token=$SONAR_TOKEN

Once the scanner completes, its analysis results will be posted to SonarQube server for viewing. Results can be accessed by pointing a supported browser to http://<HOST_IP>:9000/.

Note:

  • You can run scanner for JavaScript, PHP in the same way as above. Just make sure you are in the appropriate base directory of the project you are testing.
  • nodejs is required to run scanner for JavaScript. Download Node.js from here. (At the time of creating these build instructions, nodejs v24.2.0 was verified)

References:

⚠️ **GitHub.com Fallback** ⚠️