Eclipse + Maven + Groovy: src/test/groovy directory gets removed after update project configuration
Asked Answered
T

5

5

I'm developing a Java web project in Eclipse (STS version 2.8.1.RELEASE) with Maven (version 2.2.1) and unit tests written in Groovy. The unit tests are located under src/test/groovy. Furthermore I'm using the m2eclipse plugin for Eclipse (version 1.0) and the Gmaven plugin in Maven (version 1.3).

Building in Maven works without problems: the groovy files are compiled and executed as tests. For the unit tests to work in Eclipse I added the Groovy nature to the project, added the folder src/test/groovy under Configure Build Path... and set the output folder to target/test-classes.

This works until I do an update of the project configuration under Maven -> Update Project Configuration.... After I do this every time the directory src/test/groovy gets removed from the source folders in Eclipse and I have to add it again and set the output directory.

Is there something I am missing or why is Eclipse deleting my source folder configuration every time I do an update of the project configuration?

My GMaven configuration looks as follows:

<plugin>
    <groupId>org.codehaus.gmaven</groupId>
    <artifactId>gmaven-plugin</artifactId>
    <version>1.3</version>
    <configuration>
        <providerSelection>1.7</providerSelection>
    </configuration>
    <executions>
        <execution>
            <goals>
                <goal>compile</goal>
                <goal>testCompile</goal>
            </goals>
        </execution>
    </executions>
</plugin>
Twitch answered 7/2, 2012 at 16:19 Comment(0)
T
2

Using the builder-helper-maven-plugin helped. Eclipse adds the source folder and sets the output folder correctly. I used the following configuration:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <id>add-test-source</id>
                    <phase>generate-test-sources</phase>
                    <goals>
                        <goal>add-test-source</goal>
                    </goals>
                    <configuration>
                        <sources>
                            <source>src/test/groovy</source>
                        </sources>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Twitch answered 8/2, 2012 at 11:13 Comment(3)
Did you get a "Plugin execution not covered by lifecycle configuration" message? If so, how do you resolve that issue? I'm unable to get the build-helper-maven-plugin to work in similar circumstances.Santossantosdumont
No, it just worked fine after adding the above configuration.Twitch
I have used this approach in the past and it worked... unfortunately, it has stopped working, probably due to some recent plugin upgrade. Using: Groovy m2e integration 2.9.2.xx-201607251752-e45, build-helper m2e integration (0.15.0.201207090124), m2e (1.7.0.20160603-1933) in Eclipse Mars.2 (4.5.2; 20160218-0600).Kesselring
S
1

I had a similar issue, mine was that eclipse was preventing me from writing groovy files into java folder. But you could try the same configuration out, or check out my whole pom at github

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-eclipse-plugin</artifactId>
            <version>2.8</version>
            <configuration>
                <additionalProjectnatures>
                    <projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature>
                </additionalProjectnatures>
                <!-- Source includes is necessary to allow groovy files in the java 
                    folder, else eclipse will throw a filtering exception -->
                <sourceIncludes>
                    <sourceInclude>**/*.groovy</sourceInclude>
                </sourceIncludes>
                <!-- Download sources will make maven download and attach source files 
                    where available -->
                <downloadSources>true</downloadSources>
                <downloadJavadocs>true</downloadJavadocs>
            </configuration>
        </plugin>

After I put in this configuration in the pom, the .classpath got generated properly.

Scad answered 7/2, 2012 at 18:42 Comment(0)
C
0

Check out this issue on SoF here. You need to add the build-helper-maven-plugin to get the resources added.

Camara answered 7/2, 2012 at 16:27 Comment(1)
You also might consider not using gmaven, but instead the groovy-eclipse-compiler. There are two separate camps on which to use. If you find one more definitive than the other, I'd love to hear about it.Camara
I
0

Try by adding your Groovy source directory.

Isolating answered 7/2, 2012 at 16:28 Comment(0)
N
0

You need to install the groovy-eclipse configurator for m2eclipse. It is available from this update site:

http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.7/

If you are using m2eclipse v1.0 or later, then choose to install from here:

m2e Configurator for Groovy-Eclipse (Optional)  

If you are using an older version of m2eclipse, then install from here:

Groovy-Eclipse m2eclipse integration pre v1.0 (deprecated)
Notarial answered 7/2, 2012 at 18:58 Comment(3)
When installing the plugin he says, that it is already installed: Your original request has been modified. "Groovy-Eclipse M2E integration" is already installed, so an update will be performed instead.Twitch
And did you do go through with the update? It may be that you have a configurator for an old version of M2eclipse that is not working with the current m2eclipse.Notarial
Ok, I did the update, but the problem stays. Only using the build-helper-maven-plugin solves the problem.Twitch

© 2022 - 2024 — McMap. All rights reserved.