3

I use the build-helper-maven-plugin for a legacy project with a non standard tree folder.

I use it this way :

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>add-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${basedir}/firstmodule/src</source>
                            <source>${basedir}/secondmodule/src</source>
                        </sources>
                    </configuration>
                </execution>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>${basedir}/firstmodule/tests</source>
                            <source>${basedir}/secondmodule/tests</source>
                                                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>

It works correctly if I launch mvn install on the root of the project, tests passed.

However, this project is a submodule in a bigger project. If I launch mvn install in the root folder of the parent project, maven don't execute the test.

it seems to work but surefire do not detect any test :

[INFO] Building MyLegacyProject
[INFO]    task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target
[INFO] [build-helper:add-source {execution: add-source}]
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\src added.
[INFO] Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\src added.
[INFO] [build-helper:add-test-source {execution: add-test-source}]
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\firstmodule\tests added.
[INFO] Test Source directory: C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\secondmodule\tests added.
[debug] execute contextualize
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 40 resources
[INFO] Copying 40 resources
[WARNING] While downloading com.sun.xml:saaj-impl:1.3
  This artifact has been relocated to com.sun.xml.messaging.saaj:saaj-impl:1.3.


[WARNING] While downloading javax.xml:jaxb-api:2.1
  This artifact has been relocated to javax.xml.bind:jaxb-api:2.1.


[INFO] [compiler:compile {execution: default-compile}]
[INFO] Compiling 752 source files to C:\DEV\perforce\1992\depot\MyProject\release\BUG_FIXING\MyLegacyProject\target\classes
[debug] execute contextualize
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 2 resources
[INFO] Copying 34 resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Compiling 15 source files to C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\test-classes
[INFO] [surefire:test {execution: default-test}]
[INFO] Surefire report directory: C:\DEV\perforce\1992\depot\MyLegacyProject\release\BUG_FIXING\MyLegacyProject\target\surefire-reports

-------------------------------------------------------
 T E S T S
-------------------------------------------------------
Running TestSuite
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.381 sec

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

any idea how to made this work ?

Hugo Lassiège
  • 986
  • 1
  • 11
  • 26

3 Answers3

0

Try to launch mvn with the debug mode (-X) to view if properties used by surefire are correct for your tree folder.

0

Are you using Maven 3 ? ${basedir} is recognized only by maven 3 (and silently ignored by maven 2 :( ) How do you understand the basedir usage ? It is the directory path of the POM where the build started. Thus it will be either the path to the parent project directory or one of its modules depending where you are launching the build from. In the second case the path will be wrong. I suppose you expected to have always the path to the root directory of your project ?

  • I'm using maven2. I've committed some code to try to reproduce with a simple project: https://bitbucket.org/hlassiege/maven-build-helper/src However it works with this sample. I tried to figure out the difference with my "real life" project And about basedir, I first tried without it but I've suspected a path problem. So I've tried basedir naively. @emmanuel-venisse – Hugo Lassiège Feb 14 '12 at 10:35
0

Ok I found it !!!

Somebody had the same problem : https://stackoverflow.com/a/6925096/242658

However it was really hard to figure it.

It was not related to build-helper-maven-plugin and I don't know why I had not this problem in single module mode.

I used powermock and powermock that pulled in TestNG. And with testng my tests are not detected by surefire. So I had to exclude testng:

<dependency>
  <groupId>org.powermock</groupId>
  <artifactId>powermock-mockito-release-full</artifactId>
  <version>1.4.9</version>
  <classifier>full</classifier>
  <exclusions>
    <exclusion>
      <artifactId>powermock-module-testng</artifactId>
      <groupId>org.powermock</groupId>
    </exclusion>
  </exclusions>
</dependency>
Community
  • 1
  • 1
Hugo Lassiège
  • 986
  • 1
  • 11
  • 26