How to use external sonar server for jHipster project - spring

I am currently developing a spring boot application with jHipster and I want to use an existing sonar server from my company to analyze the code. JHipster only describes a way to use a build in sonar server from a docker container. Unfortunately that is not an option for me since my machine is running on Windows Server 2012, that is not supported by docker.
I already tried to start the maven build by adding the server url as a build parameter to the maven build, but it is ignoring it.
mvn clean test sonar:sonar -Dsonar.host.url=http://server-ip:server-port/ -Dsonar.login=login -Dsonar.password=pw
I am relatively new to the topic and was using the given command by the jhipster reference page (https://jhipster.github.io/code-quality/), so the test profile should be the correct one for this purpose.
When I run the command it ignores the given url paramter and still tries to use localhost where it expects the sonar in a docker container.
08:31:53.473 INFO - Create JDBC datasource for
jdbc:h2:tcp://localhost/sonar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.017 s
[INFO] Finished at: 2017-06-12T08:31:53+00:00
[INFO] Final Memory: 65M/392M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar (default-cli) on project project: Fail to connect to database: Cannot load JDBC driver class 'org.h2.Driver' -> [
Help 1]
Since jHipster generates and configures a lot in the background I have no idea if I am missing something vital here. Maybe a configuration file I have to adjust? I really appreciate the help.
The pom.xml was generated by jHipster and the maven plugin is configured as followed:
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>${sonar-maven-plugin.version}</version>
</plugin>
The version is set in the properties as:
<sonar-maven-plugin.version>3.2</sonar-maven-plugin.version>
I tried setting up my project on a linux vm with a running local docker sonar instance as suggested by the jHipster team and it was running fine, it is just very inconvenient for me since I have an available company sonar instance running in the intranet.
I also tried modifying my settings.xml as suggested and that was ignored, though it lead to a different looking error message:
[INFO] --- sonar-maven-plugin:3.2:sonar (default-cli) # project ---
[INFO] User cache: C:\Users\Administrator\.sonar\cache
[ERROR] SonarQube server [http://localhost:9000] can not be reached
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:12 min
[INFO] Finished at: 2017-06-14T11:29:22+00:00
[INFO] Final Memory: 57M/408M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.2:sonar (default-cli) on project project: Unable to execute SonarQube: Fail to download libraries from server: Status r
eturned by url [http://localhost:9000/batch_bootstrap/index] is not valid: [404] -> [Help 1]

Everything is explained in the sonar docs : https://docs.sonarqube.org/display/SCAN/Analyzing+with+SonarQube+Scanner+for+Maven
You should edit the settings.xml file in you ~/.m2directory with the following:
<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>

Try to add the following line into the properties section of your pom.xml file.
<sonar.host.url>http://1.2.3.4:9000/</sonar.host.url>
With the IP address corresponding to your sonarqube server.

Related

Unable to load the mojo 'sonar' - A required class is missing

Have been trying to set up sonar to run on my Jenkins instance at the end of each build. As there are restrictions on my work computer I have set up nexus to work as proxy so i can download artifacts from the central maven repository. Whenever I run my build it is successful and the tests pass however the sonar step fails.
[INFO] Building Customer 1.0-SNAPSHOT
[INFO] ---------------------------------------------------------------------
[INFO]
[INFO] --- sonar-maven-plugin:2.3:sonar (default-cli) # Customer ---
[INFO] ---------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ---------------------------------------------------------------------
[INFO] Total time: 2.543s
[INFO] Finished at: Mon Mar 23 11:44:46 GMT 2015
[INFO] Final Memory: 8M/156M
[INFO] ---------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.mojo:sonar-maven- plugin:2.3:sonar (default-cli) on project Customer: Execution default-cli of goal org.codehaus.mojo:sonar-maven-plugin:2.3:sonar failed: Unable to load the mojo 'sonar' in the plugin 'org.codehaus.mojo:sonar-maven-plugin:2.3'. A required class is missing: Lorg/apache/maven/rtinfo/RuntimeInformation;
[ERROR] -----------------------------------------------------
[ERROR] realm = plugin>org.codehaus.mojo:sonar-maven-plugin:2.3
The required class that is missing - org/apache/maven/rtinfo/RuntimeInformation
I have tried several steps to resolve this already including cleaning my repository and restarting the build. I have also tried different versions of sonar-maven-plugin. I am currently using maven 3.0.
Any advice would be greatly appreciated!
Try to use Apache Maven 3.2.5 in combination with org.codehaus.mojo:sonar-maven-plugin:2.7.1.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>2.7.1</version>
</plugin>
<!-- ... -->
</plugins>
</build>

Sonar fails to connect to mySQL always tries jdbc:h2:tcp://localhost/sonar

This morning I have downloaded Sonar latest version. maven 3.2.5, mysql.
Sonar setup went correctly and I have the web site at 9000 working fine and all tables correctly created in mySql.
I have updated my .m2/settings.xml with the following
<profiles>
<profile>
<id>sonar</id>
<properties>
<sonar.jdbc.url>jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=true</sonar.jdbc.url>
<sonar.jdbc.username>myuser</sonar.jdbc.username>
<sonar.jdbc.password>mypassword</sonar.jdbc.password>
<sonar.host.url>http://localhost:9000</sonar.host.url>
</properties>
</profile>
</profiles>
I tried mvn sonar:sonar, I always get
INFO: Work directory: /home/salam/git/spring-petclinic/target/sonar
INFO: SonarQube Server 5.1
[INFO] [00:11:25.410] Load global repositories
[INFO] [00:11:26.307] Load global repositories (done) | time=905ms
[INFO] [00:11:26.317] Server id: 20150406220059
[INFO] [00:11:26.326] User cache: /home/salam/.sonar/cache
[INFO] [00:11:26.360] Install plugins
[INFO] [00:11:26.539] Install JDBC driver
[INFO] [00:11:26.554] Create JDBC datasource for jdbc:h2:tcp://localhost/sonar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
I even updated sonnar-project.properties with
sonar.jdbc.driverClassName=com.mysql.jdbc.Driver
sonar.sourceEncoding=UTF-8
sonar.jdbc.url=jdbc:mysql://localhost:3306/sonar?useUnicode=true&characterEncoding=utf8
sonar.jdbc.username=myuser
sonar.jdbc.password=mypassword
No way, always getting the same error and sonar can not go through
I visited a couple of threads here Sonar fails to connect to database
I understand that what I have doen should make this project works fine but this is not the case
Thanks for your help
I solved it. I needed to add the following in the settings.xml
<activation>
<activeByDefault>true</activeByDefault>
</activation>

Bamboo Maven Glassfish Deploy

I've been trying to set up continuous integration and deployment for a Java EE application.
Continuous integration is working however the deployment always fail.
I tried 3 things in the maven parameter ${local.glassfish.passfile}:
path to domain-password
path to.gfclient/pass
password string
One last thing I tried was:
hardcoded value inside pom.xml
Ear pom.xml configuration:
<plugin>
<groupId>org.glassfish.maven.plugin</groupId>
<artifactId>maven-glassfish-plugin</artifactId>
<version>2.1</version>
<configuration>
<glassfishDirectory>${local.glassfish.home}</glassfishDirectory>
<user>${local.glassfish.user}</user>
<passwordFile>${local.glassfish.passfile}</passwordFile>
<domain>
<name>${local.glassfish.domain}</name>
<adminPort>${local.glassfish.adminPort}</adminPort>
<httpPort>${local.glassfish.httpPort}</httpPort>
</domain>
<components>
<component>
<name>${project.artifactId}</name>
<artifact>target/${project.build.finalName}.ear</artifact>
</component>
</components>
<debug>true</debug>
<terse>false</terse>
<echo>true</echo>
</configuration>
</plugin>
Running mvn glassfish:deploy inside the ear folder via the terminal successfully deploys the ear artefact to the server.
Bamboo Error log:
[INFO] Scanning for projects...
[INFO]
[INFO] Using the builder org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder with a thread count of 1
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building ear 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-glassfish-plugin:2.1:undeploy (default-cli) # ear ---
[INFO] Deprecated syntax, instead use:
[INFO] asadmin --echo --terse=false --interactive=false --user admin --passwordfile /home/guest/.gfclient/pass --host localhost --port 55004 undeploy [options] ...
[INFO] asadmin --host localhost --port 55004 --user admin --passwordfile /home/guest/.gfclient/pass --interactive=false --echo=true --terse=false undeploy --keepreposdir=false --isredeploy=false --cascade=false --_ignorecascade=false --_classicstyle=false ear
[INFO] Command undeploy failed.
[ERROR] Authentication failed for user: admin
[ERROR] (Usually, this means invalid user name and/or password)
[ERROR] Undeployment of ear failed.
[ERROR] For more detail on what might be causing the problem try running maven with the --debug option
[ERROR] or setting the maven-glassfish-plugin "echo" property to "true".
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.699 s
[INFO] Finished at: 2014-03-06T17:39:50+00:00
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.glassfish.maven.plugin:maven-glassfish-plugin:2.1:undeploy (default-cli) on project ear: Undeployment of ear failed. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
Failing task since return code of [/home/guest/apache-maven-3.2.1/bin/mvn glassfish:undeploy] was 1 while expected 0
Finished task 'Maven Glassfish Undeploy'
Note that I ran the "asadmin login" command after I changed the admin password in order to update the pass file.
guest#foo:~$ asadmin --port 55004 login
Enter admin user name [Enter to accept default]> admin
Enter admin password>
Admin login information for host [localhost] and port [55004] is being overwritten with credentials provided. This is because the --savelogin option was used during create-domain command.
Login information relevant to admin user name [admin] for host [localhost] and admin port [55004] stored at [/home/guest/.gfclient/pass] successfully.
Make sure that this file remains protected. Information stored in this file will be used by administration commands to manage associated domain.
Command login executed successfully.
Also, Glassfish version is 4.0, Maven version is 3.2.1.
If you have used the asadmin login command you don't need to specify the user and password in the undeploy and deploy command as it will use the credentials that you've set using the login command.
There is a Bamboo plugin that allows to deploy an war file to Glassfish Application Server.
https://marketplace.atlassian.com/apps/1219234/tasks-for-glassfish-server

Unable to build sonar project. Error: Cannot find parent: org.codehaus.sonar:sonar

Trying to build our java app using sonar for analysis. We are behind a firewall so no access to maven repo1. We do have a internal corp Artifactory for third party artifacts and a project Artifactory for our local stuff. I am the SCM guy in charge of our build server, not a developer. That said the application with junit tests builds fine. We have two goals clean install. The sonar server is 3.5.1 and the port set to 8080 instead of 9000 This is in our pom.
<profile>
<id>sonarJsEnabled</id>
<properties>
<srcDir>src/main/static</srcDir>
<sonar.exclusions>libs/**/*,DSTCore/**/*,test/**/*</sonar.exclusions>
<maven.test.skip>true</maven.test.skip>
<sonar.language>js</sonar.language>
<sonar.branch>js</sonar.branch>
</properties>
</profile>
<profile>
<id>sonarHtmlEnabled</id>
<properties>
<srcDir>src/main/static</srcDir>
<sonar.language>web</sonar.language>
<sonar.branch>web</sonar.branch>
<sonar.web.fileExtensions>html,xhtml,jspf,jsp</sonar.web.fileExtensions>
<maven.test.skip>true</maven.test.skip>
</properties>
</profile>
<profile>
<id>sonar</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<!-- SERVER ON A REMOTE HOST -->
<sonar.host.url>http://10.226.xx.xx:8080</sonar.host.url>
</properties>
</profile>
and this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>1.0-beta-2</version>
</plugin>
We add sonar:sonar When we build manually or with Bamboo we get this output.
C:\sonartest>mvn sonar:sonar
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'sonar'.
[INFO] org.apache.maven.plugins: checking for updates from EnterpriseArchitectureRepo
[INFO] org.codehaus.mojo: checking for updates from EnterpriseArchitectureRepo
[INFO] artifact org.codehaus.mojo:sonar-maven-plugin: checking for updates from EnterpriseArchitectureRepo
[INFO] Ignoring available plugin update: 2.0 as it requires Maven version 3.0
[INFO] Ignoring available plugin update: 2.0-beta-2 as it requires Maven version 3.0
[INFO] Ignoring available plugin update: 2.0-beta-1 as it requires Maven version 3.0
[INFO] ------------------------------------------------------------------------
[INFO] Building fundTrader
[INFO] task-segment: [sonar:sonar] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] [sonar:sonar {execution: default-cli}]
[INFO] Sonar host: http://10.226.xx.xx:8080
[INFO] Sonar version: 3.5.1
[INFO] Execute: org.codehaus.sonar:sonar-maven-plugin:3.5.1:sonar
Downloading: http://repository.corp.net:8080/artifactory/libs-release/org/codehaus/sonar/sonar/3.5.1/sonar-3.5.1.pom
[INFO] Unable to find resource 'org.codehaus.sonar:sonar:pom:3.5.1' in repository EnterpriseArchitectureRepo (http://repository.corp.net:8080/artifactory/libs-release)
...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Can not execute Sonar
Embedded error: Unable to build project for plugin 'org.codehaus.sonar:sonar-maven-plugin': Cannot find parent: org.codehaus.sonar:sonar for project: null:sonar-maven-plugin:maven-plugin:null for project null:sonar-maven-plugin:maven-plugin:null
Unable to download the artifact from any repository
Any help would be greatly apreciated.
I looks like the sonar-3.5.1.pom is not found. Consider adding Bintray's jcenter remote repository to your Artifactory (it has much more artifacts than Maven Center).
The simplest way to do it is to import the jcenter configuration from an Artifactory instance at repo.jfrog.org.
Just click on the Import -> Load and select jcenter from the list of loaded repository configurations.

Redeploy existing Nexus artifact to Weblogic

I have a Hudson build job that builds a Maven project, and redeploys the resulting artifact to Nexus and to a remote Weblogic instance for testing. I'm trying to create a separate job that would deploy the same artifact to another Weblogic instance, but to do so without recompiling the project and making a new WAR. The rationale here is, the bits already exist and were tested in the development environment, and only if that passes can they be promoted to the development-integration environment. Is this possible?
So far, I have tried:
1) using the existing POM and on the command line and declaring mvn deploy wls:undeploy wls:deploy - This deploys the project WAR to the new environment but also builds the project from scratch. The deploy goal also replaces the previously built project artifact (a snapshot) in Nexus, which makes sense.
2) Tried creating a new POM where the artifact from the previous build is a dependency, and the wls-maven-plugin is the only plugin declared. Running mvn wls:deploy here also fails, for different reasons.
Is there a way to perform such a deployment in a concise manner that I'm missing? Am I using the wrong mechanism (Maven) for this? Should I be using a more procedure based language like Ant? Any insight would be greatly appreciated. (Also if more information is required, please let me know!)
Edit: The redeployment succeeds if the built artifact is locally available in the target directory, and that location is referenced by the properties file. According to the documentation on Oracle's website that parameter can either be local or GAV coordinates. If I use GAV coordinates to pull the artifact directly from Nexus and then push it out to the remote Weblogic, I get the following Maven error:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building MyWebApp 0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- wls-maven-plugin:12.1.1.0:redeploy (default-cli) # MyWebApp-deploy-DIT ---
[INFO] ++====================================================================++
[INFO] ++ wls-maven-plugin: redeploy ++
[INFO] ++====================================================================++
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.480s
[INFO] Finished at: Wed Mar 20 10:19:22 EDT 2013
[INFO] Final Memory: 4M/122M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.oracle.weblogic:wls-maven-plugin:12.1.1.0:redeploy (default-cli) on project MyWebApp-deploy-DIT: Invalid file. Please provide an existing fully qualified path of the file. -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
For completeness, I'm also posting the POM I'm using to perform option #2:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>MyWebApp</name>
<parent>
<groupId>org.myorg.maven</groupId>
<artifactId>MyOrg-Parent</artifactId>
<version>2.0</version>
</parent>
<groupId>org.myorg.apps</groupId>
<artifactId>MyWebApp-deploy-DIT</artifactId>
<version>0.1-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<drools.version>5.4.0.Final</drools.version>
<REGION>DEV</REGION>
<MyWebApp_LOGDIR>.</MyWebApp_LOGDIR>
<webapp.jsp.dir>src/main/webapp/WEB-INF/jsp</webapp.jsp.dir>
<buildMsgJsp>buildMsg.jsp</buildMsgJsp>
<DEPLOYMENT_NAME>MyWebApp</DEPLOYMENT_NAME>
<MIDDLEWARE_HOME>/ci/oracle/middleware</MIDDLEWARE_HOME>
<WLS_ADMIN_HOST>lncibd008</WLS_ADMIN_HOST>
<WLS_PORT>7001</WLS_PORT>
<STAGE>true</STAGE>
<!--<SOURCE>${project.build.directory}/MyWebApp-3.7-SNAPSHOT.war</SOURCE>-->
<SOURCE>org.myorg.apps:MyWebApp:war:3.7-SNAPSHOT</SOURCE>
<WLS_TARGETS>server1</WLS_TARGETS>
</properties>
<dependencies>
<dependency>
<groupId>org.myorg.apps</groupId>
<artifactId>MyWebApp</artifactId>
<version>3.7-SNAPSHOT</version>
<type>war</type>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.oracle.weblogic</groupId>
<artifactId>wls-maven-plugin</artifactId>
<version>12.1.1.0</version>
<configuration>
<weblogicHome>wlserver_12.1</weblogicHome>
<upload>true</upload>
<remote>true</remote>
<stage>${STAGE}</stage>
<verbose>true</verbose>
<userConfigFile>wlsconfig/${WLS_ADMIN_HOST}${WLS_PORT}.config</userConfigFile>
<userKeyFile>wlsconfig/${WLS_ADMIN_HOST}${WLS_PORT}.key</userKeyFile>
<adminurl>http://${WLS_ADMIN_HOST}:${WLS_PORT}</adminurl>
<targets>${WLS_TARGETS}</targets>
<source>${SOURCE}</source>-->
<name>${DEPLOYMENT_NAME}</name>
<middlewareHome>C:\Oracle\Middleware</middlewareHome>
</configuration>
</plugin>
</plugins>
</build>
</project>
As you can see I have a commented-out and a GAV . Local one succeeds, GAV fails with the above error.

Resources