Question

Eclipse makes working with multi module maven projects easy because you don't have to re-build and re-install a module before dependent modules will see changes to it. So you just change the code and eclipse updates the dependencies magically in the background.

I want to achieve this behaviour for acceptance testing as well.

I have

storage-service
  storage-service-war
  storage-service-acceptance-tests

If I use embedded jetty or tomcat to test inside the storage-service-war project then obviously code changes are immediately viewable in the tests, but I cannot see any way to achieve the same quick iteration of testing when testing from storage-service-acceptance-tests.

Every way I look at it it seems that I have to build storage-service-war and then use the artefact generated from that, but it seems like overkill when you only want to change one line.

Does anyone have a good method for doing this?

Cheers

Piers

Was it helpful?

Solution

So answering my own question :D The solution I came up with will not work on CI it will likely only work when doing a local build as it makes use of the relative paths of the projects. At the bottom I outline a more robust but more complex approach that should satisfy eclipse and CI.

I was looking at setting attachClasses to true for the war plugin configuration of the war project.

    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <attachClasses>true</attachClasses>
            </configuration>
        </plugin>
    </plugins>

You can then reference the jar in the dependent project as follows

    <dependency>
        <groupId>${project.groupId}</groupId>
        <artifactId>storage-service-war</artifactId>
        <version>${project.version}</version>
        <classifier>classes</classifier>
    </dependency>

Then I was thinking I could run my tests from within the acceptance test module using embedded jetty or tomcat and pointing them to the web.xml defined in the war project using a relative path.

This works fine with maven via the commandline but fails in eclipse :(

The problem with this is that the jar produced by attach classes is not picked up by the eclipse m2e integration see -https://bugs.eclipse.org/bugs/show_bug.cgi?id=365419 unfortunately it wont be fixed.

So My solution for the moment is to manually add the storage-service-war project to my acceptance test project build path in eclipse. Its not great but it works

The above solution is a bit hacky but the alternative outlined is a bit more involved.

By splitting the project into the following I think it would be possible to have correct eclipse integration and projects that work on CI

storage-service
  storage-service-core
  storage-service-war
  storage-service-acceptance-tests
  storage-service-config

The core project contains the logic and source of the webapp and is of type jar, the config contains the web.xml and any other config files and is also of type jar. Then the acceptance-tests and war project are both of type war and serve merely to package the core project into a war and extract the config to the webapp/WEB-INF dir so that they may share a common setup.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top