I have a project, there are some Scala tests for Scala code, as well as junit tests for Java. How to run Scala and Junit tests with Maven.
Project is multi-modular, with scala and java modules.
You may have to manually specify the Java tests a work-around would be something like this
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<includes>
<include>**/*Suite.class</include>
<include>**/*Tests.class</include>
<include>**/*Spec.class</include>
<include>**/*Specs.class</include>
</includes>
</configuration>
</plugin>
Related
I wanted to know if with Spring Boot and Eclipse it is possible to configure something so that in the% of the project coverage it does not take into account the coverage of certain classes.
you are using jacoco plugin u can use like below
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco.mavenplugin.version}</version>
<configuration>
<excludes>
<exclude>some/package/**/*</exclude>
</excludes>
</configuration>
<executions>
...
</executions>
</plugin>
please refer below
Maven Jacoco Configuration - Exclude classes/packages from report not working
After successfully following this HowTo to integrate Lombok and AspectJ in a Maven build, my code doesn't compile anymore in eclipse.
There are a lot of errors everywhere due to absence of getter/setter/constructors normally generated by Lombok.
My goal is to be able to use eclipse to develop using Lombok, and after that using a mvn clean install on command line in order to build.
I tried to skip AspectJ weaving in eclipse, but without success.
Here is the profile I used to skip AspectJ:
<profile>
<id>noAspectJ</id>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>aspectj-maven-plugin</artifactId>
<executions>
<execution>
<id>process-classes</id>
<phase>none</phase>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerVersion>1.7</compilerVersion>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</profile>
The best solution I found was to remove the AspectJ plugin from my Eclipse, since it don't need it there.
This way I could also avoid using a profile.
But this could probably lead to some problem if I used the JUnit tests in eclipse.
Story: So I am running a WebDriver2 test suite with TestNG and all that's bundled up in a Maven architecture. I built everything in Eclipse project first, then converted this over to a Maven project. I am not a programmer but I can hack my way through Java, I am new to Maven but pretty good with TestNG and Selenium and from everything I have researched I am approaching this correctly, I have to be missing something stupid.
Problem: I am running this all in Eclipse with Maven plugin, when I run POM as TEST I get an error:
org.testng.TestNGException: Parameter 'dataMode' is required by #Configuration of method prepareDriver but has not been marked #Optional or defined
So POM setup thusly for SureFire to grab my file, testNG dependency also set and appears to work since my error is coming from TestNG itself:
<plugins>
[...]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>src\test\resources\testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
[...]
</plugins>
I have also passed in the parameters to this plugin as well:
<systemPropertyVariables>
<dataMode>Custom</dataMode>
</systemPropertyVariables>
<systemPropertyVariables>
<log_level>DEBUG</log_level>
</systemPropertyVariables>
Everything in my TestNG file is correct, if I run as a TestNG test just from the testng.xml everything runs like it is supposed to, if you want that code I will update but that part works, parameters are in there correctly.
Also, when I execute the POM as TEST I get a report that 2 out of 11 tests failed... I don't have 11 tests, if you go by my testNG.xml I have only 2 #Test's that it would find, I think it's counting every TestNG annotation in this portion of my test-suite...
My theory is that it's trying to run without the TestNG file and just running every TestNG annotation in any file it finds but I don't have it setup to do that, or do I?
Try something like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
<systemProperties>
<property>
</property>
</systemProperties>
</configuration>
</plugin>
000 unit test in one application. I know in one particular folder, all the tests takes long time, I donot want to test these cases everytime I run unit test. So may I have some property file to indiciate a pattern/folder which test cases shall skip?
I am using mvn. Java 1.6.
Take a look at Maven Surefire Plugin: Inclusions and Exclusions of Tests.
To exclude certain tests you can use:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.9</version>
<configuration>
<excludes>
<exclude>**/TestCircle.java</exclude>
<exclude>**/TestSquare.java</exclude>
</excludes>
</configuration>
</plugin>
Alternatively, on the command line, you can explicitly specify which tests you want to run. For example:
mvn -Dtest=TestSquare,TestCi*le test
Im starting to learn scala and mongo , my IDE is intellij IDEA. I created a scala project using
mvn:archetype-generate
and typed a simple hello world program in the IDEA with some arithmetic options such as
println(5)
val i = 1+2
println(i)
Then i compiled it using
mvn compile
It said
build success
But now how should i execute my application and verify the output. There isn't a single article which explains how to start off with scala,maven,idea and i am entirely new to all of this. any help would be useful for me.
maven-exec-plugin
Try with this code:
package com.example
object Main {
def main(args: Array[String]) {
println(5)
val i = 1 + 2
println(i)
}
}
Place it under /src/main/scala/com/example/Main.scala and run it using:
$ mvn package exec:java -Dexec.mainClass=com.example.Main
If you don't want to pass mainClass manually, you can do this in plugin configuration:
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.1</version>
<configuration>
<mainClass>com.example.Main</mainClass>
</configuration>
</plugin>
</plugins>
There are other possibilities, this is the easiest one. Of course in IntelliJ you should be able to run the program directly.
maven-jar-plugin
If you want to ship the application, use maven-jar-plugin to add Main-Class and Class-Path entries to the manifest:
Main-Class: com.example.Main
Class-Path: lib/scala-library-2.9.0-1.jar lib/slf4j-api-1.6.1.jar ...
The following configuration does that and also copies all the dependencies (including Scala runtime library) to target/lib.
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<archive>
<manifest>
<mainClass>com.example.Main</mainClass>
<addClasspath>true</addClasspath>
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>lib/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}
</customClasspathLayout>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
Now you can simply run your application by (note the target/lib directory is required):
$ java -jar target/your_app-VERSION.jar
You can ship your application simply by copying your JAR file along with /lib subdirectory.
Also see Exec Maven Plugin and Playing with Scala and Maven.