Skip to main content

sonar_generate_config

Generate sonar-project.properties file for SonarQube scanning.

Description

Creates a custom sonar-project.properties configuration file based on your project structure. Use this when automatic setup fails or you need custom configuration for complex projects.

Parameters

ParameterTypeRequiredDefaultDescription
projectPathstringNoCurrent directoryProject directory
configobjectYes-Configuration options

Config Object

PropertyTypeRequiredDescription
sourcesstringYesSource directories (comma-separated)
testsstringNoTest directories
exclusionsstringNoExclusion patterns
projectKeystringNoProject key (uses existing if available)
projectNamestringNoDisplay name
projectVersionstringNoVersion string
encodingstringNoSource encoding (default: UTF-8)
coverageReportPathsstringNoCoverage report location
javaBinariesstringNoJava .class files location
javaLibrariesstringNoJava libraries path
modulesarrayNoMulti-module configuration
additionalPropertiesobjectNoExtra SonarQube properties

Usage

Basic Configuration

Generate a SonarQube config for my TypeScript project

Tool call:

{
"config": {
"sources": "src",
"tests": "tests",
"exclusions": "**/node_modules/**,**/dist/**"
}
}

With Coverage

Generate config with coverage reporting

Tool call:

{
"config": {
"sources": "src",
"tests": "__tests__",
"exclusions": "**/node_modules/**,**/coverage/**",
"coverageReportPaths": "coverage/lcov.info"
}
}

Multi-Module Project

Generate config for our monorepo

Tool call:

{
"config": {
"sources": ".",
"modules": [
{
"name": "frontend",
"baseDir": "packages/frontend",
"sources": "src",
"tests": "tests"
},
{
"name": "backend",
"baseDir": "packages/backend",
"sources": "src",
"tests": "tests",
"language": "typescript"
}
]
}
}

Java Project

Generate config for our Java Maven project

Tool call:

{
"config": {
"sources": "src/main/java",
"tests": "src/test/java",
"javaBinaries": "target/classes",
"javaLibraries": "target/dependency/*.jar",
"exclusions": "**/target/**"
}
}

Response Format

CONFIGURATION GENERATED
━━━━━━━━━━━━━━━━━━━━━━━

✅ Created: sonar-project.properties

📁 Location: /Users/dev/myproject/sonar-project.properties

GENERATED CONTENT:
──────────────────────────────────────────────────────
# SonarQube Project Configuration
# Generated by Bob the Fixer

sonar.projectKey=myproject-a1b2c3d4
sonar.projectName=My Project
sonar.projectVersion=1.0.0

# Source Configuration
sonar.sources=src
sonar.tests=tests
sonar.exclusions=**/node_modules/**,**/dist/**

# Encoding
sonar.sourceEncoding=UTF-8

# Coverage
sonar.javascript.lcov.reportPaths=coverage/lcov.info
──────────────────────────────────────────────────────

NEXT STEPS:

1. Review the generated configuration
2. Modify if needed for your project
3. Run: sonar_scan_project to analyze

NOTES:
• File will be used automatically by sonar_scan_project
• Commit to version control for team sharing
• Add sensitive values via environment variables

Generated Properties Reference

Standard Properties

# Project identification
sonar.projectKey=unique-project-key
sonar.projectName=Human Readable Name
sonar.projectVersion=1.0.0

# Source configuration
sonar.sources=src
sonar.tests=tests,**/*.test.ts
sonar.sourceEncoding=UTF-8

# Exclusions
sonar.exclusions=**/node_modules/**,**/dist/**,**/*.spec.ts
sonar.test.exclusions=**/fixtures/**

Language-Specific

# TypeScript/JavaScript
sonar.typescript.tsconfigPath=tsconfig.json
sonar.javascript.lcov.reportPaths=coverage/lcov.info

# Java
sonar.java.binaries=target/classes
sonar.java.libraries=target/dependency/*.jar
sonar.java.source=17

# Python
sonar.python.coverage.reportPaths=coverage.xml
sonar.python.version=3.11

Multi-Module

# Module definitions
sonar.modules=frontend,backend,shared

# Frontend module
frontend.sonar.projectBaseDir=packages/frontend
frontend.sonar.sources=src
frontend.sonar.tests=tests

# Backend module
backend.sonar.projectBaseDir=packages/backend
backend.sonar.sources=src
backend.sonar.tests=tests

Examples

Example 1: React Application

Prompt:

Generate config for my React app with Jest coverage

Tool Call:

{
"config": {
"sources": "src",
"tests": "src/**/*.test.tsx,src/**/*.test.ts",
"exclusions": "**/node_modules/**,**/build/**,**/*.stories.tsx",
"coverageReportPaths": "coverage/lcov.info",
"additionalProperties": {
"sonar.typescript.tsconfigPath": "tsconfig.json"
}
}
}

Example 2: Python Django

Prompt:

Generate config for our Django project

Tool Call:

{
"config": {
"sources": ".",
"tests": "tests",
"exclusions": "**/migrations/**,**/venv/**,**/__pycache__/**",
"additionalProperties": {
"sonar.python.coverage.reportPaths": "coverage.xml",
"sonar.python.version": "3.11"
}
}
}

Example 3: Nx Monorepo

Prompt:

Generate config for our Nx monorepo with multiple apps

Tool Call:

{
"config": {
"sources": ".",
"modules": [
{
"name": "web-app",
"baseDir": "apps/web",
"sources": "src",
"tests": "src/**/*.spec.ts"
},
{
"name": "api",
"baseDir": "apps/api",
"sources": "src",
"tests": "src/**/*.spec.ts"
},
{
"name": "shared-ui",
"baseDir": "libs/shared-ui",
"sources": "src",
"tests": "src/**/*.spec.tsx"
}
],
"exclusions": "**/node_modules/**,**/dist/**"
}
}

When to Use

ScenarioUse This Tool
Auto-setup failed
Complex project structure
Multi-module monorepo
Custom exclusions needed
Simple single-language project❌ Use sonar_auto_setup

Best Practices

  1. Start with auto_setup - Only use this if needed
  2. Review generated config - May need adjustments
  3. Version control - Commit properties file
  4. Environment variables - Don't hardcode tokens

Common Issues

"Sources not found"

Cause: Wrong source path in configuration.

Solution: Verify paths exist relative to project root.

"Module not found"

Cause: Incorrect baseDir in module config.

Solution: Use paths relative to project root.

"Analysis fails after generation"

Cause: Missing or incorrect properties.

Solution:

  1. Check language-specific requirements
  2. Verify exclusions don't exclude sources
  3. Run sonar_project_discovery first