Hi Laurie,
Hi faced problems with the Cobertura plugin for M2 as well. I tried
some tricks but I finally gave up. And reading some Cobertura news on
the Net, it seems the Cobertura developpers are working on this plugin
for Maven 2.
So I decided to find another solution : integrate a Cobertura ant task
in my pom.xml. I know it is a little bit against the Maven philosophy
but while the Cobertura plugin is not working, I think this is the only
solution to your problem.
Here is a part of my pom.xml :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>test</phase>
<configuration>
<tasks>
<ant antfile="${basedir}/build.xml" inheritRefs="true">
<target name="cobertura"/>
</ant>
</tasks>
</configuration>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>
As you can see, you must skip the test executed by Maven, otherwise,
the tests will be executed twice. Hi called my Cobertura ant task
'cobertura' in my build.xml so it can be referenced by my target in my
pom.xml.
If not alredy done, I advise you to subscribe to the Cobertura mailing
list : [EMAIL PROTECTED]
Enjoy,
Le Jan 6, 2006, à 11:19 PM, Laurie Tynor a écrit :
I'm pretty new to maven, so this may be an obvious question to those
with more experience. I have looked through all the docs however, and
am unable to resolve it, and would appreciate any help/information.
I am using maven2 (2.0.1) and am trying to get the cobertura plugin to
work. I am able to run cobertura under ant, but not with maven2.
Our build directory uses maven modules. It's structure is like this:
main/
main/pom.xml (which has module declarations for core, etc)
main/core/
main/core/pom.xml (which has some additional dependencies for core
classes)
<etc>
The pom.xml in the main level produces no artifacts. The main
directory has no classes just has a few subdirectories. The
subdirectories have the classes, resources, and unit tests. The
main-level pom.xml has the surefire plugin, which is working fine
traversing the subdirectories.
Here are the details for my cobertura attempts. Any help is
appreciated:
1. Version from the svn sandbox (which uses cobertura 1.7), and
specifies the instrument goal in the lifecycle.xml file as part of the
process-classes phases:
a) When I call "mvn install", which should trigger the
instrumentation goal, nothing happens. It looks like
instrumentation is not attempted
b) When I call "mvn site", I get this null-pointer exception
(which I think is because the target/generated-classes directory was
never produced from the mvn install):
[INFO] task-segment: [site]
[INFO]
-----------------------------------------------------------------------
--
---
[INFO] Preparing surefire-report:report
[INFO] No goals needed for project - skipping
[INFO] Preparing cobertura:cobertura
[INFO]
-----------------------------------------------------------------------
--
---
[ERROR] FATAL ERROR
[INFO]
-----------------------------------------------------------------------
--
---
[INFO] null
[INFO]
-----------------------------------------------------------------------
--
---
[INFO] Trace
java.lang.NullPointerException
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.getMojoDescriptor
(DefaultLifecycleExecutor.java:884)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkProjectLifecy
cle(DefaultLifecycleExecutor.java:842)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.forkLifecycle(Def
aultLifecycleExecutor.java:729)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:521)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi
<etc>
c) When I try to call the instrument target directly, I get a
"BUILD ERROR" that says "Unable to prepare instrumentation
directory. Source directory doesn't exist". The
target/generated-classes/cobertura directory is created so I can
tell that it did try to instrument
2. Version from the maven auto-download. This one uses cobertura 1.6,
and specifies instrumentation as part of the generate-sources phase
(which I don't think is correct):
a) When I call "mvn install", which should trigger the
instrumentation goal, nothing happens as with the sandbox version.
b) When I call "mvn site", I get an error that the cobertura.ser
file doesn't exist (which it doesn't because the install did
nothing)
c) When I try to call the instrument target directly, I get this
error:
[INFO] Trace
java.lang.IllegalStateException: basedir C:<etc>\target\classes does
not exist
at
org.codehaus.plexus.util.DirectoryScanner.scan(DirectoryScanner.java:
542)
at
org.codehaus.plexus.util.FileUtils.getFileNames(FileUtils.java:1402)
at
org.codehaus.plexus.util.FileUtils.getFileNames(FileUtils.java:1368)
at
org.codehaus.mojo.cobertura.tasks.InstrumentTask.execute(InstrumentTa
sk.java:97)
at
org.codehaus.mojo.cobertura.CoberturaInstrumentMojo.execute(Cobertura
InstrumentMojo.java:91)
at
org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:432)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:530)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeStandalone
Goal(DefaultLifecycleExecutor.java:485)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:455)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:303)
at
org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
<etc>
3. Here is the top-level pom.xml file contents (with a little bit
blanked out). (I've also tried the plugin tag under build to have
the
<executions><execution><goals><goal>clean</goal></goals></execution></
executions>
but that didn't seem to affect anything)
<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>MyId</groupId>
<artifactId>MyArtifact</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<name>Field Equipment Simulator</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.12</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>1.2.5</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>1.8.0.1</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<!-- plugins -->
</dependencies>
<modules>
<module>MyModule1</module>
<module>MyModule2</module>
<module>MyModule3</module>
<module>MyModule4</module>
<module>MyModule5</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.0-beta-4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>surefire-report-maven-plugin</artifactId>
<version>2.0-beta-1</version>
<!--
<configuration>
<outputDirectory>${project.build.directory}/site</outputDirectory>
<reportsDirecotry>${project.build.directory}/surefire-reports</
reportsDirecotry>
</configuration>
-->
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
</plugin>
</plugins>
</reporting>
<repositories>
<repository>
<id>central</id>
<name>Maven Repository Switchboard</name>
<layout>default</layout>
<url>http://repo1.maven.org/maven2</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>MyLocalRepository</id>
<name>MyLocaalRepositoryName</name>
<url>http://MyLocalRepositoryUrl</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>snapshot</id>
<name>Maven Snapshot Repository</name>
<layout>default</layout>
<url>http://snapshots.maven.codehaus.org/maven2/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<developers>
<developer>
<name>MyDeveloper</name>
</developer>
</developers>
</project>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Mathieu Vanderwhale
___________________________________________
DENALI sa - http://www.denali.be
Château de Clerlande - 1340 Ottignies - Belgium
Tel +32 (0) 10 43 99 51 - Fax +32 (0) 10 43 99 52
___________________________________________
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]