DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Express Hibernate Queries as Type-Safe Java Streams
  • How to Publish Artifacts to Maven Central
  • Recipe To Implement the Jenkins Pipeline For MuleSoft Application [Videos]
  • ITBench, Part 1: Next-Gen Benchmarking for IT Automation Evaluation

Trending

  • Introducing Graph Concepts in Java With Eclipse JNoSQL, Part 2: Understanding Neo4j
  • IoT and Cybersecurity: Addressing Data Privacy and Security Challenges
  • Introduction to Retrieval Augmented Generation (RAG)
  • The Perfection Trap: Rethinking Parkinson's Law for Modern Engineering Teams
  1. DZone
  2. Coding
  3. Java
  4. Configuring Sonar with Maven

Configuring Sonar with Maven

By 
Valdemar Júnior user avatar
Valdemar Júnior
·
Mar. 21, 11 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
143.1K Views

Join the DZone community and get the full member experience.

Join For Free

Sonar is an open source web-based application to manage code quality which covers seven axes of code quality as: Architecture and design, comments, duplications, unit tests, complexity, potential bugs and coding rules. Developed in Java and can cover projects in Java, Flex, PHP, PL/SQL, Cobol and Visual Basic 6.

It's very efficient to navigate, offering visual reporting and you can follow metrics evolution of your project and combine them.

There is an online project called Nemo dedicated to open source projects, as you can see projects like Jetty, Apache Lucene and Apache Tomcat.

So, let's config Sonar to work together with Maven. First of all set up Sonar server and other configurations  in Maven's settings.xml file:

<profile>   <id>sonar</id>   <activation>      <activeByDefault>true</activeByDefault>   </activation>   <properties>      <sonar.jdbc.url>jdbc:postgresql://localhost/sonar</sonar.jdbc.url>      <sonar.jdbc.driver>org.postgresql.Driver</sonar.jdbc.driver>      <sonar.jdbc.username>user</sonar.jdbc.username>      <sonar.jdbc.password>password</sonar.jdbc.password>      <!-- SERVER ON A REMOTE HOST -->      <sonar.host.url>http://localhost:9000</sonar.host.url>   </properties></profile>

You must to have a Sonar server running and define it in sonar.host.url parameter. In this example I'm using the default Sonar URL, http://localhost:9000 , and you must set user name and password for your database. To install local Sonar Server you can see this link.

After that, to execute the code analysers and save results in Sonar database just execute mvn sonar:sonar. You can config Sonar to execute in your CI (Continuous Integration) application.  Hudson is a  perfect match, because there is a Sonar plugin for it. See the final result below:

 

I prefer Teamcity CI, but there isn't a stable plugin as you can see in compatibility matrix. To resolve this plugin's problem, just add sonar:sonar in the maven command executed by Teamcity.

Sonar is an essential tool for your software project to help you evaluating how cohesive your classes are, warning for future problems as code complexity or duplication problems arise, and will help you to have a cleaner code. 

If you have any question or some difficulties, contact me.

Apache Maven Open source

Opinions expressed by DZone contributors are their own.

Related

  • Express Hibernate Queries as Type-Safe Java Streams
  • How to Publish Artifacts to Maven Central
  • Recipe To Implement the Jenkins Pipeline For MuleSoft Application [Videos]
  • ITBench, Part 1: Next-Gen Benchmarking for IT Automation Evaluation

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!