SonarQube Scanner for Maven and SonarTsPlugin Cannot Run node - maven

I am using SonarQube 5.6.1 for code analysis (code written in Spring Boot and Angular (using TypeScript)). SonarQube Scanner for Maven 3.4.0.905 and SonarTsPlugin 1.1.0 are used for code scanning in Java and TypeScript, respectively.
In my pom.xml, I have the following properties set:
<frontend.directory>frontend</frontend.directory>
<sonar.host.url>http://sonarqube.some-url.local/</sonar.host.url>
<sonar.sources>src/main/java,${frontend.directory}/src/app,pom.xml</sonar.sources>
<sonar.exclusions>${frontend.directory}/node_modules/**</sonar.exclusions>
<sonar.tests>${frontend.directory}/src/app,src/test/java</sonar.tests>
<sonar.test.inclusions>**/*.spec.ts,src/test/java/**/*.java</sonar.test.inclusions>
<sonar.testExecutionReportPaths>${frontend.directory}/reports/ut_report.xml</sonar.testExecutionReportPaths>
<sonar.ts.coverage.lcovReportPath>${frontend.directory}/coverage/lcov.info</sonar.ts.coverage.lcovReportPath>
<sonar.ts.tslint.configPath>${frontend.directory}/tslint.json</sonar.ts.tslint.configPath>
<sonar.ts.tslint.nodePath>${frontend.directory}/node/node</sonar.ts.tslint.nodepath>
<sonar.ts.tslint.path>${frontend.directory}/node_modules/.bin/tslint</sonar.ts.tslint.path>
Please note that I am pointing sonar.ts.tslint.nodePath to the local node installed as following.
I use frontend-maven-plugin 1.6 to install npm and node:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<workingDirectory>${frontend.directory}</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v10.1.0</nodeVersion>
<npmVersion>6.0.1</npmVersion>
</configuration>
</execution>
...
</executions>
</plugin>
I run ./mvnw sonar:sonar to start the SonarQube scanner. However, when the SonarTsPlugin runs and goes to run tslint, the nodePath is ignored and the global node is used. This causes problems in my Jenkins box where I get the following error:
[ERROR] Failed to execute goal org.sonarsource.scanner.maven:sonar-maven-plugin:3.4.0.905:sonar (default-cli) on project nsgra-web: java.io.IOException: Cannot run program "node": error=2, No such file or directory -> [Help 1]
This is odd to me since node is installed via frontend-maven-plugin and I am pointing to that node binary in sonar.ts.tslint.nodePath.
Does anyone have any insight?

Thanks Aerus for your response.
I found the same issue inside docker pod using jenkins.
I had maven installed but not node, then maven create a local installation of node at ./node/ folder. When the TS sonar was trying to execute node to know the current version, the commented error arise and all .ts files was ignored.
I solved using your suggestion and adding this to the command line execution
-Dsonar.typescript.node=./node/node

Related

maven - generate sources is not working

please advise if possible on this
I am running mvn package source:jar and get a module.jar and module-sources.jar as expected in the target directory
However, I have 2 issues:
1) I when I do : mvn install source:jar I get a -source.jar in my "target" in
the local projects folder, HOWEVER, NOT in the "local-repository (under .m2
on my PC). Even though, I do get a module.jar with binaries installed.
EDIT: I have figured this item (1): It works if I place "source:jar" before "install". That is mvn source:jar install instead of mvn install source:jar
2) I want to NOT HAVE TO run source:jar in the command line to generate the sources. Because, when I use GO continuous integration tool, that I have no control over, they do not have a maven goal mvn source:jar there.
I know that with the configurations in the pom.xml it can be achieved, and I did see it occuring once or twice, but it stopped working (well, obviously I made a change,that I do not know that broke this)
My pom.xml has the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<outputDirectory>${source.directory}</outputDirectory>
<finalName>${project.jar.name}</finalName>
<fileNameMapping>no-version</fileNameMapping>
<classifier>${source.classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
So, ultimately, when I run either mvn package or mvn install or I want to have sources generated as a jar file next to the regular project.jar (or in the specified folder, but it is not essential)

Using maven-deploy-plugin to deploy Eclipse product

I am trying to deploy an Eclipse product to Nexus repository. I am somewhat successful, but still get some errors that I am not sure how to handle.
I am using maven-deploy-plugin in the feature (F) that builds product:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<repositoryId>snapshots</repositoryId>
<packaging>zip</packaging>
<generatePom>true</generatePom>
<url>http://repo:8081/nexus/content/repositories/snapshots</url>
<groupId>my.group</groupId>
<artifactId>my.artifact</artifactId>
<version>1.0.0-SNAPSHOT</version>
<file>
target/products/product.zip
</file>
</configuration>
</execution>
</executions>
</plugin>
I execute 'mvn clean install' to build the product and then 'mvn deploy' on F. If I do that then I get error
Exception while publishing product /home/akravets/dev/workspaces/trunk/my.repository.feature/myProduct.product: publishing result: [Included element my.product.feature.feature.group 8.0.1.R20180301-1431 is missing. Cannot determine filter for requirement to this element.] -> [Help 1]
I've read discussions about this issue, but nothing seems relevant to my issue because I don't have any defined deploy phases besides the one in maven-deploy-plugin.
If I change phase of maven-deploy-plugin to 'install' I get almost satisfactory results. The zip file and generated pom get deployed to repository, but the build fails with error
product.qualifier-p2artifacts.xml. Return code is: 400, ReasonPhrase: Bad Request.
Why does this file even gets considered to be deployed to repository when it's not in file element of maven-deploy-plugin and it's not in the directory structure where zip file is: target/ vs target/product/product.zip? Is this because maven-deploy-plugin is executed during the install phase and it picks up all generated resources as candidates for deployment?
I simply recommend you to use Maven-Tycho to deploy Eclipse RCP product.Tycho determines the dependencies of a plug-in via the MANIFEST.MF file of the plug-in and fetches the required plugins-bundles through the online repositories.
You can check this git repository as an example; rcp - tycho

pull apache beam from github compile error

I am new to Apache beam, I download latest source code from github and compile runner module under path :
../beam/runners
with command : mvn package and it prints the exception like this :
enter image description here
Apache Beam :: Runners :: Core Construction Java ... FAILURE
Does anyone have some ideas with this ? thanks!
#Balajee Venkatesh
Here are my compile steps:
cd beam-master
mvn compile
wait compile finish
The first time I execute mvn compile command and met the exception shown above was under path beam-master/runners. After I changing compiling path to beam-master everything goes well .
And may I ask are you trying to compile the whole project to load it to your IDE ?
If so , I suggest using IDEA with 'File'->'import from existing source' instead of executing 'mvn compile' command .
If you try to use IDEA import beam , you can just remove/comment error messages in ${project_loc:beam-parent/pom.xml} like :
<!-- <plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.3</version>
<reportSets>
<reportSet>
<reports>
<report>dependency-updates-report</report>
<report>plugin-updates-report</report>
</reports>
</reportSet>
</reportSets>
</plugin>-->
and, replace this maven plugins version the same as your mvn -version .
<!-- Rename the artifact produced by the Apache parent's
source release. -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>**3.3.3**</version>
<executions>
<execution>
<id>source-release-assembly</id>
<configuration>
<finalName>apache-beam-${project.version}</finalName>
</configuration>
</execution>
</executions>
</plugin>
By the way , my maven version is 3.3.3 . You can also check out if the pom.xml's maven version incompatible with your local mvn -version .
Here is my mvn compile path :
enter image description here
After I changing my compiling path to main path every module compiled success.

Multi module project analysis with SonarQube

SonarQube Server 5.1.2, Sonar-Runner 2.4
As provide in Multi-moduleProject i have created a project structure as
Accounts
|
->invoice
|
->src
->receipt
|
->src
->sonar.properties
File:sonar.properties
sonar.projectKey=org.mycompany.acc
sonar.projectName=Account
sonar.projectVersion=1.0
sonar.sources=src
sonar.modules=invoice,receipt
invoice.sonar.projectName=Invoice
receipt.sonar.projectName=Receipt
When execute with above configuration in sonar-runner i encountered with error "src" folder is missing in "Account" directory, hope this configuration is same as the conf available in that link. As per the understanding if the configuration is fine then the Invoice and Receipt will be listed as sub project under Account Project, so what are the changes are required in above configuration to achieve multi module / project under one project.
ERROR
ERROR: Error during Sonar runner execution
ERROR: Unable to execute Sonar
ERROR: Caused by: The folder 'src' does not exist for 'org.mycompany.acc' (base
directory = C:\Users\xyz\Accounts\.)
ERROR:
ERROR: To see the full stack trace of the errors, re-run SonarQube Runner with t
he -e switch.
ERROR: Re-run SonarQube Runner using the -X switch to enable full debug logging.
try this:
sonar.projectKey=org.mycompany.acc
sonar.projectName=Account
sonar.projectVersion=1.0
sonar.sources=src # try to remove this by the way if you don't have suchdirectory under root folder of project
sonar.modules=invoice,receipt
invoice.sonar.projectName=Invoice
invoice.sonar.sources=invoice/src
receipt.sonar.projectName=Receipt
receipt.sonar.sources=receipt/src
You can try this option, If you want scan multiple projects at same time OR in same build then try this option.
sonar.sources=invoice,receipt
sonar.modules property was deprecated long time ago. Use sonar.sources parameter to perform a scan.
In short, you have to specify in sonar:sonar goal parameters where the sources and reportPaths are located for the required modules and declare jacoco configuration for each module respectively. As a result, it will look something like this:
Jacoco plugin declaration in each module:
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
Sonar goal execution:
mvn clean verify sonar:sonar /
-Dsonar.projectKey=... /
-Dsonar.host.url=... /
-Dsonar.login=... /
-Dsonar.branch.name=... /
-Dsonar.sources=../module1/src/main,../module2/src/main /
-Dsonar.jacoco.reportPath=module1/target/jacoco.exec,module2/target/jacoco.exec
Important! It's required to specify .. before module name in -Dsonar.sources parameter because jacoco plugin in each module can only read content by relative path from it's location.

WSO2ESB - Building a CAR file with Maven

Using WSO2 Developer Studio (version 3.7.0), I have created a WSO2 ESB proxy service with a sequence in a "ESB Config Project", this proxy service using a wsdl file located in a "Registry Resources Project". I also created a "Composite Application Project" to generate my .car file (including proxy service, sequence and resources), and deployed this file in my WSO2 ESB installation with success.
Now I am trying to generate (then deploy) the .car file using maven command.
I first tried this solution : https://docs.wso2.com/display/DVS370/Deploying+a+CAR+File+with+the+Maven+Plug-In.
When executing command "mvn clean install" on my ESB Config Project, I get this error :
[ERROR] The goal you specified requires a project to execute but there is no POM in this directory ([ESB Config Project Path]\target\capp).
Please verify you invoked Maven from the correct directory. -> [Help 1]
Indeed, the install goal is configured to be executed in "target/capp" directory :
<directory>target/capp</directory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
<extensions>true</extensions>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>mvn</executable>
<workingDirectory>${project.build.directory}</workingDirectory>
<arguments>
<argument>clean</argument>
<argument>install</argument>
<argument>-Dmaven.test.skip=${maven.test.skip}</argument>
</arguments>
</configuration>
</execution>
...
Then I tried to create a "Maven Multi Module Project", as suggested here : maven build for WSo2 artifacts, but I did not found any solution to make it work :
following the steps from this documentation (https://docs.wso2.com/display/DVS310/Using+Maven+with+Developer+Studio?src=search), I created a "Maven Multi Module Project", and selected my Config, Resources and Composite projects as children. Then I launched the "mvn clean install" command, but still getting the error on ESB Config Project (no POM in target/capp folder).
Actually, I just did not found any information about these errors, and do not understand why the WSO2 documented solution did not work for me.
Does anyone have a suggestion about that ? How does WSO2 Developer Studio generate the .car file ?
Thanks
I found another answer for this problem. The exec-maven-plugin version seems to be buggy. The WSO2 Developer Studio 3.7.0 add a buggy version (1.2) when creating the project. You just have to change the artifact from:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2</version>
to:
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
See this as a complementary information:
exec-maven-plugin says cannot run specified program, even though it is on the PATH
I finally succeded in generating a .car file and creating a maven multi module project.
I was trying to create all my maven projects with WSO2 Developer Studio 3.7.0, although the sample said to use version 3.2.0. As the WSO2's maven plugins versions change, it now works fine for me, executing maven install with plugin v2.0.4.
And a maven multi module project is finally just a maven project with modules, so it is OK.

Resources