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>
Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
Felix Reckers
  • 1,282
  • 1
  • 14
  • 15

5 Answers5

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>
Felix Reckers
  • 1,282
  • 1
  • 14
  • 15
  • 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. – Conan Jun 08 '12 at 10:39
  • No, it just worked fine after adding the above configuration. – Felix Reckers Jun 11 '12 at 07:32
  • 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). – rec Aug 02 '16 at 10:22
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.

Abe
  • 8,623
  • 10
  • 50
  • 74
0

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

Community
  • 1
  • 1
Spencer Kormos
  • 8,381
  • 3
  • 28
  • 45
  • 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. – Spencer Kormos Feb 07 '12 at 16:28
0

Try by adding your Groovy source directory.

Efthymis
  • 1,326
  • 11
  • 13
ndeverge
  • 21,378
  • 4
  • 56
  • 85
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)
Andrew Eisenberg
  • 28,387
  • 9
  • 92
  • 148
  • 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. – Felix Reckers Feb 08 '12 at 11:07
  • 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. – Andrew Eisenberg Feb 08 '12 at 16:54
  • Ok, I did the update, but the problem stays. Only using the build-helper-maven-plugin solves the problem. – Felix Reckers Feb 10 '12 at 13:44