I am using maven jacoco plugin for code coverage. I decided to exclude some classes from jacoco coverage report. I found here, how to do it.
So my updated pom file looks like this:
<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>
<artifactId>payment-rest</artifactId>
<packaging>war</packaging>
<name>payment-rest</name>
<parent>
<artifactId>payment-ws</artifactId>
<groupId>com.example.foo</groupId>
<version>1.0.0-INTEGRATION-SNAPSHOT</version>
</parent>
<properties>
<jacoco.line.coverage>0.78</jacoco.line.coverage>
<jacoco.branch.coverage>1.00</jacoco.branch.coverage>
<servlet.version>3.0.1</servlet.version>
</properties>
<dependencies>
<!-- all dependecies here-->
</dependencies>
<build>
<finalName>payment-ws</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>sonar-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
**/com/example/foo/payment/configuration/**.*
</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<attachClasses>true</attachClasses>
<classesClassifier>classes</classesClassifier>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build>
</project>
So, when I am running mvn clean install command, I gets this error ():
Execution default-test of goal org.apache.maven.plugins:maven-surefire-plugin:2.19:test failed: The forked VM terminated without properly saying goodbye. VM crash or System.exit called?
If I remove exclusion part, project builds successfully.
Can someone advise me how can I solve this issue?
issue is occur because maven-surefire-plugin is missing into your project pom.xml. you need to add this plugin into pom.xml, after adding need to update and rebuild the project and run it.
you can find the maven plugin below:
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
</plugins>
you can refer higher version from 2.19.1.
Related
I have a simple java project with on Junit test case that has the current architecture:
pom.xml
src/main/java/com/Example.Java
src/test/java/com/ExampleTest.java
The contents of pom.xml are as follow:
<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>
<groupId>com</groupId>
<artifactId>SampleExample</artifactId>
<packaging>jar</packaging>
<version>1.0</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</project>
To execute the tests I simply call mvn test from bash. This as expected will run the test. Now to my question:
specifying javagent outside of maven is simply done by specificity the -javaagent option. How do I do this within the maven framework such that when I execute mvn test the agent I specify is loaded? (i.e how do I add custom arguments that maven will pass to the 'java' command when the tests are executed)
Define the Surefire plugin in your POM and pass the JVM arg via Surefire's configuration.
For example:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<argLine>-javaagent:/path/to/javaagent</argLine>
</configuration>
</plugin>
For background: the test goal is bound to surefire:test by default (more details on default bindings here) so you have been already been running the Surefire plugin perhaps without realising it. The only change now is that you need to change the configuration of the Surefire plugin and this requires you to include it explicitly in your POM as per the example I showed above. You cannot run the test goal without using the Surefire plugin and you cannot tell Surefire to use a JVM arg without configuring the Surefire plugin to do so.
I'm trying to exclude a complete folder to be embedded within a JAR. I found the following directive which works like a charm :
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/unwantedJars/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
So, when running mvn clean install, no problem, I get a JAR without the unwanted folder.
However, I have several projects which needs to include this directive (together with other common configuration), so I'm using a parent POM project. Everything is working well, apart the above directive. As soon as I move this exclude part to the parent POM definition, it doesn't work anymore.
Strange thing is that if I compare the effective POM of the 2 configuration, they're strictly identical!
What's the difference between having this directive on the POM of the current project or in the parent POM?
You need to use pluginManagement
parent-pom.xml
<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">
...
<build>
...
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<excludes>
<exclude>**/unwantedJars/**</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</pluginManagement>
...
</build>
</project>
child-pom.xml
<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">
...
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
</plugin>
</plugins>
...
</build>
</project>
I have found this solution on stackoverflow. Warning - Build path specifies execution environment J2SE-1.4
I am getting almost the same problem but instead of 1-4 i am having 1-6. Unfortunately I don't really understand this configuration thing. It's new thing to me. I am trying second answer to get this working. I found this pom.xml in src under my project and it's xml looks like this:
<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>eu.jpereira.trainings.designpatterns.creational.singleton</groupId>
<artifactId>singleton</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>singleton</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
</dependency>
</dependencies>
<!-- Configure Build Process -->
<build>
<plugins>
<!-- Compiler plugin to use Java 1.6 compatiblity -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<!-- Eclipse plugin to force download of source and JavaDoc jars -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<wtpversion>2.0</wtpversion>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
</plugins>
</build>
</project>
What and where should I add sth? I am using Eclipse on Windows 7. My version of java is: 1.8.0.25-b18 Words like plugin and Maven and JUnit are highlighted red. I would be grateful for help!
Try
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.4</source>
<target>1.4</target>
</configuration>
</plugin>
And then regenerate the Eclipse project with mvn eclipse:eclipse.
I am trying to use checkstyles google_checks.xml with maven-checkstyle-plugin. If I use the google_checks.xml with the latest checkstyle intelliJ plugin everything is correct but when I try configurating it via maven-checkstyle plugin I get this error:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.13:check (default-cli) on project XX_XX_XX: Failed during checkstyle configuration: cannot initialize module TreeWalker - Unable to instantiate AvoidEscapedUnicodeCharacters:
Unable to instantiate AvoidEscapedUnicodeCharactersCheck
My pom.xml looks like this:
<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">
<properties>
[...]
<checkstyle.file.path>develop/checkstyle/google_checks.xml</checkstyle.file.path>
</properties>
[...]
<build>
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.13</version>
<configuration>
<configLocation>${checkstyle.file.path}</configLocation>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.9.1</version>
<configuration>
<configLocation>${checkstyle.file.path}</configLocation>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
</plugins>
</reporting>
Do you guys have some suggestions about what could be wrong?
fixed this by updating the checkstyle-dependency manually to the latest stable version:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.13</version>
<dependencies>
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>${checkstyle.latest.version}</version>
</dependency>
</dependencies>
<configuration>
<configLocation>${checkstyle.file.path}</configLocation>
<failOnViolation>false</failOnViolation>
</configuration>
</plugin>
Maven checkstyle plugin uses checkstyle 5.7 (the first line of plugin description).
Checkstyle 5.7 does not have this check (see checks package on grepcode).
You need either to disable this check or to wait for official fix of MCHECKSTYLE-261.
I give a demo at
https://github.com/favoorr/Maven-Checkstyle-Multimodule-Use
Multi modules and use Google Chechstyle
I'm using Maven's exec:java to run jline for one of my projects (current POM attached below). The project used to be a single component, so all dependencies were in the same POM as the exec:java plugin definition. This worked great and all the dependencies were picked up and put on the classpath when I ran 'mvn exec:java'. However, I've now split up the project into a few modules and would like the dependencies from each module to be picked up when exec:java is run, but I can't figure out how to configure it. Advice would be greatly appreciated!
thanks,
Nick
<?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>Lensfield</name>
<groupId>org.lensfield</groupId>
<artifactId>lensfield-pom</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<includeProjectDependencies>true</includeProjectDependencies>
<includePluginDependencies>true</includePluginDependencies>
<executableDependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
</executableDependency>
<mainClass>jline.ConsoleRunner</mainClass>
<arguments>
<argument>clojure.lang.Repl</argument>
</arguments>
</configuration>
<dependencies>
<dependency>
<groupId>jline</groupId>
<artifactId>jline</artifactId>
<version>0.9.94</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<modules>
<module>lensfield-share</module>
<module>lensfield-build</module>
<module>lensfield-webapp</module>
</modules>
</project>
You can specify a parent POM for the project and define the exec-plugin in the pluginManagement section of the parent. This means that the plugin configuration will be available to any child POM that declares a minimal plugin configuration. The following would be sufficient.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
</plugin>
When the child is processed it will inherit the configuration from the parent, and the exec-plugin will be executed with the current project's dependencies.