I am setting up Sonar through Jenkins Sonar plugin and I have a couple of questions about the way Sonar interprets the directories I give it.
sources=srcDir1,srcDir2 : from what I understand this is where I pass source dir of my project. My project is actually a multiproject with many source dirs inside. Is it okay to give Sonar the root path to the project and Sonar will know to go deep and find each projects .java files ? Or do I have to give it each one of the source dirs ? Also if I have src/com/mycompany/myproj/... package structure do I have to give it the end path, or the src path is sufficient ?
binaries=binDir : Here I should give Sonar the path to the compiled .class code or the packed .jar / .war / .ear files so Findbugs will work. Same question here: I don't have a central place with all the compiled classes, so do I have to specify each one of the paths ?
The Sonar ANT task contains a section on how to configure Sonar to analysis a multi-module build:
http://docs.codehaus.org/display/SONAR/Analyzing+with+Ant+Task
Related
My project structure looks like this:
services
A
a1
a2
pom.xml
B
b1
b2
pom.xml
pom.xml
I would like to scan the inner-most projects (a1,a2,b1,b2). In jenkins Post Steps, I added "Analysis properties" in Execute SonarQube Scanner without property files, mainly:
sonar.modules=A,B
sonar.sources=src
I would like to build from services directory, but it failed with this ERROR:
The folder 'src' does not exist for 'A:a1'
I understand, that SonarQube tries to find src inside the directory A, but I have a few nested projects like a1 (I also tried A.modules=a1,a2 without success)
How can I make the scanner analyze these projects?
this is my solution:
sonar.modules=A,B
A.sonar.modules=a1,a2
B.sonar.modules=b1,b2
sonar.projectBaseDir=.
sonar.sources=src
the key point is projectBaseDir ,I hope this can help someone meet the similar problem.
Use the maven goal sonar:sonar instead of a sonar.properties configuration, when analyzing maven projects with SonarQube.
You should not even have to change any analysis property, when using maven. The maven configuration will already give sonar information about source folders, etc. Check the official documentation on how to set it up. Usually you do not have to change the pom.xml of the projects for this (only you local maven settings.xml).
I have a project with different modules bundled into each others.
We build with ant and I have no problem running the Ant build inside Intellij if I provide the path to the generic build files through a property (repository.dir : C:/myRepositoryFolder).
Similarly, I have no problem running my ant build in command line given I have set my environment variable ANT-OPTS with -Drepository.dir=C:/myRepositoryFolder
However, Intellij does not know where to find this folder and therefore the inspection 'Ant inspections / Ant references resolve problems' blow off on most of my build.xml.
Does anybody know where I can show Intellij where to find this folder without modifying my existent build.properties?
Thanks in advance!
I want to open Nutch 2.1 source file (http://www.eu.apache.org/dist/nutch/2.1/) at Intellij IDEA. Here is an explanation of how to open it at Eclipse: http://wiki.apache.org/nutch/RunNutchInEclipse
However I am not familiar with Ant (I use Maven) and when I open that source file many classes are not known by Intellij.
i.e.:
org.apache.hadoop.mapreduce.JobContext
org.apache.gora.mapreduce.GoraMapper
How can I add them to library or what should I do?
I finally figure out how to do it. Now our team can dev nutch in IntellIJ
The process we do
Get nutch source from apache.org
wget http://www.eu.apache.org/dist/nutch/2.3/apache-nutch-2.3-src.tar.gz
Import nutch source in intellij
Get Dependencies by Ant
Run ant runtime
Run ant test
Import dependencies into Intellij
File > Project Structures
Library > Ivy
Click to Plus button
Select all libraries in apache-nutch-2.3/build/lib
Now we have a project with nutch source and all dependencies
I think, you should use ant build for nutch project. Because, pom.xml is problematical for nutch. If you want to use it anyway maven, you check maven dependency in pom.xml .
I think, the problem can be solved with the following:
You create new project via idea and add nutch source. Idea is not
supported ivy ant project. You can install ivy plugin for idea, I
suppose, Idea12 does not support it.
or
You can create ant project for nutch via eclipse and then save
project. Then open the project on idea via eclipse classpath.
or
You can configure classpath. If you use ant build, you should add jars : File->ProjectStructure as follows:
Create a library
Attach Files
Then, if you use ant build, select jars from NUTCH_HOME/build/lib/* after build.
If you use maven build, select jars from ~/.m2/* (MAVEN_REPO)
Although Intellij supports running ant scripts directly through the IDE via the ant plugin, the Intellij editor will not figure out the classpath using your build.xml file by itself.This will result in the editor showing the code littered with errors.
Unfortunately the only solution I found to this is to add all the jars manually.You can get all the jars needed by building the ant project using the ant jar command.
So these are the steps you need to follow :->
1.Run ant jar command in the root of your program
2.Copy all the jars created inside the build folder(they will not be directly inside build folder.I had to go from build->ivy->lib->{project name})
3.Paste these jars to a new folder created somewhere outside the directory
4.Go to File->Project Structure->Libraries. Press the + button.
5.Select all the copied jars and press ok to any prompts which appear.
6.Press finish and wait for indexing to complete.Any dependency errors in the editor should resolve now.
Note: Since you are manually adding jars, you would need to keep them in sync if you change your build.xml file for any dependency change.
It seems that dependencies are managed using Ivy (see the ivy folder in the sources archives), so you could try to install the Ivy plugin, which would allow you to fix your classpath issues.
In Sonar documentation there are two properties options, the sonar.tests and sonar.binaries.
# path to test source directories (optional)
sonar.tests=testDir1,testDir2
# path to project binaries (optional), for example directory of Java bytecode
sonar.binaries=binDir
Questions:
If sonar.tests and sonar.binaries are added to my Ant target, how do they show up in Sonar? What would be different in Sonar if I did/did not set these properties?
Should sonar.binaries contain both source binaries and test binaries, or only source?
Can .jar files be given to both properties instead of path to actual .class files and/or .java files?
Answers:
If you do not set those 2 properties, you won't have test results ("sonar.tests") nor violations detected by Findbugs or bytecode-based tools ("sonar.binaries").
"sonar.binaries" should contain only compiled sources, not tests
No. Only "sonar.libraries" can (and actually must) point to JAR files.
I have a Java project that is dependent on other Java projects that are siblings and there is a chain of dependencies. Each individual project has a build script written in Ant. For clarity find below a sample of the same.
EARProject depends on WebProject and EJBProject: The war file that is generated by the WebProject build and jar file that is generated by the EJBProject are needed to build the EARProject.
WebProject depends on ComponentOneProject: The jar file that is generated by the ComponentOneProject build is needed to build WebProject.
EJBProject depends on ComponentTwoProject: The jar file that is generated by the ComponentTwoProject build is needed to build EJBProject.
So, when I build the EARProject build, if the dependent war and jar have not been built yet, then it should kick-off the WebProject build and EJBProject build and if the ComponentOneProject is yet to be built, the build of ComponentOneProject needs to be kicked-off and so on.
Can someone suggest a clean method by which we can accomplish this?
Facing the same problem we at our company wrote a custom Groovy script that explores the full dependency tree ant generates the Ant build scripts based on all the .project, .classpath, .settings/* files. This wasn't as difficult as it might seem as first. This way we can build our products without (My)Eclipse on a clean CVS+JDK+Groovy virtual machine. Hope it helps..