I've a maven project which use surefire plugin for both unit tests and integration tests.
Is there a maven command that I can use just to skip the unit tests but to run integration tests.
I've tried mvn clean install -DskipUnitTests but that is not working
I would say: no.
But I recommend you the failsafe plugin solution. Some refactoring/renaming, and you can test.
See here my answer, it could help you: How can I fire integration tests separately using failsafe-plugin?
run this command:mvn verify -Dtest=!*Test -DfailIfNoTests=false
Below 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>com.aaa</groupId>
<artifactId>IntegrationTestMaven</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>IntegrationTestMaven</name>
<!-- <properties>
Only unit tests are run by default.
<skip.integration.tests>true</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
-->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>add-test-source</id>
<phase>process-resources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>src/integrationtest/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.15</version>
<configuration>
<!-- Skips unit tests if the value of skip.unit.tests property is true -->
<!-- Excludes integration tests when unit tests are run. -->
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
<configuration>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<!-- <skipTests>${skip.integration.tests}</skipTests> -->
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!-- <profiles>
<profile>
<id>all-tests</id>
<properties>
<build.profile.id>all-tests</build.profile.id>
All tests are run.
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>false</skip.unit.tests>
</properties>
</profile>
<profile>
<id>dev</id>
</profile>
<profile>
<id>integration-tests</id>
<properties>
Used to locate the profile specific configuration file.
<build.profile.id>integration-test</build.profile.id>
Only integration tests are run.
<skip.integration.tests>false</skip.integration.tests>
<skip.unit.tests>true</skip.unit.tests>
</properties>
</profile>
</profiles>
-->
</project>
Related
Jacoco reports for this project contain line coverage for test classes, despite attempting to exclude tests as below
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<configuration>
<excludes>
<exclude>**/*Test.*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<configuration>
<excludes>
<exclude>**/*Test.*</exclude>
</excludes>
</configuration>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<configuration>
<excludes>
<exclude>**/*Test.*</exclude>
</excludes>
</configuration>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
<execution>
<id>jacoco-check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule implementation="org.jacoco.maven.RuleConfiguration">
<excludes>
<exclude>**/*Test.*</exclude>
</excludes>
<element>CLASS</element>
<limits>
<limit implementation="org.jacoco.report.check.Limit">
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.94</minimum>
</limit>
<limit implementation="org.jacoco.report.check.Limit">
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.85</minimum>
</limit>
</limits>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
The above pom is basically us shotgunning the config with solutions from existing StackOverflow questions, but none of them are working.
Any feedback would be much appreciated!
In absence of Minimal Complete Reproducible Example one can only guess how your test files are placed in your project and why they are shown in report, because jacoco-maven-plugin doesn't show test classes in report by default - here is proof:
for the following pom.xml
<?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>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
src/main/java/Example.java
class Example {
void sayHello() {
System.out.println("Hello, World!");
}
}
and src/test/java/ExampleTest.java
import org.junit.Test;
public class ExampleTest {
#Test
public void test() {
new Example().sayHello();
}
}
execution of
mvn clean verify
generates following report that as you can see doesn't contain src/test/java/ExampleTest.java:
Trying to blindly guess, one can assume that your project has non-standard structure where the above Example.java and ExampleTest.java reside in the same src directory and you have following pom.xml
<?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>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<testSourceDirectory>${project.basedir}/src</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
then execution of mvn clean verify indeed will produce following report that contains ExampleTest.java
however in this case following exclusion of **/*Test.*
<?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>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>${project.basedir}/src</sourceDirectory>
<testSourceDirectory>${project.basedir}/src</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.3</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
<goal>report</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*Test.*</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
works just fine
I want to exclude some class files since those files do not want to get considered when calculating code coverage.
My scenario is I'm getting .exec file and class files from Jenkins for multiple projects and trying to create one aggregated report. So I'm using jacoco:merge to create the merged exec file and I'm generating the report using jacoco:report. I want to exclude some classes here. But I can't use <excludes> inside jacoco:structure.
My code attached here.
<?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>wso2</groupId>
<artifactId>code-coverage-report</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<directory>${project.basedir}/target</directory>
</build>
<profiles>
<profile>
<id>with-tests</id>
<activation>
<property>
<name>!maven.test.skip</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-jacoco-dependencies</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<includeTypes>jar</includeTypes>
<includeArtifactIds>org.jacoco.ant</includeArtifactIds>
<stripVersion>true</stripVersion>
</configuration>
</execution>
</executions>
</plugin>
<!-- Ant plugin - Merge Jacoco Reports -->
<!-- Logging and distribution modules are not checked since not relevant -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:jacoco="antlib:org.jacoco.ant">
<taskdef uri="antlib:org.jacoco.ant" resource="org/jacoco/ant/antlib.xml">
<classpath path="${project.build.directory}"/>
</taskdef>
<jacoco:merge destfile="merged.exec">
<fileset dir="jacoco/exec/" includes="*.exec"/>
</jacoco:merge>
<jacoco:report>
<executiondata>
<file file="merged.exec"/>
</executiondata>
<structure name="Final Coverage Report">
<classfiles>
<fileset dir="jacoco/class/classes/"/>
</classfiles>
<excludes>
**/org/xxx/carbon/dataservices/ui/stub/admin/*,
**/org/xxx/carbon/rest/api/stub/types/aaa/*,
**/org/xxx/carbon/endpoint/stub/types/aaa/*,
</excludes>
</structure>
<html destdir="jacoco/tmp_report"/>
<xml destfile="jacoco/tmp_report/coverage-report.xml"/>
<csv destfile="jacoco/tmp_report/coverage-report.csv"/>
</jacoco:report>
</target>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.jacoco</groupId>
<artifactId>org.jacoco.ant</artifactId>
<version>${jacoco.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<jacoco.version>0.7.9</jacoco.version>
</properties>
</project>
But it gives the following exception. when I try to run it.
An Ant BuildException has occured: structure doesn't support the nested "excludes" element.
See documentation:
Task report
Element structure
Note that the classfiles and sourcefiles elements accept any Ant resource collection. Therefore also filtering the class file set is possible and allows to narrow the scope of the report, for example:
<classfiles>
<fileset dir="classes">
<include name="org/jacoco/examples/important/**/*.class"/>
</fileset>
</classfiles>
Hence
<classfiles>
<fileset dir="jacoco/class/classes/">
<exclude name="org/xxx/carbon/dataservices/ui/stub/admin/**/*.class"/>
<exclude name="org/xxx/carbon/rest/api/stub/types/aaa/**/*.class"/>
<exclude name="org/xxx/carbon/endpoint/stub/types/aaa/**/*.class"/>
</fileset>
</classfiles>
I have parent pom which includes all dependencies which will be used by multiple child project. I also configured plugins in parent pom to be extended to child project.
I also wanted the Jacoco code coverage report to be generated and enforce build failure when the coverage is lesser than the minimum threshold.
The Jacoco plugin which fails the build(child project) when configured in child pom but does not fail the build of child project when configured in parent pom.
Parent 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>microservice</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>ms-parent</name>
<description>Parent pom will include all the dependencies commonly used
across the microservices </description>
<properties>
<spring.version>4.3.4.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
<build>
<finalName>ParentPOM</finalName>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<useProjectReferences>false</useProjectReferences>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>
${project.build.directory}/coverage.exec
</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals><goal>prepare-agent</goal></goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals><goal>report</goal></goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration><rules><rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.99</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.99</minimum>
</limit>
</limits>
<excludes>
</excludes>
</rule></rules></configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Child 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>microservice</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>childmodule</groupId>
<artifactId>module</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>cipher Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<!-- inherits config from parent: can override if required -->
</plugin>
</plugins>
</build>
</project>
The above pom setup does not fail the build of the child project.
If I include the jacoco plugin in child pom then the build fails if the coverage is less than the threshold.
Child Pom with jacoco plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.17</version>
<configuration>
<systemPropertyVariables>
<jacoco-agent.destfile>${project.build.directory}/coverage.exec</jacoco-agent.destfile>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.7.201606060606</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals><goal>prepare-agent</goal></goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals><goal>report</goal></goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration><rules><rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.99</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.99</minimum>
</limit>
</limits>
<excludes>
</excludes>
</rule></rules></configuration>
</execution>
</executions>
</plugin>
How to ensure the Jacoco configuration set in parent pom fails the build(child project) when the coverage is less than the threshold.
Thanks in advance.
It is very unfortunate that JaCoCo does not provide a way to make an aggregate check for the entire multi-module project. It works for the individual modules only.
If reporting is enough, though, "report-aggregate" goal can be used.
Good example here: jacoco simple integration test solution
Other source:
https://github.com/jacoco/jacoco/wiki/MavenMultiModule
I have created a web project using maven 2(it will be deployed on tomcat 7.0.35), which should serve as a client for JAX-WS web service. I am trying to generate client classes from wsdl file(I have 1 wsdl and 1 xsd).
After I run "mvn clean install" command, no classes are generated and I don't see any errors in console
This 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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.ws</groupId>
<artifactId>my_ws</artifactId>
<packaging>war</packaging>
<version>1.0</version>
<name>cs Maven Webapp</name>
<url>http://maven.apache.org</url>
<build>
<finalName>my_ws</finalName>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.8</version>
<configuration>
<projectNameTemplate>
[artifactId]-[version]
</projectNameTemplate>
<wtpmanifest>true</wtpmanifest>
<wtpapplicationxml>true</wtpapplicationxml>
<wtpversion>2.0</wtpversion>
<manifest>
${basedir}/src/main/resources/META-INF/MANIFEST.MF
</manifest>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>${basedir}/src/main/resources/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>my_ws.wsdl</wsdlFile>
</wsdlFiles>
<packageName>com.test.ws.client</packageName>
<sourceDestDir>${basedir}/target/generated-sources/</sourceDestDir>
<keep>true</keep>
<bindingFiles>
<bindingFile>${basedir}/src/main/resources/wsdl/binding.xml</bindingFile>
<bindingFile>${basedir}/src/main/resources/wsdl/jaxb-binding.xml</bindingFile>
</bindingFiles>
</configuration>
<phase>generate-sources</phase>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.9</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0.2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.2.8</version>
</dependency>
</dependencies>
</project>
Here is binding.xml
<bindings
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
wsdlLocation="./my_ws.wsdl"
xmlns="http://java.sun.com/xml/ns/jaxws">
<!-- Disable default wrapper style -->
<enableWrapperStyle>false</enableWrapperStyle>
</bindings>
and jaxb-binding.xml
<jaxb:bindings version="2.1" xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<jaxb:globalBindings generateElementProperty="false" />
</jaxb:bindings>
When using <pluginManagement> element in a pom file, you don't declare plugins usage, but plugins availability. <pluginManagement> is used in a parent pom to announce available plugins for child pom usage.
Just remove this element, and the plugins should be called.
Hi i m running into some error
I have a really small project in groovy.
I want to use maven.
I was able to compile my files, source and test(i have my .class in the target folder). But no test are executed.
here is my pom file.
<?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>gmedia</groupId>
<artifactId>gmedia.api</artifactId>
<name>Gmedia API project</name>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>1.7.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sf.json-lib</groupId>
<artifactId>json-lib</artifactId>
<version>2.2.3</version>
<classifier>jdk15</classifier>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.0.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.0-rc-5</version>
<executions>
<execution>
<goals>
<!--<goal>generateStubs</goal>-->
<goal>compile</goal>
<!--<goal>generateTestStubs</goal>-->
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<url>http://ftp.ing.umu.se/mirror/eclipse/rt/eclipselink/maven.repo</url>
<id>eclipselink</id>
<layout>default</layout>
<name>Repository for library Library[eclipselink]</name>
</repository>
</repositories>
My groovy files are in src/groovy and test/groovy
What i'm dooing wrong?
BTW, I get compilation errors when I add this configuration:
<configuration>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>
compile my file with erro when adding this to the groovy-maven-plugin
<configuration>
<sources>
<fileset>
<directory>${pom.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</fileset>
</sources>
</configuration>
Well for one thing you are using an outdated version of GMaven.
The plugin has moved to the Group Id org.codehaus.gmaven and the current version is 1.3:
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<goals>
<goal>generateStubs</goal>
<goal>compile</goal>
<goal>generateTestStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
</plugin>
Also, you probably need to keep the stub goals active for JUnit to find you test classes.
See this page for reference: Buildung Groovy Projects with GMaven
Update:
If i define a test to run, it run. but
with just mvn clean test, the test are
compiled, but not executed
This sounds like you're not following the naming conventions for test classes.
See the first section of this page: Inclusions and Exclusions of Tests