Sonar using Sonar Runner on Jenkins Job fails to access classes - jenkins

Im trying to run a sonar analysis on a Jenkins Job. Im using ant so im using Sonar Runner and sonar.properties in the projects. Im configuring the the binaries to
sonar.binaries=build/ant/classes
After a successfull build Sonar starts and is running a while. But i get a lot of warnings during bytecode analysis.
Im getting WARN XX - Class 'XX' is not accessible through the ClassLoader.
for every class...
I dont really know why classes are all there?

These are warnings issued by Findbugs, which requires access to source, compile binaries and 3rd party libraries.
To resolve these warnings you need to include an additional sonar.libraries property, populated with the 3rd party jars your code depends upon (See Analaysis Parameters documentation)

I actually had the same problem, but that was because of an issue with the maven caches.
I had run mvn clean install in the directory on my local machine, but was running sonar on the directory on a virtual box. This resulted in classes not being found.

Related

intellij grails unable to resolve external library at groovy compile time

I'm writing a simple etrade programmatic trading program that needs to authenticate with etrade oauth. I'm using IntelliJ Ultimate with Grails 3.1.9.
I added a folder full of jars to Project Settings->Libraries and Project Settings->Modules->main project (accessible by pressing "command ;") and selected "export." The classes resolve fine in the groovy editor in my controller class but they don't resolve at groovy compile time. Why is that?
~/IdeaProjects/<project name>/grails-app/controllers/etradescripter/ETradeUserController.groovy: 8: unable to resolve class com.etrade.etws.sdk.client.ClientRequest
# line 8, column 1.
import com.etrade.etws.sdk.client.ClientRequest;
Grails use the Gradle build system, which is comparable (superior IMHO) to maven.
It is completely external to the IDE itself and not dependend to any IDE.
It is a very powerfull external build tool which has it's own tooling, dependency management,
library cache and logs.
The libraries and SDK you declare in Intellij project structure settings are for IntelliJ internal support (intellisense, code assist, decompiling etc) not for building and/or debugging
The gradle tooling support for your project (found in File/Settings/Gradle) can be:
a gradlew declaration in the project : the project will use it's own
build system version downloaded from the specifications in
gradle/wrapper/gradle-wrapper.properties file with the accompanying
gradle-wrapper.jar downloader - this is the recommended way to go if you are not comfortable with the system to avoid
problems but disk consuming and not the fastest build. There will be a gradle binary distribution download for the first build
a Gradle version bundled with Intellij (2.13 for the last IntelliJ version I think)
one you can declare in the project settings (ie your own Gradle installation root, you have to install it before and set the right
environment variables to make it work) for the last one it can be a
"daemon" version which speeds up thing notably but is very cpu and
memory expensive for a large project (be prepared for 100% cpu and
memory hogs for a large project whatever computer you have).
The main file for build where you declare the build and debug dependencies is "Build.gradle" file at the root of your project.
Dependencies are declared with lines (Groovy syntax, gradle is a groovy tool) like:
dependencies {
assets "com.craigburke.angular:angular-template-asset-pipeline:2.2.6"
assets "com.craigburke.angular:angular-annotate-asset-pipeline:2.4.0"
assets "com.craigburke:js-closure-wrap-asset-pipeline:1.2.0"
compile "org.springframework.boot:spring-boot-starter-logging"
compile "org.springframework.boot:spring-boot-autoconfigure"
etc...
This is where you have to add your own dependencies, not in IntelliJ SDK/lib settings.
This is comparable to the maven system with a different syntax (groovy).
For jars comming from an external repo or local dependencies, you should see lines that you can copy/paste and modify.
If not look at gradle docs
especially 23.3 and 23.4, how to declare you dependencies.
There can be other gradle files in gradle directory and/or subprojects directory. It depend on your project.
To build your project, you can open the Gradle tool window in IntelliJ (View/Tool Windows/Gradle), select the build task (Task/build/build), double click on it and it will launch the build.
This will change the run/debug configuration in the IntelliJ IDE so you can build it again with the IDE toolbar by clicking on the Run button
Note: the run button runs the currently selected gradle task, not the application, this is a bit confusing at the beginning
To run or debug you app, you select the appropriate task, in case of Grails task, application/bootrun and double click on it.
This will launch your application (after a build if needed), and if it is a web app, you can browse you application in your browser.
When you run the Run task (not the build task) you can also click on 'Debug' icon to debug your application
If you select another task and click debug, you will have a socket exception because IntelliJ thinks you are launching a jvm and tries to connect to it for debugging.
(they are lots of predefined task in Gradle : assembling jars, building docs etc... and the Run task may be specific to a project
Generally Build tasks are under the build category and run task under the application category)

Getting Error in POM.xml on KEPLER Eclipse

I have created maven based web application so after created application i am getting two errors in pom.xml which are
1.Multiple annotations found at this line:
- Failure to transfer org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted
until the update interval of central has elapsed or updates are forced. Original error: Could not transfer artifact org.apache.maven.plugins:maven-resources-plugin:pom:2.6 from/to central (http://
repo.maven.apache.org/maven2): null to http://repo.maven.apache.org/maven2/org/apache/maven/plugins/maven-resources-plugin/2.6/maven-resources-plugin-2.6.pom
2.Multiple annotations found at this line:
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile)
- Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (execution: default-compile, phase: compile)
- CoreException: Could not calculate build plan: Plugin org.apache.maven.plugins:maven-compiler-plugin:3.1 or one of its dependencies could not be resolved: Failed to read artifact descriptor for
org.apache.maven.plugins:maven-compiler-plugin:jar:3.1: ArtifactResolutionException: Failure to transfer org.apache.maven.plugins:maven-compiler-plugin:pom:3.1
Could you please let me know what needs to be done for resolving the issue
If you are facing the same issue I described in my comment above then it seems I could fix it by running mvn eclipse:eclipse with working directory set to Eclipse project folder i.e.
$ cd /path/to/eclipse/workspace/Project
$ mvn eclipse:eclipse
Does this work for you ? Maybe your environment is different . Providing more details might help others to understand your problem even better so as to offer useful suggestions .
I had similar problem Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-compiler-plugin:3.1:testCompile (execution: default-testCompile, phase: test-compile).
To Fix (apart from installing M2E plug-in and all):
Ensure installed maven is > 3.1 (using mvn -v). If not, you need to upgrade.
Ensure eclipse is pointing to correct maven location (Window->Preferences->Maven->Installations)
On Command prompt, go to project home directory and run mvn eclipse:clean and mvn eclipse:eclipse
Disable and enable Maven nature in eclipse (Right click on project, goto Maven -> Disable Maven Nature. To enable, Right click on project goto Configure -> Convert to Maven Project)

is sonar multi-module broken?

trying to make a multi module project I dowloaded the samples in github: I use this folder
https://github.com/SonarSource/sonar-examples/tree/master/projects/multi-module/sonar-runner/java-sonar-runner-modules-own-configuration-file as a project base dir
In a command line in this folder, I type /opt/sonar-runner/bin/sonnar-runner
First thing I find is that sonar-project.properties has a property named sonar.sources=src, but executing throws
Exception in thread "main" org.sonar.runner.RunnerException: You must define mandatory properties: sources
Then I correct this property with sources=src and runner execution finish, adds the project to my sonar server, but no code, modules or file is detected. It is like if all project is empty.
It is exactly the same with other examples and with my own project. No matter if is java, python...
Any help is welcome
You are using an old version of Sonar Runner and/or Sonar. Please update to the latest versions (Sonar Runner 2.2 and Sonar 3.5.1).

Include ant libs from within the build file

My problem is the following:
I would like to use the propertyregex task in ant. The project I am working on is built on various different servers and I don't want to configure (install the ant-nodeps.jar) every server. The source needs to include everything, that is not installed on the system by default.
So now I would need to add the ant-nodeps.jar to the ant classpath from within the build file. Does somebody know how to do that?
Cheers,
Robert
The propertyregex task is part of ant-contrib and can be installed as part of your build using Apache ivy
Checkout the following example, which demonstrates how to download and use the "for" task (also from the ant-contrib project):
Problems getting my ANT builds to work after OS upgrade
The one downside is that ivy does not come pre-packaged with ANT, so the following answer has a tip on how to bootstrap your ANT builds. Once ivy is started it can be used to pull down everything else your build needs.
Ivy fails to resolve a dependency, unable to find cause
Update
While I understand you requirement to have no change on the target platforms, it's a very difficult problem to solve if you must also match several old versions of the build software. I have found incompatibilities between the latest ANT and 5 year old versions like 1.7 (ANT 1.6.5 is now 8 years old....)
What I do is install a very limited number of ANT versions on my Jenkins slave nodes. Build jobs can then only choose from these and then use ivy to download all other 3rd party software dependencies (This setup emulates how you'd manage a set of Maven projects).
I suspect you're using ANT to run your deployments? If that is the case I would suggest switching to something like Groovy, which can be deployed as a single jar file and can pull down dependencies on the fly, using Grape.

Intellij IDEA, build artifact using Ant?

I might be missing something, but I have been struggling with this problem for some time now.
I have an Web application with Ant build script. I would like to set up an Artifact to this module, (which is the .war file, generated using ant), so that I could deploy this war file, to the configured Tomcat server.
But I am not able to figure out, how to make Intellij use my Ant script to build artifact. I see an option to Run Ant Targets, but this just runs the Ant target and Intellij then proceeds to generate Artifact, in the usual way.
Please let me know if the question is ambiguous. The problem is not Ant Integration with Intellij. I could just use the Ant window and run any target and also could make an Ant target run as part of Build. The problem is to associate an Artifact to a module and leverage the Ant script to build that artifact. I need this to enable, tight tomcat integration, Since while integrating the Tomcat server, I can specify an artifact to be deployed.
Note: Intellij IDEA version 11.1
IDEA can either deploy Artifact or the External Source (directory or file) that is built by Ant or any other tool:
It's not possible to associate IDEA Artifact with Ant build.

Resources