I have a multimodule maven project with below structure
test-project(parent)-> packaging is pom
- test-project.ear
- test-project.war
The problem is I am generating a xml file during the mvn deploy phase before the sonar scan and it is generating a xml file under the parent project ,in this case it is generating immediately under the test-project. I want this file to be scanned by Sonar, but sonar seems to scan only the xml files under the ear and war files. Could any one help me on this
I am using SonarQube 4.3.2
SonarQube cannot analyse files that are in aggregator projects (i.e. projects with POM packaging).
Related
I have a multi-module Gradle project (which generates 3 artifacts per module, the sources, javadoc, and main jar). I need to generate a .pom file for my project for use with the Maven Deploy Plugin which is installed on an image that Gitlab CI uses. I have a (WIP) script which generates a .pom file with gradle, but I'm unsure of exactly where or how many .pom files I need for all of my modules.
Questions:
Where exactly should I be generating a .pom file(s) so that the
Maven Deploy Plugin can see it when I run mvn deploy:deploy in the
Gitlab yaml file?
Do I need a separate .pom file for each group of module artifacts?
Any help would be appreciated! Especially some sort of example of someone generating a .pom file with Gradle and then deploying with the Gitlab CI.
I have a simple project that need to Run JUnit test and let SonarQube to scan / run the Test of JUnit result with SonarScanner. I put my project at Github here
There are some problems:
WARN: Class "XXX" is not accessible through the classloader sonar (Reference)
No jacoco-it.exec and jacoco-ut.exec, only run jacoco.exec at SonarScanner
Cannot exclude some files when running Test JUnit, because I only want to Run Test in my Service Folder (Reference)
This is my sonar-project.properties :
# Required metadata
sonar.projectKey=com.example:Sample
sonar.projectName=Java :: Example :: SonarQube Scanner
sonar.projectVersion=1.0
# Comma-separated paths to directories with sources (required)
sonar.sources=src
sonar.exclusions=src/main/resources/**
#sonar.test.inclusions=src/main/java/com/example/service/**, src/test/java/**
#sonar.test.exclusions=src/main/java/com/example/controller/**
# Encoding of the source files
sonar.sourceEncoding=UTF-8
#Jacoco
sonar.junit.reportsPath=target/surefire-reports
sonar.jacoco.reportPath =target/jacoco.exec
sonar.jacoco.reportMissing.force.zero=true
sonar.java.binaries=target/classes/**
#sonar.java.libraries=libs/**
When I Run Maven Test until build success, It create some files and folders in folder Target.
After that I run my SonarScanner to Scan my project, but I got those problems.
My question:
How can I run my SonarQube Scanner without any WARN ?
How to exclude files properly when scanning JUnit result? Because I use the reference settings, and Coverage still scan the files
How to create jacoco-it.exec and jacoco-ut.exec and run it on SonarScanner?
My project is based on this Reference
Use SonarQube Scanner for Maven instead of just SonarQube Scanner. Otherwise you fall into troubles with configuration, into which you fall, because need to do everything manually:
sonar.sources most likely is incorrect - should be src/main/java and will be properly configured by Scanner for Maven, and that's why you're getting undesired test files analysed as main files
as well as sonar.tests that normally for Maven based projects points to src/test/java
sonar.java.libraries is empty and that's why you're getting Class "XXX" is not accessible through the classloader sonar - it might be quite hard to list all required JAR files of dependencies of your Maven project, while again Scanner for Maven will do this automatically and most importantly will do this correctly
sonar.projectKey with Scanner for Maven will be set automatically to Maven groupId:artifactId
sonar.projectName and sonar.version with Scanner for Maven will be set correctly to Maven project name and version respectively, so that you don't need to change version, when it will change in Maven project
others such as sonar.sourceEncoding, sonar.java.binaries, sonar.java.test.binaries and sonar.java.test.libraries with Scanner for Maven will also be set automatically
If needed you'll still be able to provide other additional properties
via command line such as mvn ... sonar:sonar -Dsonar.something=something
or in SonarQube UI
or specify them directly in properties section of pom.xml
How to create jacoco-it.exec and jacoco-ut.exec and run it on SonarScanner?
Usually jacoco-ut.exec refers to coverage data about unit tests and jacoco-it.exec refers to coverage data about integration tests. They are created by jacoco-maven-plugin, in your pom.xml you configured jacoco-maven-plugin for creation of jacoco.exec.
I am new to Maven and know the basic concepts of Maven. I got a requirment to work on mavenizing multiple projects which uses most of common/same jars.
I was asked to build a TAR/ZIP file that contains all the jars and build WAR file for each project with out jars. So that Project (WAR) can use jars present in TAR/ZIP file.
finally after build, TAR/ZIP file needs to be deployed on server forst and later WAR file. so that, in run time WAR can have refrence to jars.
Can anyone please help me in this ?
Actually this structure will reduce size of WAR files as we are keeping these jars in single TAR/ZIP file and deploying it in tomcat server.
I have a root parent maven module which has lot of sub-modules that build jar files as artifacts.
I cannot change all sub-module pom.xml files.
From the root parent pom.xml is there a way I can get a list of all jars (artifacts) built by sub-modules?
Preferably after the package phase is complete?
PS: As a part of root module build I want to generate a report using a tool which requires this list of jar files.
There's a target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst in a Maven project.
You can use the GMavenPlus Plugin and Walking the File Tree to gather these files and put their content where you want.
Another option is to develop an own Maven plugin that does the same.
I need to create a dependent maven project.
The child one should be a jar, that would be called by the parent project which should be a war file.
The steps should be like this. When I build the war, it should automatically build the jar file and include it and build the war and show output of the child jar (suppose a simple print statement).
Note: Build should be done only once and that is for building the final war.
Need to edit the pom.xml accordingly.
I am new to maven,so a bit elaborate solution would be very helpful.