A package in an unexpected state of nonexistence

Oops, I broke the build.  The unit tests all passed in Eclipse, but when I committed, one of my production classes didn’t even compile.

In the face of a mystery like this, I tend to wax philosophical, pondering: “How can this be?”

Well, let’s dig in and see if we can figure it out.

Digging In

I can reproduce the issue by doing a local Maven Install.  (Guess it would be a good idea to do one of those before committing my changes, huh? :)  The output looks something like this:

...
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Compilation failure

C:\path\to\eclipse-workspaces\production\framework-test-harness\src\main\java\com\example\fw\testutil\ConfigurationSwappingAbstractTestCase.java:[7,24] package org.junit.runner does not exist

C:\path\to\eclipse-workspaces\production\framework-test-harness\src\main\java\com\example\fw\testutil\ConfigurationSwappingAbstractTestCase.java:[8,25] package org.junit.runners does not exist

C:\path\to\eclipse-workspaces\production\framework-test-harness\src\main\java\com\example\fw\testutil\ConfigurationSwappingAbstractTestCase.java:[9,39] package org.junit.runners.Parameterized does not exist
...

Now how’s come the org.junit.runner package doesn’t even exist?

This smelled like a pom file issue…and indeed it was.

Normally Test Scope is Right…

We have a parent pom file that brings in certain libraries for every project, and JUnit 4 is one of those.  It is declared at test scope, because we normally wouldn’t want to ship the JUnit library, or any tests that depend on it.

…But This is a Little Different…

That’s where our framework test harness is a little different: this project’s purpose is to provide services for use by other projects’ integration tests, and as part of that it provides a base class that uses JUnit annotations.  So our framework test harness actually has a compile-scope dependency on JUnit rather than the normal test scope dependency.

Solution

All I needed to do was update the test harness project’s pom file and adjust the junit artifact’s scope to compile, like this:

        <!-- Need compile scope for integration test base class -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <scope>compile</scope>
        </dependency>

…and now Maven Install finds the JUnit classes just fine.

So, I admit it: I earned my -10 points on the leader board fair and square.  : )

Advertisements

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s