Docker builds the code detection platform SonarQube and detects the process of Maven projects

Docker builds the code detection platform SonarQube and detects the process of Maven projects

1 Introduction

Good coding habits are qualities that a good programmer should possess, but relying on people's habits and memory to ensure code quality is not always a reliable thing. People in the computer industry should be well aware that as long as it is man-made, there will be operational risks. This article explains how to build the code detection platform SonarQube through Docker and use it to detect the code of maven projects.

2 Install SonarQube with Docker

2.1 Installation

Installation through Docker is quick and easy. You can simply delete the container and image when you don’t need it.

# Pull the Sonar image docker pull sonarqube:8.3.1-community
# Run the example docker run --name sonarqube -p 9000:9000 -d sonarqube:8.3.1-community

Then visit: http://localhost:9000/, the default administrator user and password are: admin/admin .

Here we choose the free Community version. There are also paid versions such as Developer and Enterprise , which have more powerful functions. The specific differences are as follows:

2.2 Specifying a database

Generally we will start a database such as Oracle , MySQL or PostgreSQL ourselves. Relevant system information can be viewed in Administration-System . If we do not specify, the embedded H2 database is used by default. If you want to specify another database, you need to specify it when starting Docker:

-e SONARQUBE_JDBC_USERNAME="xxx" \
-e SONARQUBE_JDBC_PASSWORD="***" \
-e SONARQUBE_JDBC_URL="jdbc:mysql://xxx"

Using the H2 database has the following limitations:

The embedded database can only be used in testing scenarios. The embedded database cannot be extended or upgraded to new versions of SonarQube, and does not support migrating your data to other database engines.

Therefore, it is recommended not to use the embedded H2 database in actual use.

2.3 Entering the container

By command:

$ docker exec -it container_id bash

bash-5.0# ls
COPYING bin conf data elasticsearch extensions lib logs temp web
bash-5.0#

Can enter the SonarQube container. In the directory /opt/sonarqube you can view configuration files, plug-ins, data files, log files, etc. The actual use should be mapped to the directory of the host machine, so that when you restart an instance, the data and configuration are still there.

2.4 Installing plugins

SonarQube provides powerful plug-in management functions. Taking the Chinese language pack as an example, we will explain how to install the plug-in:

Administration-Marketplace-Plugins , enter Chinese in the search box and choose to install it.

When the status shows Install Pending , the plug-in installation is complete. Click Restart Server to take effect.

3. Detect code through Maven

3.1 Use by account and password

Specify the address of the SonarQube platform and specify the username and password to detect the code. The specific commands are as follows:

mvn clean verify sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=admin -Dsonar.password=admin

3.2 Use via Token

Of course, it is not a good habit to directly use admin and expose the password. You can create a user and a token through配置-權限-用戶.

Copy the token: 9656c84090b2481db6ea97b6d14d87d546bff619 .

In this way, you can operate through the token:

mvn clean verify sonar:sonar -Dsonar.host.url=http://localhost:9000 -Dsonar.login=9656c84090b2481db6ea97b6d14d87d546bff619

After executing the command, a new project will be automatically created on the interface and the detection results will be given:

Sonar provides many indicators such as test coverage, complexity, etc., which can greatly help us write better code:

4 Conclusion

SonarQube is powerful and is one of the important DevOps tools that needs to be understood and mastered.

This is the end of this article about using Docker to build the code detection platform SonarQube and detect Maven projects. For more related content about using Docker to build the code detection platform SonarQube and detect Maven projects, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to build sonarqube using docker

<<:  VUE implements token login verification

>>:  Solve the problem of invalid utf8 settings in mysql5.6

Recommend

MySQL scheduled full database backup

Table of contents 1. MySQL data backup 1.1, mysql...

Future-oriented all-round web design: progressive enhancement

<br />Original: Understanding Progressive En...

MySQL master-slave principle and configuration details

MySQL master-slave configuration and principle, f...

Some tips on deep optimization to improve website access speed

Some tips for deep optimization to improve websit...

Summary of the advantages of Vue3 vs. Vue2

Table of contents 1. Why do we need vue3? 2. Adva...

Q&A: Differences between XML and HTML

Q: I don’t know what is the difference between xml...

JavaScript countdown to close ads

Using Javascript to implement countdown to close ...

Docker large-scale project containerization transformation

Virtualization and containerization are two inevi...

Native JS music player

This article example shares the specific code of ...

Detailed tutorial on installation and configuration of MySql 5.7.17 winx64

1. Download the software 1. Go to the MySQL offic...

A detailed introduction to wget command in Linux

Table of contents First install wget View Help Ma...

Detailed Explanation of JavaScript Framework Design Patterns

Table of contents mvc mvp mvvm The source of Vue ...

Element table header row height problem solution

Table of contents Preface 1. Cause of the problem...