views:

389

answers:

3

Hi there, when i instrument my classes using Maven 2 using the command

mvn cobertura:instrument

The output (the instrumented classes) are put in \target\generated-classes. Is there a way to change the output location to \target\classes?

I checked the instrumentation tasks of the cobertura-maven plugin but this does not give me a solution sofar.

+1  A: 

As far as I understand, the instrumented classes are only needed by cobertura for report generation. If you create them in target/classes, they will overwrite the original class files.

If you need the instrumented files in a jar as a result, you can configure the maven-jar-plugin to pick up the files from the target/generated-classes directory instead of or in addition to the files from the standard ${build.project.outputDirectory}.

Edit

Have a look at the maven-jar-plugin description. To only use target/generated-classes, the following addition to your POM should work - try it and modify it to your needs:

<project>
  ...
  <build>
    <plugins>
      ...
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3</version> <!-- replace with correct version nbr! -->
        <configuration>
          <includes>
            <include>${project.build.directory}/generated-classes/**/*.class</include>
          </includes>
          <excludes>
            <exclude>${project.build.directory}/classes/**/*.class</include>
          </excludes>

        </configuration>
      </plugin>
      ...
    </plugins>
  </build>
  ...
</project>

${project.build.directory} points to your target folder, ${project.build.ouputDirectory} to target/classes. I do not know if you can simply set ${project.build.ouputDirectory} to a new value - have a look at the this chapter of the maven book, maybe you find some hints

Edit 2

Alternativly or additionally you can use maven to copy the files from target/generated-classes to target/classes after coberture:instrument has finished. This question has one answer with an example POM (fragment), you just have to identify the correct phase (process-resources is definitely too early for your case)

Andreas_D
That would be optimal to overwrite the target/classes, in that way the packaging of my wars, jars and ears will be untouched. Is it enough to overwrite/set the ${project.build.outputDirectory} for generation or packaging?
Marco
I need those instrumented classes inside my jars/wars and ears. So i am looking for a way on how to accomplish this the easy way.
Marco
A: 

I just implemented the solution proposed by Andreas_D, modified my pom and uses the maven-resources-plugin. So on some stage of my build the Cobertura generated files are copied to the /target/classes directory.

Marco
A: 

You can configure it using <classesDirectory>[Your DIR]</classesDirectory>

RN