Building SonarQube - linux-on-ibm-z/docs GitHub Wiki
The instructions provided below specify the steps to run SonarQube 25.10.0 on Linux on IBM Z for the following distributions:
- RHEL (8.10, 9.4, 9.6, 10.0)
- SLES (15 SP6,15 SP7)
- Ubuntu (22.04, 24.04, 25.04)
- 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.
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/25.10.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.
export SOURCE_ROOT=/<source_root>/- RHEL (8.10, 9.4, 9.6, 10.0)
sudo yum install -y wget git unzip tar which net-tools curl gzip patch make gcc gcc-c++ jq procps iproute --allowerasing- SLES (15 SP6, 15 SP7)
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, 25.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-
With Eclipse Adoptium Temurin Runtime
- Download and install Eclipse Adoptium Temurin Runtime (Java 21) from here.
-
With OpenJDK 21
- RHEL (8.10, 9.4, 9.6, 10.0)
sudo yum install -y java-21-openjdk-devel
- SLES (15 SP6, 15 SP7)
sudo zypper install -y java-21-openjdk java-21-openjdk-devel
- Ubuntu (22.04, 24.04, 25.04)
sudo apt-get install -y openjdk-21-jdk
- RHEL (8.10, 9.4, 9.6, 10.0)
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.6+7).
SonarQube needs Elasticsearch and the package includes it. However, it does not work properly on s390x therefore we need to build it from source and replace the provided package. Please check this link for more details of building Elasticsearch.
cd $SOURCE_ROOT
PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/SonarQube/25.10.0/patch"
export LANG="en_US.UTF-8"
export ES_JAVA_HOME=$JAVA_HOME
git clone -b v8.17.0 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 --max-workers=`nproc` --parallel
# save the artifact link to an env variable.
export elasticsearch=`pwd`/distribution/archives/linux-s390x-tar/build/distributions/elasticsearch-8.17.0-SNAPSHOT-linux-s390x.tar.gz
# make sure the file exists:
ls -l $elasticsearchcd $SOURCE_ROOT
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-25.10.0.114319.zip
unzip -q sonarqube-25.10.0.114319.zip
wget https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-7.2.0.5079-linux-x64.zip
unzip -q sonar-scanner-cli-7.2.0.5079-linux-x64.ziprm $SOURCE_ROOT/sonarqube-25.10.0.114319/bin/elasticsearch
rm -rfd $SOURCE_ROOT/sonarqube-25.10.0.114319/elasticsearch/*
tar -xzf $elasticsearch -C $SOURCE_ROOT/sonarqube-25.10.0.114319/elasticsearch --strip-components 1
rm -rf $SOURCE_ROOT/sonarqube-${PACKAGE_VERSION}/elasticsearch/modules/x-pack-ml $SOURCE_ROOT/sonarqube-${PACKAGE_VERSION}/elasticsearch/modules/x-pack-esql
cp $SOURCE_ROOT/sonarqube-25.10.0.114319/elasticsearch/bin/elasticsearch $SOURCE_ROOT/sonarqube-25.10.0.114319/bin/sudo groupadd sonarqube # If group is not already created
sudo usermod -aG sonarqube $(whoami)
sudo chown $(whoami):sonarqube -R $SOURCE_ROOT/sonarqube-25.10.0.114319
export PATH=$PATH:$SOURCE_ROOT/sonarqube-25.10.0.114319/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.
Modify $SOURCE_ROOT/sonar-scanner-7.2.0.5079-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-7.2.0.5079-linux-x64/bin/sonar-scannerModify SonarScanner CLI settings:
echo 'sonar.host.url=http://localhost:9000' >> "$SOURCE_ROOT"/sonar-scanner-7.2.0.5079-linux-x64/conf/sonar-scanner.properties
echo 'sonar.scanner.skipJreProvisioning=true' >> "$SOURCE_ROOT"/sonar-scanner-7.2.0.5079-linux-x64/conf/sonar-scanner.propertiesClone sample test cases
cd $SOURCE_ROOT/
git clone https://github.com/SonarSource/sonar-scanning-examples.gitNote: SonarQube no longer supports scanner operations using username and password. A token needs to be generated.
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
$SOURCE_ROOT/sonar-scanner-7.2.0.5079-linux-x64/bin/sonar-scanner -Dsonar.projectKey=myproject -Dsonar.sources=. -Dsonar.token=$SONAR_TOKENOnce 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.
nodejsis 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)- In case of errors encountered similar to
Unsupported architecture: s390xwhile scanning the repo, Follow below steps :
After starting the server, navigate to the UI, then to Administration > General Settings > Languages. From the list, choose Kubernetes and disable the option for Activate Kubernetes analysis.
Alternative, if you want for specific scan, can add-Dsonar.kubernetes.activate=falseflag to the command.
Reference: https://community.sonarsource.com/t/gradle-sonar-arm64-support/107629
- https://docs.sonarsource.com/sonarqube/latest/
- https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner/
- https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/scanners/sonarscanner-for-gradle/
- https://docs.sonarsource.com/sonarqube/latest/analyzing-source-code/languages/javascript-typescript-css/
- https://github.com/linux-on-ibm-z/docs/wiki/Building-Elasticsearch