Building SonarQube - linux-on-ibm-z/docs GitHub Wiki
The instructions provided below specify the steps to run SonarQube version 26.9.0 on Linux on IBM Z for the following distributions:
- RHEL (8.10, 9.6, 9.8, 10.0, 10.2)
- SLES (15 SP7, 16)
- Ubuntu (22.04, 24.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/26.9.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>/
export PATCH_URL="https://raw.githubusercontent.com/linux-on-ibm-z/scripts/master/SonarQube/26.9.0/patch"- RHEL 8.10
sudo yum install -y wget git unzip tar which net-tools curl gzip patch make gcc gcc-c++ xz jq procps iproute bzip2 zip python3.11 python3.11-devel python3.11-pip cmake ninja-build zlib-devel libxml2-devel gcc-toolset-13 gcc-toolset-13-gcc gcc-toolset-13-gcc-c++ gcc-toolset-13-binutils- RHEL (9.6, 9.8, 10.0, 10.2)
sudo yum install -y wget git unzip tar which net-tools curl gzip patch make gcc gcc-c++ xz jq procps iproute bzip2 zip python3 python3-devel python3-pip cmake ninja-build zlib-devel libxml2-devel- SLES 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 bzip2 zip python311 python311-devel python311-pip cmake ninja zlib-devel libxml2-devel gcc15 gcc15-c++- SLES 16
sudo zypper install -y git wget unzip tar which gzip xz net-tools curl patch make gcc gcc-c++ jq procps gawk iproute2 bzip2 zip python313 python313-devel python313-pip cmake ninja zlib-devel libxml2-devel gcc15 gcc15-c++- Ubuntu (22.04, 24.04)
sudo apt-get update
sudo DEBIAN_FRONTEND=noninteractive apt-get install -y wget git unzip tar net-tools xz-utils curl gzip patch locales make gcc g++ jq procps iproute2 bzip2 zip zlib1g-dev libxml2-dev python3 python3-dev python3-pip cmake ninja-build
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.6, 9.8, 10.0, 10.2)
sudo yum install -y java-21-openjdk-devel
- SLES (15 SP7, 16)
sudo zypper install -y java-21-openjdk-devel
- Ubuntu (22.04, 24.04)
sudo apt-get install -y openjdk-21-jdk
- RHEL (8.10, 9.6, 9.8, 10.0, 10.2)
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.
- Java 17 is used while building ml-cpp.
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 9.4.3 is built using Temurin 21. Java 17 is required while building ml-cpp. Install Java 17 from here under /opt/java17, as it is used by the ml-cpp build.
cd $SOURCE_ROOT
export LANG="en_US.UTF-8"
export ES_JAVA_HOME=$JAVA_HOME
# Build ml-cpp for Elasticsearch 9.4.3
rm -rf "$SOURCE_ROOT/ml-cpp"
rm -rf /tmp/mlcpp-ivy
git clone --depth 1 -b v9.4.3 https://github.com/elastic/ml-cpp.git
cd "$SOURCE_ROOT/ml-cpp"
curl -sSL "$PATCH_URL/ml-cpp.patch" | git apply -
chmod +x s390x/build_ml_cpp.sh
export PACKAGE_VERSION="9.4.3"
export ML_CPP_REPO="/tmp/mlcpp-ivy"
export ML_CPP_SOURCE_DIR="$SOURCE_ROOT/ml-cpp"
export ML_CPP_JAVA_HOME="/opt/java17"
# For RHEL 8.10 and SLES 15 SP7:
export PYTHON_BIN="python3.11"
# For SLES 16:
export PYTHON_BIN="python3.13"
# For RHEL 9.x,10.x and Ubuntu:
export PYTHON_BIN="python3"
bash "$SOURCE_ROOT/ml-cpp/s390x/build_ml_cpp.sh"
ML_CPP_GRADLE_OPTS="-Dbuild.ml_cpp.repo=file:///tmp/mlcpp-ivy"
#Install Zstd
cd $SOURCE_ROOT
wget -q https://github.com/facebook/zstd/archive/refs/tags/v1.5.7.tar.gz
tar -xzf v1.5.7.tar.gz
cd zstd-1.5.7
make -j$(nproc) lib
make DESTDIR=$(pwd)/_build install
#Clone and build elasticsearch
cd $SOURCE_ROOT
git clone -b v9.4.3 https://github.com/elastic/elasticsearch.git
cd elasticsearch
curl -sSL "$PATCH_URL/elasticsearch.patch" | git apply -
sed -i "s#%S390X_ZSTD_DEP_DIR%#$SOURCE_ROOT/zstd-native-dep#g" \
"$SOURCE_ROOT/elasticsearch/libs/native/libraries/build.gradle"
# Build JANSI for s390x
cd $SOURCE_ROOT
rm -rf jansi jansi-jar
git clone --depth 1 -b jansi-2.4.0 https://github.com/fusesource/jansi.git
cd jansi
make clean-native native OS_NAME=Linux OS_ARCH=s390x
mkdir -p $SOURCE_ROOT/jansi-jar
cd $SOURCE_ROOT/jansi-jar
wget -q https://repo1.maven.org/maven2/org/fusesource/jansi/jansi/2.4.0/jansi-2.4.0.jar
jar xf jansi-2.4.0.jar
mkdir -p org/fusesource/jansi/internal/native/Linux/s390x
cp $SOURCE_ROOT/jansi/target/native-Linux-s390x/libjansi.so \
org/fusesource/jansi/internal/native/Linux/s390x/
jar cf jansi-2.4.0.jar .
export GRADLE_USER_HOME="$SOURCE_ROOT/.gradle"
mkdir -p $GRADLE_USER_HOME/caches/modules-2/files-2.1/org.fusesource.jansi/jansi/2.4.0/321c614f85f1dea6bb08c1817c60d53b7f3552fd/
cp jansi-2.4.0.jar \
$GRADLE_USER_HOME/caches/modules-2/files-2.1/org.fusesource.jansi/jansi/2.4.0/321c614f85f1dea6bb08c1817c60d53b7f3552fd/
jansi_sha256=$(sha256sum jansi-2.4.0.jar | awk '{print $1}')
sed -i -e \
's|6cd91991323dd7b2fb28ca93d7ac12af5a86a2f53279e2b35827b30313fd0b9f|'"${jansi_sha256}"'|g' \
-e 's|616491ff68183f90e145b68874627742d796572dbfe4d8dfe64bac22a27864cb|'"${jansi_sha256}"'|g' \
$SOURCE_ROOT/elasticsearch/gradle/verification-metadata.xml
# Create Zstd native dependency
cd $SOURCE_ROOT
mkdir -p $SOURCE_ROOT/zstd-native-dep/artifacts/linux-s390x
cp $SOURCE_ROOT/zstd-1.5.7/lib/libzstd.so \
$SOURCE_ROOT/zstd-1.5.7/LICENSE \
$SOURCE_ROOT/zstd-native-dep/artifacts/linux-s390x/
jar --create \
--no-manifest \
--file $SOURCE_ROOT/zstd-native-dep/zstd-1.5.7-linux-s390x.jar \
-C $SOURCE_ROOT/zstd-native-dep/artifacts/ .
# Create s390x distribution directories
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/docker-s390x-export/
touch $SOURCE_ROOT/elasticsearch/distribution/packages/s390x-rpm/build.gradle
touch $SOURCE_ROOT/elasticsearch/distribution/packages/s390x-deb/build.gradle
touch $SOURCE_ROOT/elasticsearch/distribution/archives/linux-s390x-tar/build.gradle
touch $SOURCE_ROOT/elasticsearch/distribution/docker/docker-s390x-export/build.gradle
# Build Elasticsearch
cd $SOURCE_ROOT/elasticsearch
export LOCAL_VEC_BINARY_OS=linux-s390x
./gradlew --stop >/dev/null 2>&1 || true
ES9_EXCLUDED_TASKS=(
":libs:entitlement:bridge:compileMain22Java"
":libs:entitlement:bridge:compileMain23Java"
":libs:entitlement:compileMain22Java"
":libs:entitlement:compileMain23Java"
":libs:entitlement:compileMain25Java"
":libs:entitlement:compileMain26Java"
":libs:native:compileMain22Java"
":libs:simdvec:compileMain22Java"
)
ES9_OPTS=""
for task in "${ES9_EXCLUDED_TASKS[@]}"; do
./gradlew -q help --task "$task" >/dev/null 2>&1 \
&& ES9_OPTS="$ES9_OPTS -x $task" \
|| true
done
./gradlew \
:distribution:archives:linux-s390x-tar:assemble \
$ES9_OPTS \
$ML_CPP_GRADLE_OPTS \
--max-workers=`nproc` \
--parallel
# save the artifact link to an env variable.
export elasticsearch=`pwd`/distribution/archives/linux-s390x-tar/build/distributions/elasticsearch-9.4.3-SNAPSHOT-linux-s390x.tar.gz
# make sure the file exists:
ls -l $elasticsearchcd $SOURCE_ROOT
wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-26.9.0.129388.zip
unzip -q sonarqube-26.9.0.129388.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.ziprm $SOURCE_ROOT/sonarqube-26.9.0.129388/bin/elasticsearch
rm -rfd $SOURCE_ROOT/sonarqube-26.9.0.129388/elasticsearch/*
tar -xzf $elasticsearch -C $SOURCE_ROOT/sonarqube-26.9.0.129388/elasticsearch --strip-components 1
rm -rf $SOURCE_ROOT/sonarqube-26.9.0.129388/elasticsearch/modules/blob-cache $SOURCE_ROOT/sonarqube-26.9.0.129388/elasticsearch/modules/searchable-snapshots
cp $SOURCE_ROOT/sonarqube-26.9.0.129388/elasticsearch/bin/elasticsearch $SOURCE_ROOT/sonarqube-26.9.0.129388/bin/# 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.9.0.129388
chmod 755 $SOURCE_ROOT/sonarqube-26.9.0.129388/bin/linux-x86-64/sonar.sh
mkdir -p $SOURCE_ROOT/sonarqube-26.9.0.129388/elasticsearch/lib/platform/linux-s390x
cp $SOURCE_ROOT/zstd-1.5.7/lib/libzstd.so $SOURCE_ROOT/sonarqube-26.9.0.129388/elasticsearch/lib/platform/linux-s390x/
export PATH=$PATH:$SOURCE_ROOT/sonarqube-26.9.0.129388/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-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-scannerModify 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.propertiesClone sample test cases
cd $SOURCE_ROOT/
git clone https://github.com/SonarSource/sonar-scanning-examples.gitGenerate 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_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)
- 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