maven cannot run junit test for plug-in project - eclipse

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>

Related

Error only with maven: NoClassDefFoundError: feign/codec/Encoder

I created a project in Eclipse with the Maven wizard and edited the pom.xml file to include my dependencies. My project, which uses Open Feign, builds and runs in Eclipse, but I get the following runtime error when I build it at the command line with Maven:
Error: Unable to initialize main class edu.mills.cs180a.BookRepositoryImplFeign
Caused by: java.lang.NoClassDefFoundError: feign/codec/Encoder
Here is my pom.xml file:
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>edu.mills.cs.180a</groupId>
<artifactId>book-client-example</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>book-client</name>
<description>Book REST API example</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>15</maven.compiler.target>
<maven.compiler.source> 15</maven.compiler.source>
</properties>
<dependencies>
<!-- Begin Open Feign dependencies -->
<!-- https://mvnrepository.com/artifact/io.github.openfeign/feign-core -->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-core</artifactId>
<version>11.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.github.openfeign/feign-jackson -->
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
<version>11.0</version>
</dependency>
<!-- End Open Feign dependencies -->
<dependency>
<groupId>io.github.openfeign.form</groupId>
<artifactId>feign-form</artifactId>
<version>3.8.0</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
<version>2.2.5.RELEASE</version>
</dependency>
</dependencies>
</project>
To build and run it in Eclipse, I only need the first two dependencies. I added the rest in an attempt to eliminate the error.
Here is a command-line transcript:
$ mvn -v
Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)
Maven home: C:\Program Files\apache-maven-3.6.3
Java version: 15.0.1, vendor: Oracle Corporation, runtime: C:\Program Files\Java\jdk-15.0.1
Default locale: en_US, platform encoding: Cp1252
OS name: "windows 10", version: "10.0", arch: "amd64", family: "windows"
$ mvn clean
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< edu.mills.cs.180a:book-client-example >----------------
[INFO] Building book-client 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # book-client-example ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.153 s
[INFO] Finished at: 2020-11-03T10:54:18-08:00
[INFO] -----------------------------------------------------------------------
$ mvn package
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< edu.mills.cs.180a:book-client-example >----------------
[INFO] Building book-client 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # book-client-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\ellen\eclipse-workspace9\book-client-example\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) # book-client-example ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 4 source files to C:\Users\ellen\eclipse-workspace9\book-client-example\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # book-client-example ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory C:\Users\ellen\eclipse-workspace9\book-client-example\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) # book-client-example ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # book-client-example ---
[INFO] No tests to run.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # book-client-example ---
[INFO] Building jar: C:\Users\ellen\eclipse-workspace9\book-client-example\target\book-client-example-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.748 s
[INFO] Finished at: 2020-11-03T10:54:25-08:00
[INFO] ------------------------------------------------------------------------
$ java -cp target/book-client-example-0.0.1-SNAPSHOT.jar edu.mills.cs180a.BookRepositoryImplFeign
Error: Unable to initialize main class edu.mills.cs180a.BookRepositoryImplFeign
Caused by: java.lang.NoClassDefFoundError: feign/codec/Encoder
See also the repo.
Update
Per below answer, I added this to pom.xml:
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>edu.mills.cs180a.BookRepositoryImplFeign</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
I still get the same error when I try building and running:
$ java -jar target/book-client-example-0.0.1-SNAPSHOT.jar
Error: Unable to initialize main class edu.mills.cs180a.BookRepositoryImplFeign
Caused by: java.lang.NoClassDefFoundError: feign/codec/Encoder
The problem is how you run your code in the end.
When you compile and build your project, Maven will put all your compiled code into your jar file. This is the one you add to the classpath for execution. But you already know there are two more dependencies which you did not specify.
What you may want Maven to do is copy all your dependencies to your target folder. This can be done via the maven dependency plugin.
Next, you probably do not want to specify all the required libs on the classpath when you run your code. At least in my projects I add the main class and the classpath into the manifest using the maven jar plugin.
Here is a snippet from my pom.xml:
<project>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>edu.mills.cs180a.BookRepositoryImplFeign</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project>
With that in your pom you should be able to run your code like this:
java -jar target\book-client-example-0.0.1-SNAPSHOT.jar

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

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>

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.

Trying to get ScalaTest working: "There are no tests to run" when doing "mvn test"

Edit: I finally got it to work!!!
It needed a combination of JUnit in the pom.xml, and three statements in my .scala:
import org.junit.runner.RunWith
import org.scalatest.junit.JUnitRunner
#RunWith(classOf[JUnitRunner])
For some reason, trying to configure Surefire makes the tests stop running again.
I'm coding in IntelliJ, trying to get a simple ScalaTest test running via a Maven (mvn test) build process. There aren't any errors, but unfortunately no tests run either.
Here is my .scala file:
import org.scalatest.FunSuite
import org.scalatest.BeforeAndAfter
class ExampleSuite extends FunSuite with BeforeAndAfter {
before {
println("Doing setup tasks...")
}
test("Example test of checking the browser title") {
val expected_title = "Company Platform"
var actual_title = "Company Platform"
assert(actual_title == expected_title)
}
after {
println("Doing teardown tasks...")
}
}
Here's the Maven output:
[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for JoeTestDemo:JoeTestDemo:jar:1.0
[WARNING] 'build.plugins.plugin.version' for org.scala-tools:maven-scala-plugin is missing. # line 42, column 21
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building JoeTestDemo 1.0
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # JoeTestDemo ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) # JoeTestDemo ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-scala-plugin:2.15.2:compile (default) # JoeTestDemo ---
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[WARNING] No source files found.
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) # JoeTestDemo ---
[WARNING] Using platform encoding (MacRoman actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/Joeshaver/Projects/JoeTestDemo/src/test/resources
[INFO]
[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) # JoeTestDemo ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-scala-plugin:2.15.2:testCompile (default) # JoeTestDemo ---
[INFO] Checking for multiple versions of scala
[INFO] includes = [**/*.scala,**/*.java,]
[INFO] excludes = []
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.7.2:test (default-test) # JoeTestDemo ---
[INFO] Surefire report directory: /Users/Joeshaver/Projects/JoeTestDemo/target/surefire-reports
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.368s
[INFO] Finished at: Tue Oct 23 10:58:30 PDT 2012
[INFO] Final Memory: 6M/81M
[INFO] ------------------------------------------------------------------------
Here is the pom.xml. I think my Maven Scala plugin might not be right:
<?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>JoeTestDemo</groupId>
<artifactId>JoeTestDemo</artifactId>
<version>1.0</version>
<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>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.9.0-1</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.9.0-1</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDir>src/main/java</sourceDir>
<jvmArgs>
<jvmArg>-Xms64m</jvmArg>
<jvmArg>-Xmx1024m</jvmArg>
</jvmArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
You might want to use the scalatest-maven-plugin to run your scala tests.
Also make sure that you use the <scope>test</scope> for jars needed only for test purposes.
This is how I have defined my pom.xml for using ScalaTest:
<?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>
<groupId>com.stackoverflow</groupId>
<artifactId>Q13036561</artifactId>
<version>1.0-SNAPSHOT</version>
<name>${project.artifactId}-${project.version}</name>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<scala.version>2.9.2</scala.version>
<scalatest.version>2.0.M4</scalatest.version>
</properties>
<dependencies>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>${scala.version}</version>
</dependency>
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_${scala.version}</artifactId>
<version>${scalatest.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
<version>2.15.2</version>
<executions>
<execution>
<id>scala-compile</id>
<goals>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
<configuration>
<args>
<arg>-make:transitive</arg>
<arg>-dependencyfile</arg>
<arg>${project.build.directory}/.scala_dependencies</arg>
</args>
</configuration>
</execution>
</executions>
</plugin>
<!--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.7.2</version>
<executions>
<execution>
<id>default-test</id>
< ! - Disable the default-test by putting it in phase none - >
<phase>none</phase>
</execution>
</executions>
</plugin>
-->
<plugin>
<groupId>org.scalatest</groupId>
<artifactId>scalatest-maven-plugin</artifactId>
<version>1.0-M2</version>
<configuration>
<reportsDirectory>${project.build.directory}/surefire-reports</reportsDirectory>
<stdout>W</stdout> <!-- Skip coloring output -->
</configuration>
<executions>
<execution>
<id>scala-test</id>
<goals>
<goal>test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
As you can see I have also added a section that disables the surefire plugin if you really don't want to run it. It is commented in the above pom but if you want to disable the surefire plugin just uncomment that part.
I am using IntelliJ too and there are no problems at all with this combination. Just run the tests from within IntelliJ or by using mvn test, they will both work.
If you're running on Maven, then you'll either have to annotate your test class(es) with
#RunWith(classOf[JUnitRunner])
This would require you having JUnit as a dependency. Or you could use the ScalaTest Maven Plugin (haven't used it myself though).
Adding to Blake's answer, besides #RunWith(classOf[JUnitRunner]) you might also need to set the surefire as follows:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Suite.class</include>
<include>**/*Test.class</include>
<include>**/*Tests.class</include>
<include>**/*Spec.class</include>
<include>**/*Specs.class</include>
</includes>
</configuration>
</plugin>
Here's one of my Maven projects which tests just fine by ScalaTest without any special plugin: https://github.com/nikita-volkov/sext/