Why cobertura reports code coverage as zero for all but one module in multi-module maven project? - cobertura

I am trying to generate code coverage report for our multi-module maven project using cobertura. After I run mvn clean and then run mvn package. Then, in one of the modules from where we run JUnit tests, the coverage report generated for that module is correct as expected. But the coverage is only for a few packages. Not all packages are covered. Remember it is a multi-module project with one parent POM and each child module having its own POM. Should I also include the cobertura maven plugin details in each of those child POMs ?
However, the individual module specific coverage report generated in the other /target/site/cobertura directories is reported as zero for both line coverage and branch coverage.
Am I missing something, in my parent POM ?, I have not made any changes to
any of the child POMs in the directories. Please let me know
how to generate the code coverage report for a multi module maven project
using cobertura.
Here is how my parent POM looks like.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<formats>
<format>html</format>
<format>xml</format>
</formats>
</configuration>
<inherited>true</inherited>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>cobertura</goal>
</goals>
</execution>
</executions>
</plugin>
...
<dependencies>
<dependency>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.5.1</version>
<type>plugin</type>
<scope>package</scope>
</dependency>
</dependencies>
Thanks!

According to the docs, there's a distinction between plugins that run as part of the build and plugins that run as part of reporting :
http://maven.apache.org/guides/mini/guide-configuring-plugins.html
your using 'executions' suggests that you have the plugin under 'build' whereas apparently it belongs under 'reporting' - as per the cobertura usage page :
http://mojo.codehaus.org/cobertura-maven-plugin/usage.html
Try removing cobertura plugin completely from 'build', and instead putting it under 'reporting' :
<project>
<!-- project stuff-->
<build>
<!-- build stuff -->
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<formats>
<format>html</format>
</formats>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
then run it either with
mvn cobertura:cobertura
or with
mvn site

Related

vaadin-maven-plugin npm registry configuration

For context, I'm running a jenkins build which has no direct internet access. We have a nexus with proxy repositories for maven, nodejs and npm.
I'm using the recommended frontend-maven-plugin to download and install node and npm. This step works fine. Afterwards the vaadin-maven-plugin is used with the prepare-frontend and build-frontend goals.
Apparently, this triggers the actual npm install so I need it to contact the private npm registry, yet I can't find any setting to specify this. I did find a npmRegistryURL variable in the vaadin-maven-plugin configuration, but apparently this isn't used for the build-frontend goal.
My pom setup looks like this:
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v12.13.0</nodeVersion>
<nodeDownloadRoot>https://nexusrepo.com/repository/nodejs/</nodeDownloadRoot>
<npmDownloadRoot>https://nexusrepo.com/repository/npmjs/</npmDownloadRoot>
</configuration>
</plugin>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<executions>
<execution>
<id>prep</id>
<goals>
<goal>prepare-frontend</goal>
<goal>build-frontend</goal>
</goals>
</execution>
</executions>
<configuration>
<npmRegistryURL>https://nexusrepo.com/repository/npmjs/</npmRegistryURL>
</configuration>
</plugin>
</plugins>
</build>
I've also tried to let the frontend-maven-plugin handle the npm install but that doesn't work because the vaadin-maven-plugin is manually adding extras to the node_modules/#vaadin folder.
So I got the same Error: Cannot find module '#vaadin/stats-plugin' as specified in Vaadin issue 10306
I've also tried to add a .npmrc file to the root of my project to specify the npm registry, but that had no effect. Should this work or is it simply not checked by the vaadin-maven-plugin?
Some help would be greatly appreciated. I can't manually configure the node installation by using npm config set registry because it's not a static node installation, so the configuration needs to happen inside of the actual maven build.
After quite a bit of searching and testing, there seem to be 2 ways of solving this problem.
Option 1 is to configure the frontend-maven-plugin with an npm execution/goal.
The default argument is install, but it doesn't have to be. That way you can use this execution to run the npm config set registry command.
<execution>
<id>npm config</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>config set registry https://nexusrepo.com/repository/npmjs/</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
WARNING: from my experience, this saves the given registry in a user folder .npmrc file, which would probably affect every npm build on your jenkins, since it would save it for the default jenkins-user. Therefore, this did not seem like a proper solution.
Option 2 is adding a .npmrc file to the root of your project.
I tried doing this at first but it didn't work (as specified in the question). This only seemed to be the case on my local workstation, probably because I also had nodejs and npm actually installed and the settings were being overridden somewhere else. During the jenkins build this worked as intended.
Option 2 definitely seemed like the better way to go forward, so that's what I did for now. Still annoyed by the lack of vaadin-maven-plugin documentation, but at least I got it to work.

New Vaadin 14 app fails to run, error "Failed to determine 'node' tool." Missing Node.js and npm tools

I used the Get Started page to create a new Vaadin 14 app, after choosing the Plain Java Servlet option.
The web page successfully downloaded a .zip file which I unzipped, and opened with IntelliJ Ultimate Edition version 2019.2. I waited a few minutes while Maven did its thing, downloading and reconfiguring the project. Eventually I went to the Maven panel within IntelliJ, and ran the Lifecycle items clean and install.
I received the following error message on the console.
[ERROR] Failed to execute goal com.vaadin:vaadin-maven-plugin:14.0.0:prepare-frontend (default) on project acme: Execution default of goal com.vaadin:vaadin-maven-plugin:14.0.0:prepare-frontend failed:
[ERROR]
[ERROR] ======================================================================================================
[ERROR] Failed to determine 'node' tool.
[ERROR] Please install it either:
[ERROR] - by following the https://nodejs.org/en/download/ guide to install it globally
[ERROR] - or by running the frontend-maven-plugin goal to install it in this project:
[ERROR] $ mvn com.github.eirslett:frontend-maven-plugin:1.7.6:install-node-and-npm -DnodeVersion="v10.16.0"
[ERROR] ======================================================================================================
See discussion on Vaadin Forum.
I filed Ticket # 6262 Configure Maven to automatically install Node.js & npm, suggesting to the Vaadin team that requiring and omitting Node.js & npm is a problem.
Update: Non-issue in 14.2
Vaadin 14.2 & 16 have been changed to now include automatically the necessary npm tool in a Maven-driven project. No need to manually install Node.js & npm.
To quote this blog post:
Automatic Node.js install
Starting from versions 14.2 and 16, the Node.js install (which includes npm) happens automatically. It is installed to a .vaadin folder inside the home folder, and reused from there for all Vaadin projects. As before, Node is only used to build the frontend side of things; it does not run after you deploy for production!
And further improvement: pnpm instead of npm.
Frontend dependency management that just works - pnpm
Behind the scenes, npm has been used to manage frontend dependencies since 14.0. Now, we’ve added support for pnpm, which introduces the following benefits:
Shorter build time, compared to npm on your local machine and CI system, because pnpm only downloads packages once and reuses them from a local cache.
No need to delete package.json, lock file or the node_modules folder when updating the Vaadin version in your project.
In 14.2, npm is still used by default, but we encourage you to test pnpm and give us your feedback. Trying pnpm is easy: there is no migration, just enable it by using a configuration property or Maven plugin configuration. You can learn more about pnpm here. Vaadin 16 will use pnpm by default.
I have verified this works well. I have now manually removed the Node.js/npm installation from my Mac.
tl;dr
The Vaadin 14 team expects you to have Node.js and npm tools installed on your computer.
As alternative, Vaadin 14 seems to be working with Node.js/npm being automatically installed within your project (rather than globally on your computer) by the frontend-maven-plugin tool you can specify in your Maven POM file. See XML snippet below for your POM.
If you would prefer to install Mode/npm globally on your computer, be sure to read the other Answer by Tom Novosad.
Details
As of Vaadin 14, the Vaadin team is switching:
From HTML Imports, Bower, and WebJars
To ES6 Modules, npm, and Webpack, with Node.js
…as part of their transition from Polymer 2 to Polymer 3.
See blog post, Bower and npm in Vaadin 14+.
Hopefully, as Vaadin-on-Java users, we need not care about these underlying technical details… but for one thing: Unfortunately, the npm & Node.js tools are required but not bundled within your Vaadin project by default.
You have two solutions:
Install the tools globally.
Install within your project.
I prefer the latter. And I prefer to have Maven auto-install them within my project, with less housekeeping for me to do manually.
CAVEAT: I do not know the limitations or ramifications of my node/npm-per-project solution. I barely have any idea of the purpose or nature of either node/npm, and have no idea how Vaadin makes use of them. So use this solution at your own risk. All I can say is that it seems to be working for me.
Add frontend-maven-plugin to your project
The frontend-maven-plugin tool can be used by Maven to download and install Node.js with npm within your Vaadin project.
Open the Maven POM file within your Vaadin project.
Add the following block inside the <build> <defaultGoal>jetty:run</defaultGoal> <plugins> element of that POM.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- Use the latest released version:
https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
<version>1.8.0</version>
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v10.16.3</nodeVersion>
<!-- optional: with node version greater than 4.0.0 will use npm provided by node distribution -->
<!-- <npmVersion>2.15.9</npmVersion>-->
<!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
<!-- <downloadRoot>http://myproxy.example.org/nodejs/</downloadRoot>-->
</configuration>
</plugin>
Of course, you can tweak that snippet to use the latest version numbers. Check the Node.js page for the latest versions number.
Notice that we commented-out the npm item, as that tool is bundled with the latest versions of Node.js.
Remaining steps:
In the Maven panel within IntelliJ, run the Lifecycle items named clean and install. Wait a moment as some more items are downloaded and configured. (Notice the item "Installing node version v10.16.3" in your console history.)
In that same panel, in the section Plugins > jetty, run the jetty:run item. Wait a moment as the Jetty server launches to run your Vaadin app.
On the console you should see something like this (that mysterious Quiet Time warning is perennial with all releases of Vaadin):
[INFO] Started Jetty Server
[INFO] Using Non-Native Java sun.nio.fs.PollingWatchService
[WARNING] Quiet Time is too low for non-native WatchService [sun.nio.fs.PollingWatchService]: 1000 < 5000 ms (defaulting to 5000 ms)
Point your web browser to: http://localhost:8080/ to see the "Click Me" button appear, as your app successfully runs.
This solution came from the project page for the Maven plugin frontend-maven-plugin. Note that the example POM fragment there is incorrect, failing to wrap the <execution> tag within a plural <executions> tag. I filed ticket # 838 there.
You may want to follow this discussion in the Vaadin Forums.
For your reference, here is a complete POM file to compare to yours.
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>work.basil.example</groupId>
<artifactId>acme</artifactId>
<name>acme</name>
<version>2.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<maven.compiler.source>13</maven.compiler.source>
<maven.compiler.target>13</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<failOnMissingWebXml>false</failOnMissingWebXml>
<vaadin.version>14.0.5</vaadin.version>
<drivers.downloader.phase>pre-integration-test</drivers.downloader.phase>
</properties>
<repositories>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<!-- Repository used by many Vaadin add-ons -->
<repository>
<id>Vaadin Directory</id>
<url>https://maven.vaadin.com/vaadin-addons</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-bom</artifactId>
<type>pom</type>
<scope>import</scope>
<version>${vaadin.version}</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<!-- Replace artifactId with vaadin-core to use only free components -->
<artifactId>vaadin</artifactId>
<exclusions>
<!-- Webjars are only needed when running in Vaadin 13 compatibility mode -->
<exclusion>
<groupId>com.vaadin.webjar</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars.bowergithub.insites</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars.bowergithub.polymer</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars.bowergithub.polymerelements</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars.bowergithub.vaadin</groupId>
<artifactId>*</artifactId>
</exclusion>
<exclusion>
<groupId>org.webjars.bowergithub.webcomponents</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Added to provide logging output as Vaadin uses -->
<!-- the unbound SLF4J no-operation (NOP) logger implementation -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-testbench</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<defaultGoal>jetty:run</defaultGoal>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<!-- Jetty plugin for easy testing without a server -->
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.19.v20190610</version>
<configuration>
<!-- If using IntelliJ IDEA with autocompilation, this
might cause lots of unnecessary compilations in the
background.-->
<scanIntervalSeconds>2</scanIntervalSeconds>
<!-- Use war output directory to get the webpack files -->
<webAppConfig>
<allowDuplicateFragmentNames>true</allowDuplicateFragmentNames>
</webAppConfig>
</configuration>
</plugin>
<!--
Take care of synchronizing java dependencies and imports in
package.json and main.js files.
It also creates webpack.config.js if not exists yet.
-->
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<version>${vaadin.version}</version>
<executions>
<execution>
<goals>
<goal>prepare-frontend</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- Use the latest released version:
https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
<version>1.8.0</version>
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks nice in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
</executions>
<configuration>
<nodeVersion>v10.16.3</nodeVersion>
<!-- optional: with node version greater than 4.0.0 will use npm provided by node distribution -->
<!-- <npmVersion>2.15.9</npmVersion>-->
<!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
<!-- <downloadRoot>http://myproxy.example.org/nodejs/</downloadRoot>-->
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<!-- Production mode is activated using -Pproduction -->
<id>production</id>
<properties>
<vaadin.productionMode>true</vaadin.productionMode>
</properties>
<dependencies>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.vaadin</groupId>
<artifactId>vaadin-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-frontend</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>integration-tests</id>
<build>
<plugins>
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>9.4.19.v20190610</version>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<stopPort>8081</stopPort>
<stopWait>5</stopWait>
<stopKey>${project.artifactId}</stopKey>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>deploy-war</goal>
</goals>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Runs the integration tests (*IT) after the server is started -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M3</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
<configuration>
<trimStackTrace>false</trimStackTrace>
<enableAssertions>true</enableAssertions>
<systemPropertyVariables>
<!-- Pass location of downloaded webdrivers to the tests -->
<webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>com.lazerycode.selenium</groupId>
<artifactId>driver-binary-downloader-maven-plugin</artifactId>
<version>1.0.17</version>
<configuration>
<onlyGetDriversForHostOperatingSystem>true
</onlyGetDriversForHostOperatingSystem>
<rootStandaloneServerDirectory>
${project.basedir}/drivers/driver
</rootStandaloneServerDirectory>
<downloadedZipFileDirectory>
${project.basedir}/drivers/driver_zips
</downloadedZipFileDirectory>
<customRepositoryMap>
${project.basedir}/drivers.xml
</customRepositoryMap>
</configuration>
<executions>
<execution>
<!-- use phase "none" to skip download step -->
<phase>${drivers.downloader.phase}</phase>
<goals>
<goal>selenium</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
The Problem is in method
FrontendUtils::getNpmExecutable(String baseDir)
from flow-server.jar. This method tries to locate
node/node_modules/npm/bin/npm-cli.js
in $baseDir (which is project root folder in case of prepare-frontend goal). When that path does not exist, code continues executing "where/which npm.cmd" to get absolute path of 'npm.cmd'. In my case, got NodeJS installed globally, it returns correct path.
Subsequently code continues trying to execute "path-to-npm.cmd\npm.cmd -v", to ensure that npm.cmd exists and is runnable.
And here is the problem in method:
ProcessBuilder FrontEndUtils::createProcessBuilder(List<String> command)
In this method under certain circumstances program code sets environment variable 'PATH' to path of npm.cmd (since ProcssBuilder.environment() returns map which does not contain 'PATH' variable).
Next when trying to execute command 'path-to-npm\npm.cmd -v', the exit value of the process is 1, and stderr is non-empty, because 'chcp' command is called before other stuff in 'npm.cmd' (probably SETLOCAL command), but since now 'chcp' is not in PATH.
Following code evaluates these conditions (exit code 1, stderr nonempty) as an error in execution of npm.cmd and
Failed to determine 'npm.cmd' tool.
message is printed.
This happens on my Windows 10, Vaadin Flow 14.0.1, NodeJS 10.16.3 installed globally.
Also got the same issues when running tomcat server with an application, since $baseDir variable contains path to tomcat bin directory.
Workaround
As a workaround it is sufficient to make symbolic link of NodeJS directory into your project root (and if application running on Tomcat, also make link of NodeJS to Tomcat's bin directory).
This problem appeared when I was testing new Vaadin 14.
I followed instructions, installed node, but I was doing that with previously opened Idea with another project (other to the this).
The problem went away only when I restarted Idea.
To be more exact there is a case when the real error can be found in the logs at plugin run:
Command '[C:\Program Files\nodejs\npm.cmd, -v]' failed with exit code '1'
but if you run the same command from prompt then you see that nothing wrong with the command and exit code.
As somebody mentioned the problem is that Windows tries to run "chcp" but it is not on the PATH (manipulated by the maven plugin). This happened in my case since I modified in the registry to run cmd always with UTF encoding. In Windows this is implemented by executing "chcp 65001" along with (before) any batch or command files like npm.cmd ...
My simple solution was copy chcp.com from System32 dir to nodejs directory...
After the installation of node i had the same problem compiling vaadin app.
It was needed to restart the PC to locate node and run successfully.
The solution I found was to add
-Dvaadin.project.basedir="/home/me/project/root/directory"
to your JVM startup args.
The answer came from this thread.
https://vaadin.com/forum/thread/18491365/vaadin-14-3-1-prepare-frontend-neede-at-every-eclipse-start
Almost same here.
Win 10, JDK 11.0.2, node 10.16.2 installed globally
mvn results in
[ERROR] Failed to determine 'npm.cmd' tool.
[ERROR] Please install it either:
[ERROR] - by following the https://nodejs.org/en/download/ guide to install it globally
[ERROR] - or by running the frontend-maven-plugin goal to install it in this project:
[ERROR] $ mvn com.github.eirslett:frontend-maven-plugin:1.7.6:install-node-and-npm -DnodeVersion="v10.16.0"
So... first advice to install it globally fails. second one works.

Maven install node modules in target directory

In my pom.xml this is how my front-end-maven-plugin config looks like.
My package.json and gulpfiles are in the projects root directory.
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<!-- Use the latest released version: https://repo1.maven.org/maven2/com/github/eirslett/frontend-maven-plugin/ -->
<version>1.6</version>
<executions>
<execution>
<!-- optional: you don't really need execution ids, but it looks nice
in your build log. -->
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<!-- optional: default phase is "generate-resources" -->
<phase>generate-resources</phase>
<configuration>
<!-- optional: The default argument is actually "install", so unless
you need to run some other npm command, you can remove this whole <configuration>
section. -->
<arguments>install ./target/node_modules</arguments>
</configuration>
</execution>
<execution>
<id>gulp</id>
<goals>
<goal>gulp</goal>
</goals>
<configuration>
<arguments>replace-runner-start</arguments>
</configuration>
</execution>
<execution>
<id>javascript tests</id>
<goals>
<goal>karma</goal>
</goals>
<!-- optional: the default plase is "test". Some developers choose
to run karma in the "integration-test" phase. -->
<phase>test</phase>
<configuration>
<!-- optional: the default is "karma.conf.js" in your working directory -->
<karmaConfPath>src/main/karma_webapp_all_conf.js</karmaConfPath>
</configuration>
</execution>
</executions>
<configuration>
<!-- <workingDirectory>src/main</workingDirectory> -->
<installDirectory>target</installDirectory>
<nodeVersion>v6.11.3</nodeVersion>
</configuration>
</plugin>
when i run mvn clean install like this i get node installed in target but node_modules cannot be installed there because the folder does not exist. Is there a way without another plugin to make the directory and install the node_modules there.
If someone still has this issue I suggest these options:
Set the install directory to target in the "Frontend Maven Plugin": https://github.com/eirslett/frontend-maven-plugin/blob/master/README.md#installation-directory
Don't use target at all for local development, but use the "Spring Boot DevTools" which handles everything in src and is my preferred way: https://docs.spring.io/spring-boot/docs/current/reference/html/using-spring-boot.html#using-boot-devtools
If you REALLY need node_modules in target, use the "Maven Resources Plugin" to copy the folder into target: https://maven.apache.org/plugins/maven-resources-plugin/examples/copy-resources.html
Looks like node_modules path is given wrong. Check the path of your node_modules. This can be done by
Global libraries
You can run npm list -g to see where global libraries are installed.
On Unix systems they are normally placed in /usr/local/lib/node or /usr/local/lib/node_modules when installed globally. If you set the NODE_PATH environment variable to this path, the modules can be found by node.
Windows XP - %USERPROFILE%\Application Data\npm\node_modules
Windows 7, 8 and 10 - %AppData%\npm\node_modules
Non-global libraries
Non-global libraries are installed the node_modules sub folder in the folder you are currently in.
You can run npm list to see the installed non-global libraries for your current location.

How to configure code coverage to work in Sonarqube using JaCoCo when unit tests are written in Groovy

I'm writing an application whose target classes (in src/main/java) are written / compiled to Java 7 but whose unit tests (in src/test/java) are written in Groovy. I am trying to get metrics from Sonarqube when I run mvn sonar:sonar. I get most everything, but I don't get code coverage metrics from JaCoCo. Instead I get the following message when the runner gets to the JaCoCo sensor:
Project coverage is set to 0% as no JaCoCo execution data has been dumped: C:\Users\fiddlerpianist\Projects\emailnotifier\target\jacoco.exec
However, when I run the EclEmma coverage (which uses JaCoCo) inside of Eclipse, I get full coverage reports with these Groovy tests. It just doesn't work through Sonarqube. Does anyone know why it doesn't work, or if there is a way I can configure something differently to make it work? I've tried a bunch of permutations of configuration, but so far... no luck.
The Maven java compiler plugin I'm using is configured a little differently (i.e. I use lombok):
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
<source>1.7</source>
<target>1.7</target>
<compilerArguments>
<javaAgentClass>lombok.core.Agent</javaAgentClass>
</compilerArguments>
<fork>true</fork>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>2.7.0-01</version>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>2.0.8-01</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.12.6</version>
</dependency>
</dependencies>
</plugin>
And I have my Groovy dependency scoped as test:
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.0.8</version>
<scope>test</scope>
</dependency>
</dependencies>
I'm using Sonarqube 3.7.4, Maven 3.1.1, Groovy 2.0.8, and Java 7. I'm using all the defaults for the Sonar Maven plugin (version 2.2).
So it turns out that you have to have at least one file with the .java extension (doesn't even have to be a test) in the src/test/java folder, and then everything works. It reminds me of a Groovy integration bug with Maven that used to require one Java file in with your Groovy code, but they since fixed that.

How to use cobertura.ser generated by ant to be used while running maven integration test

I run integration-test with cucumber cases (say: with tag#abc in feature files) with following command and pom.xml snippet -
pom.xml snippet:
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.11</version>
<configuration>
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*.class</include>
</includes>
<systemPropertyVariables>
<job.host.name>server-t10</job.host.name>
<job.email.notification>abc#abc.com</job.email.notification>
<cucumber.options>--format pretty --format
html:target/cucumber/cucumber-html</cucumber.options>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
...
mvn command to run the test case:
mvn clean integration-test -Dcucumber.options="--format pretty --format html:target/cucumber/cucumber-html1 --tags #abc" -Djob.host.name=server-t10
Every thing works fine with cases being executed and all reports produced. The problem arises when I try to get the coverage of the test cases.
I tried all possible combinations to generate a cobertura coverage report with cobertura-maven-plugin and version2.5.2 (without using ant instrumnet/report), but it just does not create any report, nor any .ser file or anything. Only logs say that - No files to instrument and does nothing.
Losing the battle, I finally downloaded cobertura (1.9.4.1) and created custom cobertura.xml. And when I run the following ant commands for ex -
ant -f cobertura.xml instrument
mvn clean integration-test -Dcucumber.options="--format pretty --format html:target/cucumber/cucumber-html1 --tags #abc" -Djob.host.name=server-t10
ant -f cobertura.xml report
Luckily though, it creates all the reports/.ser file etc. However, after running all of it, it shows as zero coverage in the final coverage report for all used classes. That could be because (as I think) the mvn command did not use/manipulate the cobertura.ser created by ant instrument.
So, please help me out in this, that what and where I put something in my pom.xml so that when I run the mvn command, it uses the instrumented file (output generated by ant insturment command) and update it. so that i can use that file for my report generation using ant report. I tried putting all possible entries in pom.xml. but it did not help.
Note: I am looking for this particular solution because all my efforts have gone wastedtrying to make cobertura-maven-plugin work. I dont' know the reason, but this plugin just doesn't work for me for creating report or even running the cases.

Resources