cucumber runner files is not able to pickup features/classes when run from maven - eclipse

I am able to run my cucumber runner file(as JUnit) without any issues. Tests are picked up and running fine.
But when i run through maven, though maven points to the Runner file, unable to execute tests.
Please find my maven logs and pom.xml file. Can someone help me what is missing in pom.xml? or eclipse configuration?
[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 LinenHousePOC 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # LinenHousePOC ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory E:\Programming\Cucumber\LinenHousePOC\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # LinenHousePOC ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # LinenHousePOC ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # LinenHousePOC ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # LinenHousePOC ---
[INFO] Surefire report directory: E:\Programming\Cucumber\LinenHousePOC\target\surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running runners.RunnerTest
Configuring TestNG with: org.apache.maven.surefire.testng.conf.TestNG652Configurator#7f7052
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 2.041 sec
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 13.463 s
[INFO] Finished at: 2016-07-03T10:45:17+05:30
[INFO] Final Memory: 8M/19M
[INFO] ------------------------------------------------------------------------
Following is my 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">
<modelVersion>4.0.0</modelVersion>
<groupId>LinenHousePOC</groupId>
<artifactId>LinenHousePOC</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.1.5</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.47.1</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.0</version>
</dependency>
</dependencies>
</project>

Update in your POM build!!
use below configuration and run mvn clean verify. If you don't want to run tests in parallel, remove parallel, perCoreThreadCount and threadCountClasses tags. Make sure to update the regular expression to match your test naming convention **/Run*.java
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<id>acceptance-test</id>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<outputEncoding>UTF-8</outputEncoding>
<parallel>classes</parallel>
<perCoreThreadCount>true</perCoreThreadCount>
<threadCountClasses>10</threadCountClasses>
<argLine>-Xmx1024m</argLine>
<argLine>-XX:MaxPermSize=256m</argLine>
<includes>
<include>**/Run*.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>

Executing the tests from IDE is different from executing the tests from Command Line (Maven).
In IDE, the configuration, the context variables are automatically initialized or picked when we invoke the tests. Where as in the Maven Execution, few parameters needs to be explicitly mentioned.
when you invoke a test in :
Executing tests with Maven (command line)
mvn clean test -Dcucumber.options="--format json-pretty --glue classpath:src/test/resources"
The above command will set the glue from where the tests needs to be picked by maven to invoke the tests.
This glue information is same as the information passed as input in the CucumberOptions in the CucumberRunner.java
Executing tests with Maven (using Maven Profile)
Create a profile and pass the cucumber.options as input parameters as shown below:
<profiles>
<profile>
<id>cucumber-tests</id>
<properties>
<cucumber.options>--glue src/test/resources</cucumber.options>
</properties>
. . .
</profile>
</profiles>

Related

maven cannot run junit test for plug-in project

I am using "maven-surefire-plugin" to my junit test, but after running "mvn surefire:test", I cannot see any error information and also cannot see the report.
here are my pom.xml
<project >
<modelVersion>4.0.0</modelVersion>
<groupId>mygroupId</groupId>
<artifactId>myartifactId</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<parent>
<groupId>mygroupId</groupId>
<artifactId>myPArtifactId</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit5-engine</artifactId>
<version>5.0.0-ALPHA</version>
</dependency>
</dependencies>
<build>
<directory>${project.basedir}/target</directory>
<testSourceDirectory>${project.build.directory}/src</testSourceDirectory>
<testOutputDirectory>${project.build.directory}/test-classes</testOutputDirectory>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<resources>
<resource>
<directory>${project.basedir}/src</directory>
</resource>
</resources>
<testResources>
<testResource>
<directory>${project.basedir}/src</directory>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Please notify that my packaging type is "eclipse-plugin", and here are the output
[INFO] Scanning for projects...
[WARNING] No explicit target runtime environment configuration. Build is platform dependent.
[INFO] Computing target platform for MavenProject: com.packtpub.e4:com.packtpub.e4.clock.ui:1.0.0-SNAPSHOT # C:\eclipse_workspaceBookNew\com.packtpub.e4.clock.ui\pom.xml
[INFO] Fetching p2.index from http://download.eclipse.org/releases/oxygen/
[INFO] Adding repository http://download.eclipse.org/releases/oxygen
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/oxygen/
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/oxygen/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/oxygen/201710111001/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/oxygen/201710111001/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/oxygen/201709271000/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/oxygen/201709271000/
[INFO] Resolving dependencies of MavenProject: com.packtpub.e4:com.packtpub.e4.clock.ui:1.0.0-SNAPSHOT # C:\eclipse_workspaceBookNew\com.packtpub.e4.clock.ui\pom.xml
[INFO] Resolving class path of MavenProject: com.packtpub.e4:com.packtpub.e4.clock.ui:1.0.0-SNAPSHOT # C:\eclipse_workspaceBookNew\com.packtpub.e4.clock.ui\pom.xml
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building com.packtpub.e4.clock.ui 1.0.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-surefire-plugin:2.20.1:test (default-cli) # com.packtpub.e4.clock.ui ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 12.310 s
[INFO] Finished at: 2017-10-27T15:13:45+08:00
[INFO] Final Memory: 50M/441M
[INFO] ------------------------------------------------------------------------
as you can see, Though there is no error, the tests doesn't run at all.
Assuming the tests are packages in an appropriate directory structure, you might want to use the following configuration instead :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version> <!-- Specific due to memory leak in 2.20 -->
<dependencies>
<!--Custom provider and engine for Junit 5 to surefire-->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.0.1</version>
</dependency>
</dependencies>
<configuration>
<argLine>${argLine}</argLine>
</configuration>
</plugin>

Error with variable declaration - java.lang.NoSuchMethodError: scala.runtime.IntRef.create(I)Lscala/runtime/IntRef; - scala version mismatch

I am working with a Spark/Scala application on intelliJ with Maven. I am trying to write a file and after the writing is complete, I am trying to read it line by line and increment a variable named count depending on a condition. Here is my code:
val writer: BufferedWriter = new BufferedWriter(new FileWriter("test.csv"))
/* Logic
for
writing
the file
*/
writer.close()
var count = 0
val bufferedSource = Source.fromFile("test.csv")
for(line <- bufferedSource.getLines()){
count = count+1
line.split(",").foreach(x => {if(x.toString == "1") count = count+1})
}
bufferedSource.close()
When I run the above code, it gives me the following error:
Exception in thread "main" java.lang.NoSuchMethodError: scala.runtime.IntRef.create(I)Lscala/runtime/IntRef;
It is throwing the error at the variable declaration statement: var count = 0
I searched for this error online and found the reason to be scala version mismatch, as pointed out here: NoSuchMethodError when declaring a variable
Initially, I had my project SDK setup to 2.10.6. That's the default version I use for my projects. I didn't mention any scala language dependency in my pom.xml. And when I run the mvn -U package command for building the jar, I get the following messages:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building project
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # IPscan ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\zkh9xcl\workspace\IPscan\src\main\resources
[INFO]
[INFO] --- scala-maven-plugin:3.2.2:compile (scala-compile-first) # IPscan ---
[WARNING] Expected all dependencies to require Scala version: 2.11.7
[WARNING] com.databricks:spark-csv_2.11:1.4.0 requires scala version: 2.11.7
[WARNING] com.twitter:chill_2.10:0.5.0 requires scala version: 2.10.4
[WARNING] Multiple versions of scala libraries detected!
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # IPscan ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # IPscan ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\zkh9xcl\workspace\IPscan\src\test\resources
[INFO]
[INFO] --- scala-maven-plugin:3.2.2:testCompile (scala-test-compile) # IPscan ---
[WARNING] Expected all dependencies to require Scala version: 2.11.7
[WARNING] com.databricks:spark-csv_2.11:1.4.0 requires scala version: 2.11.7
[WARNING] com.twitter:chill_2.10:0.5.0 requires scala version: 2.10.4
[WARNING] Multiple versions of scala libraries detected!
[INFO] No sources to compile
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # IPscan ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # IPscan ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # IPscan ---
[INFO]
[INFO] --- maven-shade-plugin:2.4.1:shade (default) # IPscan ---
[INFO] Including com.databricks:spark-csv_2.11:jar:1.4.0 in the shaded jar.
[INFO] Including org.scala-lang:scala-library:jar:2.11.7 in the shaded jar.
[INFO] Including org.apache.commons:commons-csv:jar:1.1 in the shaded jar.
[INFO] Including com.univocity:univocity-parsers:jar:1.5.1 in the shaded jar.
[INFO] Skipping pom dependency org.jodd:jodd:pom:3.4.0 in the shaded jar.
[INFO] Including org.threeten:threetenbp:jar:1.3.3 in the shaded jar.
[INFO] Attaching shaded artifact.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.054 s
[INFO] Finished at: 2017-10-26T11:18:39-04:00
[INFO] Final Memory: 38M/663M
[INFO] ------------------------------------------------------------------------
It is throwing a warning saying: [WARNING] Multiple versions of scala libraries detected!
Here's my 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>project</groupId>
<artifactId></artifactId>
<version>1.0-SNAPSHOT</version>
<name>IPscan</name>
<repositories>
<repository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>scala-tools.org</id>
<name>Scala-tools Maven2 Repository</name>
<url>http://scala-tools.org/repo-releases</url>
</pluginRepository>
</pluginRepositories>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>scala-test-compile</id>
<phase>process-test-resources</phase>
<goals>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<relocations>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>org.shaded.apache.http</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>*:*</artifact>
</filter>
</filters>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>shaded</shadedClassifierName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.databricks</groupId>
<artifactId>spark-csv_2.11</artifactId>
<version>1.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jodd/jodd -->
<dependency>
<groupId>org.jodd</groupId>
<artifactId>jodd</artifactId>
<version>3.4.0</version>
<type>pom</type>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-core_2.10 -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_2.10</artifactId>
<version>1.6.0</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- https://mvnrepository.com/artifact/org.threeten/threetenbp -->
<dependency>
<groupId>org.threeten</groupId>
<artifactId>threetenbp</artifactId>
<version>1.3.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.spark/spark-hive_2.10 -->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_2.10</artifactId>
<version>1.6.0</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
I am new to maven, please excuse me if there is a probelm with my pom.xml.
I am not sure why there are multiple versions of scala libraries included in the jar. I actually changed the java version to 2.11.7 and then to 2.10.4 in the global libraries of the project in intelliJ, but it gives a problem saying Library scala-sdk-2.10.4 is not used [Fix]. I am pretty sure I added 2.10.4 to the list of dependencies in intelliJ. No matter what I do, I still get the multiple scala versions warning when I build the jar and the noSuchMethodError still persists. Looks like I am missing something.
What is causing the error? And what is the best way to overcome this and avoid it in the future? Any help would be appreciated. Thank you!
P.S: I am using Spark 1.6 and I can't upgrade to a newer version.
Its a simple case of dependency mismatch. My guess is that it is because of the spark-csv package by com.databricks. Can you change the version to 2.10 and try again.
Let me know if this helped. Cheers.

Maven doesn´t check JUnit tests

I configured Maven with Junit using mainly this tutorial:
http://maven.apache.org/surefire/maven-surefire-plugin/examples/junit.html
I have a one test Class and when I execute "mvn test", this test Class is caught by Maven but Maven doesn´t check it (The result should be FAIL).
C:\Users\User\git\example\example>mvn test
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building passport 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # passport -
--
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 1 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # passport ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # pa
ssport ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources,
i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # passpor
t ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.18.1:test (default-test) # passport ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.472 s
[INFO] Finished at: 2015-04-22T12:07:27+02:00
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------
My Test Class is in src/main/resources (the console shows "Copying 1 resource"):
package main.resources;
import static org.junit.Assert.*;
import org.junit.Test;
public class exampleTest {
#Test
public void test() {
int result = 5;
assertTrue(result == 2);
}
}
My 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">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>passport</name>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
</configuration>
<dependencies>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-junit47</artifactId>
<version>2.18.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Maven version:
Apache Maven 3.3.1 (cab6659f9874fa96462afef40fcf6bc033d58c1c; 2015-03-13T21:10:2
7+01:00)
Maven home: C:\apache-maven-3.3.1\bin\..
Java version: 1.8.0_40, vendor: Oracle Corporation
Java home: C:\Program Files\Java\jdk1.8.0_40\jre
Default locale: es_ES, platform encoding: Cp1252
OS name: "windows 8.1", version: "6.3", arch: "amd64", family: "dos"
Any idea why don´t check the test Case?
Other question, I don´t know because shows a warning about enconding CP1252 when I have configured my project with UTF-8.
Your test class must reside in src/test/java and NOT in src/main/resources Take a look at the default folder layout.
Based on your question the following should be made part of your pom:
<project>
...
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
...
</project>

build-helper-maven-plugin add-source doesn't work

I'm using maven-processor-plugin to generate my metamodel classes, now I'd like to ad the generated foldet to my build path to use the classes generated in my code. However when I run mvn install, my metamodel is generated correctly, but the folder is not added as source folder. Here's my 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">
<modelVersion>4.0.0</modelVersion>
<groupId>intl</groupId>
<artifactId>intl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.4.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>4.3.4.Final</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.28</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>16.0.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>2.2.4</version>
<executions>
<execution>
<id>process</id>
<goals>
<goal>process</goal>
</goals>
<phase>generate-source</phase>
<configuration>
<processors>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</processors>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>add-source</id>
<phase>generate-source</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/annotations</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
</plugins>
</build> </project>
I have no error, maven says BUILD SUCCESS but no source folder added. Can someone see what I did wrong? Sorry if it's obvious I'm a newbie to all things maven-related.
Here's the output I got when running mvn install:
[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 intl 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # intl ---
[INFO] Deleting C:\Users\myuser\Workspace\intl\intl\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # intl ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\myuser\Workspace\intl\intl\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # intl ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 9 source files to C:\Users\myuser\Workspace\intl\intl\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # intl ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\myuser\Workspace\intl\intl\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # intl ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # intl ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-war-plugin:2.3:war (default-war) # intl ---
[INFO] Packaging webapp
[INFO] Assembling webapp [intl] in [C:\Users\myuser\Workspace\intl\intl\target\intl-0.0.1-SNAPSHOT]
[INFO] Processing war project
[INFO] Webapp assembled in [52 msecs]
[INFO] Building war: C:\Users\myuser\Workspace\intl\intl\target\intl-0.0.1-SNAPSHOT.war
[INFO]
[INFO] --- maven-install-plugin:2.4:install (default-install) # intl ---
[INFO] Installing C:\Users\myuser\Workspace\intl\intl\target\intl-0.0.1-SNAPSHOT.war to C:\Users\myuser\.m2\repository\intl\intl\0.0.1-SNAPSHOT\intl-0.0.1-SNAPSHOT.war
[INFO] Installing C:\Users\myuser\Workspace\intl\intl\pom.xml to C:\Users\myuser\.m2\repository\intl\intl\0.0.1-SNAPSHOT\intl-0.0.1-SNAPSHOT.pom
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.771 s
[INFO] Finished at: 2014-03-30T13:39:30+01:00
[INFO] Final Memory: 16M/244M
[INFO] ------------------------------------------------------------------------
You use srcas path for the generated sources, but add ${project.build.directory}/generated-sources/annotations as source folder.
Change the outputDirectory property of maven-processor-plugin to ${project.build.directory}/generated-sources/annotations, and every should work as intended.
Update
In your current logfile, neither process nor build-helper plugin are executed. This is due to a type in your phase. The phase is named generate-sources, but you wrote generate-source.
If your eclipse is recent enough, it should either work out of the box, or the project should show an "unknown lifecycle..." error, whose first quick fix (discover...) will download an m2e-buildhelper plugin which will show the generated sources in your eclipse as well.
#DeleteMePlease: neither maven-processor-plugin nor build-helper-maven-plugin show up in the log. I.e. neither of them are executed. As stated by #blackbuild, it's due to a typo mistake. When a phase is unknown, Maven ignores the associated goal(s) during a build.
But there is may be an other issue: in the pom, first maven-processor-plugin then build-helper-maven-plugin are declared in the section build/plugins with the same phase, i.e.: generate-sources. In such a case, the declaration order is the runtime order: maven-processor-plugin will run before build-helper-maven-plugin, i.e. before this last plugin has specified any folder as a source one. As maven-compiler-plugin will run later it shouldn't be an issue. If it is, then two options:
keep the two plugins in the same section but swap their order;
move build-helper-maven-plugin in an earlier phase, e.g. initialize.

Reading a properties file in a Maven test

This seems like such a silly question but no solutions I've found online have worked for me. I'm writing an integration test in a Maven project, and I need to read values from a properties file, which I've put in src/test/resources.
My test tries to read this properties file during construction:
public ControllerIT() throws Exception {
wc = new WebConversation();
prop = new Properties();
InputStream stream = getClass().getResourceAsStream( "/test.properties" );
prop.load( stream );
}
When I run the test, I always get a NullPointerException on the call to prop.load( stream );.
I've tried just about every permutation of solutions that I've found online:
Referencing the file as test.properties instead of /test.properties
Getting the input stream via getClass().getClassLoader().getResourceAsStream( "test.properties" );
But nothing works.
And I guess for extra points, the ideal solution would allow me to run this test via mvn integration-test on the CLI as well as in Eclipse via Run As -> JUnit test. To that end, I guess I should also mention that I've explicitly added main/test/resources as a source folder in Eclipse, but it's still not loading the file correctly.
And as requested, here is my POM:
<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>com.example</groupId>
<artifactId>listener-testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>listener-testing</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<!-- Failsafe configuration for running integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.16</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<!-- Surefire configuration for generating reports -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.16</version>
<reportSets>
<reportSet>
<id>integration-tests</id>
<reports>
<report>failsafe-report-only </report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>httpunit</groupId>
<artifactId>httpunit</artifactId>
<version>1.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.x</version>
</dependency>
</dependencies>
</project>
As you can see, this is a stand-alone integration test suite (it basically just sends POST requests to a web service). I run it with mvn verify and see:
$ mvn verify
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building listener-testing
[INFO] task-segment: [verify]
[INFO] ------------------------------------------------------------------------
[INFO] [site:attach-descriptor {execution: default-attach-descriptor}]
Downloading: http://artifactory:8081/artifactory/simple/vm/junit/junit/debian/junit- debian.pom
[INFO] Unable to find resource 'junit:junit:pom:debian' in repository libs-release (http://artifactory:8081/artifactory/libs-release)
Downloading: http://artifactory:8081/artifactory/simple/vm/junit/junit/debian/junit-debian.pom
[INFO] Unable to find resource 'junit:junit:pom:debian' in repository central (http://repo1.maven.org/maven2)
[INFO] [failsafe:integration-test {execution: default}]
[INFO] Failsafe report directory: /home/jmp/desktop/listener-testing/target/failsafe-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running com.example.integration.ControllerIT
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.156 sec <<< FAILURE! - in com.example.integration.ControllerIT
testRequest(com.example.integration.ControllerIT) Time elapsed: 0.006 sec <<< ERROR!
java.lang.NullPointerException: null
at java.util.Properties$LineReader.readLine(Properties.java:435)
at java.util.Properties.load0(Properties.java:354)
at java.util.Properties.load(Properties.java:342)
at com.example.integration.ControllerIT.<init> (ControllerIT.java:30)
Results :
Tests in error:
ControllerIT.<init>:30 » NullPointer
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] [failsafe:verify {execution: default}]
[INFO] Failsafe report directory: /home/jmp/desktop/listener-testing/target/failsafe-reports
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] There are test failures.
Please refer to /home/jmp/desktop/listener-testing/target/failsafe-reports for the individual test results.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Fri Mar 14 10:13:04 GMT 2014
[INFO] Final Memory: 12M/125M
[INFO] ------------------------------------------------------------------------
In this output, line 30 of ControllerIT is the call to prop.load( inputstream ).
Your project is of packaging type pom. That way, resources-plugin is not included in lifecycle (and no resources will be copied over to target and thus land in the classpath)
Change your packaging to jar, and everything should work.