Dave LeBlanc
Dave LeBlanc

Reputation: 346

How to get JBehave to include test dependency jars when running in Maven?

I've got a simple-enough project that I'm trying to test with JBehave core, and doing things in a maven-kosher fashion (that is production under src/main, test under src/test, integration testing stuff under an added path of src/it/{java,resources}, and test dependencies scoped with test). Getting this all running together seems rather harder than it should be.

My case is a little different because my code is in src/it/java, and resources in src/it/resources. Having configured those in maven, Eclipse runs the stories just fine - the problem is with Maven.

Currently my problem is that it doesn't see mockito (or other test dependencies) when running (mvn -X). Even editing a working example and adding a test dependency doesn't include it.

I've been able to bodge it into working by sticking my test dependencies within the plugin xml blob, but obviously I don't want to repeat myself like that.

The relevant parts of the build file (without the manually specified dependency hack) are:

<testResources>
    <testResource>
        <directory>src/test/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*</include>
        </includes>
    </testResource>
    <testResource>
        <directory>src/it/resources</directory>
        <filtering>false</filtering>
        <includes>
            <include>**/*</include>
        </includes>
    </testResource>
</testResources>

...

  <plugin>
    <groupId>org.jbehave</groupId>
    <artifactId>jbehave-maven-plugin</artifactId>
    <executions>
      <execution>
        <id>embeddable-stories</id>
        <phase>integration-test</phase>
        <configuration>
          <includes>
            <include>**/*Story.java</include>
          </includes>
          <ignoreFailureInStories>false</ignoreFailureInStories>
          <ignoreFailureInView>false</ignoreFailureInView>
          <scope>test</scope>
          <testSourceDirectory>src/it/java</testSourceDirectory>
        </configuration>
        <goals>
          <goal>run-stories-as-embeddables</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

Ideas?

Upvotes: 7

Views: 3115

Answers (2)

kan
kan

Reputation: 28951

The plugin has property scope which defaults to compile, I suppose you should to change it to test. Consult with the documentation.

Also, here is good point why compile is by default.

Upvotes: 4

Raghuram
Raghuram

Reputation: 52635

According to jbehave maven plugin documentation,

When using the JBehave Maven Plugin, and depending on the rest of your POM configuration, you may need to add Apache log4j as Plugin Dependency (as opposed to the Project Dependency) if you find that it's not able to load its classes

Could you be facing the same issue?

Upvotes: 2

Related Questions