maven connecting to Sonar - maven

I have maven installed on my local machine and I'm trying to test out Sonar installed on a remote box.
I found a few post online to configure settings.xml (maven\config\settings.xml) and append a profile entry...which I did but does not work
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://remotebox:9000</sonar.host.url>
</properties>
</profile>
What is the cli way? I tried several options but nothing worked.
I tried: mvn sonar:sonar http://remotebox:9000
What is the correct syntax?
Thanks in advance.
Damian
PS. this works fine on the remote box where both maven and sonar are installed...i just want to try it my box to the remote box.

Running sonar with
mvn sonar:sonar -Dsonar.jdbc.url=jdbc:h2:tcp://ipaddr:9092/sonar -Dsonar.host.url=http://ipaddr:9000
,where ipaddr is your remote host, seems to work.

Up to Version 5.2 beside the sonar.host.url you also have to specify the database parameters as described here. That way it works for me.
Configuration example
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- EXAMPLE FOR MYSQL -->
<sonar.jdbc.url>
jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
</sonar.jdbc.url>
<sonar.jdbc.username>sonar</sonar.jdbc.username>
<sonar.jdbc.password>sonar</sonar.jdbc.password>
<!-- optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://myserver:9000
</sonar.host.url>
</properties>
</profile>
Since Version 5.2 this not not necessary anymore:
Quote:
Scanners don't access the database
This is the biggest change of this new version: scanners (e.g. Sonar Runner) no longer access the database, they only use web services to communicate with the server. In practice, this means that the JDBC connection properties can now be removed from analysis CI jobs:
sonar.jdbc.url,
sonar.jdbc.username,
sonar.jdbc.password

Just the following works for sonar-maven-plugin:3.2:
mvn sonar:sonar -Dsonar.host.url=http://<sonarqubeserver>:<port>

Problem 1
As explained you need to specify the JDBC connection details, otherwise Sonar will attempt to talk to the embedded Derby instance, it assumes is running on localhost.
Problem 2
Are you using Derby? Well, the default configuration of Derby does not accept remote connections, but only connections from the same host.
The SONAR-1039 issue explains how to work-around this problem, but my advise would be to setup a full-blown database such as MySQL or Postgresql.

I had some problem and then realized, I was running mavn on parent pom whereas sonar configuration was in a child pom, for which I wanted analysis report anyway, so running mvn sonar:sonar with child pom worked.

Related

Execute analysis in SonarQube from Maven but not storing the results in database

I am developing a new project in Eclipse and I have to analyze it with SonarQube. I am doing a lot of changes in the code and analysing it, but I wouldn't like that SonarQube store all the results in it's database (they are temporary versions). Is there any option for it?
I have configured my pom file like sonarQube official config:
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<sonar.host.url>
http://myserver:9000
</sonar.host.url>
</properties>
</profile>
It connects with sonnar and execute the analysis ok, but I am storing lots of useless executions in SonarQube.
Regards
You might get some value from the SonarLint Eclipse plugin: https://www.sonarlint.org/eclipse .
With this, you might be able to iterate on local changes before submitting a full sonarqube scan.

How can I configure the port a Quarkus application runs on?

I would like my Quarkus application to run on a port other than the default. How can I accomplish that?
The Quarkus configuration property to be used is quarkus.http.port (the default value is 8080).
If this property is set in application.properties then that value will be used.
The property can also be overridden at runtime as follows:
When running a Quarkus application in JVM mode you can set the port using the quarkus.http.port System property.
For example:
java -Dquarkus.http.port=8081 -jar example-runner.java
The same property applies to GraalVM Native Mode images.
For example:
./example-runner -Dquarkus.http.port=8081
To complement geoand’s answer, you can use the same property for mvn quarkus:dev. Unfortunately you cannot directly set it in a profile in ~/.m2/settings.xml to avoid the need to type it each time (for example because Microk8s binds 8080), but you can set it via jvm.args:
<profiles>
<profile>
<id>microk8s-quarkus-dev</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<jvm.args>-Dquarkus.http.port=8090</jvm.args>
</properties>
</profile>
</profiles>
Alternately, you could configure this in project sources:
echo '%dev.quarkus.http.port=8090' >> src/main/resources/application.properties
though this would not be shared across projects, and might be unwanted by other developers of the same project.
You can use <projhome>/resources/application.properties to configure the port.
For example
quarkus.http.port=8080
%dev.quarkus.http.port=8811
%test.quarkus.http.port=7711
%server.quarkus.http.port=6611
Here dev, test, and server refer to the profiles.
You can run them as below
$ mvn compile quarkus:dev -- port 8811 will be used
$ mvn -Dquarkus-profile=server compile quarkus:dev -- port 6611 will be used

Questions about pom.xml in Jenkins to run sonarQube through maven project

I'm trying to run sonarQube through Jenkins but I have some difficulties right now. When I build a new job, I use Maven Project and inside the configuration I have to give à pom.xml path but what does it correspond to ?
Thank you in advance
You should find in any jenkins job a post action for sonarqube analyse.
The pom.xml you mention is the pom.xml for your maven project, because sometimes you can put your parent pom.xml in a subdirectory and this is the way for helping jenkins to find it.
Instead of adding Sonar Task to each project why not just configure Sonar at Global Level configuring the settings.xml for your maven configuration, just go to $HOME/someUser/.m2/settings.xml (if you don't have it created yet) with this content:
<settings>
<pluginGroups>
<pluginGroup>org.sonarsource.scanner.maven</pluginGroup>
</pluginGroups>
<profiles>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- Optional URL to server. Default value is http://localhost:9000 -->
<sonar.host.url>
http://myserver:9000
</sonar.host.url>
</properties>
</profile>
</profiles>
</settings>
After you you have done that you will be able to run sonar in all the projects this way:
mvn clean verify sonar:sonar
 
# In some situation you may want to run sonar:sonar goal as a dedicated step. Be sure to use install as first step for multi-module projects
mvn clean install
mvn sonar:sonar
 
# Specify the version of sonar-maven-plugin instead of using the latest. See also 'How to Fix Version of Maven Plugin' below.
mvn org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar
You may find more information in sonar official documentation:
https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven

Goal specific javax.net.ssl.trustStore

I've got a Maven project for which i use org.apache.tomcat.maven:tomcat6-maven-plugin to deploy to a remote Tomcat.
This tomcat is configured so that i need to specify:
-Djavax.net.ssl.trustStore=mykeystore.jks -Djavax.net.ssl.trustStorePassword=mypassword
My problem is that by doing so, I can't download dependencies anymore from remote repositories through my company proxy as it tries to establish a secure connection using this truststore and it fails...
I'm looking for a way to connect to both ends (maven repo and my remote tomcat) without having to set/unset my MAVEN_OPTS variable every time...
I've seen that I can have a <configuration /> element in my settings.xml, but I can't find what to put in it.
Thanks...
Using different profiles with maven:
Define the active profiles in your pom (you can also define profiles in settings.xml but I think this should work for your case):
<profiles>
<profile>
<id>TOMCAT_DEPLOY</id>
<activation>
// Rules to active the profile
<activeByDefault>true</activeByDefault>
</activation>
<properties>
</properties>
// Add rest of profile specific configuration
</profile>
</profiles>
For executing maven with an specific profile, basically you have a list of active profiles and you can execute one of them according to different triggers:
A profile can be triggered/activated in several ways:
Explicitly, Through Maven settings, Based on environment variables OS settings or based on some Present or missing files
Please, read this link where you can have all information about profiles and how activate them for any execution

Netbeans build failure

Brand new to netbeans and working on the address-book tutorial. I am able to run the program without issues but when I build I get the following error. I have yet to find any possible solutions to the issue
Failed to execute goal org.codehaus.cargo:cargo-maven2-plugin:1.4.4:redeploy (deploy) on project address-book: Execution deploy of goal org.codehaus.cargo:cargo-maven2-plugin:1.4.4:redeploy failed: Failed to create deployer with implementation class org.codehaus.cargo.container.glassfish.GlassFish4xInstalledLocalDeployer for the parameters (container [id = [glassfish4x]], deployer type [installed]). InvocationTargetException: The container configuration directory "c://glassfish4/glassfish/domains" does not exist. Please configure the container before attempting to perform any local deployment. Read more on: http://cargo.codehaus.org/Local+Configuration -> [Help 1]
How does Maven know which server to deploy to and where is it located?
It's all in the pom.xml file.
Sometimes you will have to trace up the parents of the pom.xml to find it.
In the case of Java EE tutorial, when I was building project hello1, Maven couldn't find the location of my GlassFish server.
I traced up the parents of pom.xml to find
C:\mine\tools_installation\glassfish4\docs\javaee-tutorial\examples\pom.xml(51):
<glassfish.home.prefix>c:/</glassfish.home.prefix>
Then I changed it to
<glassfish.home.prefix>c:/mine/tools_installation</glassfish.home.prefix>.
The container configuration directory "c://glassfish4/glassfish/domains" does not exist.
Maven / Cargo looks for a folder defined in pom.xml and it doesn't exist on your computer.
I the property you need to change is and you'll need to set it to your GlassFish installation directory.
So it is automatically taken from the parent examples folder pom.xml rather than from your open example. So you should edit the pom.xml from
YOUR_GLASSFISH_HOME\docs\javaee-tutorial\examples
It think it is a bug in the examples pom.xml
I encountered similar error, the solution is very simple You need to edit the pom.xml file as follows. Replace line 38:
${glassfish.home.prefix}/glassfish4
to your GlassFish home, I run GlassFish 4.1.1 installed in C:\ drive. So my modification is:
${glassfish.home.prefix}glassfish-4.1.1.
Please note the slash before glassfish was removed too. The slash after c: in line 51 suffice.
Build it again. Should be fine.
I resolved this error adding in pom.xml those lines:
<profiles>
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<glassfish.home>C://Program Files//glassfish-4.1.1</glassfish.home>
</properties>
</profile>
</profiles>
I hope this help
I also usually install my glassfish development server under c:/opt so I had the same problem with the hello2 tutorial from the Java Platform, Enterprise Edition (Java EE) 8 Tutorial.
To solve this problem, I changed the "tutorial-examples/pom.xml" file which is the root parent of all the tutorial POM files. As I am using the J2EE8 tutorial, it is expected that glassfish5 is installed so this is reflected in the properties section:
<glassfish.home>${glassfish.home.prefix}/glassfish5</glassfish.home>
I not sure what tutorial version you are going through but as I see, it expects a glassfish 4 installation thus you need to edit the POM file accordingly.
Also (in the J2EE 8 tutorial), ${glassfish.home.prefix} is defined for every supported profile. For windows the windows profile, I had to change the line:
<glassfish.home.prefix>c:/</glassfish.home.prefix>
to
<glassfish.home.prefix>c:/opt</glassfish.home.prefix>
So the complete windows profile will be:
<profile>
<id>windows</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<properties>
<glassfish.home.prefix>c:/opt</glassfish.home.prefix>
<glassfish.executables.suffix>.bat</glassfish.executables.suffix>
</properties>
</profile>
Of course, you'll have to edit the POM file accordingly to your own setup.

Resources