GRECLIPSE
  1. GRECLIPSE
  2. GRECLIPSE-1221

Groovy tests in src/test/groovy ignored if no tests in src/test/java

    Details

    • Testcase included:
      yes
    • Number of attachments :
      1

      Description

      Steps to Reproduce

      1. Extract the attachment.
      2. Run mvn test

      -------------------------------------------------------
       T E S T S
      -------------------------------------------------------
      There are no tests to run.
      
      Results :
      
      Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
      

      3. See that src/test/groovy/com/kp/BuildInfoTest.groovy exists, and be confused

      Workaround

      Simply move src/test/groovy/com/kp/BuildInfoTest.groovy to src/test/java/com/kp/BuildInfoTest.groovy

      (The test will fail, but that's irrelevant for this. It just points out the fact that the test actually ran.)

        Activity

        Andrew Eisenberg made changes -
        Field Original Value New Value
        Assignee Andrew Eisenberg [ werdna ]
        Fix Version/s 2.6.0.Release [ 17849 ]
        Affects Version/s 2.5.2.Release [ 17434 ]
        Hide
        Andrew Eisenberg added a comment -

        I can confirm the bug. However, there does not need to be a test in src/test/java. Any file will do: a Java file, a text file, etc.

        Show
        Andrew Eisenberg added a comment - I can confirm the bug. However, there does not need to be a test in src/test/java. Any file will do: a Java file, a text file, etc.
        Hide
        The Alchemist added a comment -

        @Andrew: Thank you!

        If you point me in the right direction, I'll send over a patch!

        Show
        The Alchemist added a comment - @Andrew: Thank you! If you point me in the right direction, I'll send over a patch!
        Hide
        Andrew Eisenberg added a comment -

        A patch would be great since I won't be able to get to this for at least a couple of weeks. Here is the svn url:
        https://svn.codehaus.org/groovy/eclipse/trunk/extras/groovy-eclipse-compiler

        It is a very straight forward maven compiler plugin. Let me know if you have any questions.

        Show
        Andrew Eisenberg added a comment - A patch would be great since I won't be able to get to this for at least a couple of weeks. Here is the svn url: https://svn.codehaus.org/groovy/eclipse/trunk/extras/groovy-eclipse-compiler It is a very straight forward maven compiler plugin. Let me know if you have any questions.
        Hide
        The Alchemist added a comment -

        Unfortunately, I'm not familiar with maven compiler plugins. It would help me get a patch out much faster if you could at least send me a class name. If not, that's ok too.

        Thanks, Andrew!

        Show
        The Alchemist added a comment - Unfortunately, I'm not familiar with maven compiler plugins. It would help me get a patch out much faster if you could at least send me a class name. If not, that's ok too. Thanks, Andrew!
        Hide
        Andrew Eisenberg added a comment -

        There is one class in the compiler plugin. All it does is gather up the right configuration to send to the batch compiler. Here is the svn link to the file:

        https://svn.codehaus.org/groovy/eclipse/trunk/extras/groovy-eclipse-compiler/src/main/java/org/codehaus/groovy/eclipse/compiler/GroovyEclipseCompiler.java

        Show
        Andrew Eisenberg added a comment - There is one class in the compiler plugin. All it does is gather up the right configuration to send to the batch compiler. Here is the svn link to the file: https://svn.codehaus.org/groovy/eclipse/trunk/extras/groovy-eclipse-compiler/src/main/java/org/codehaus/groovy/eclipse/compiler/GroovyEclipseCompiler.java
        Hide
        The Alchemist added a comment -

        @Andrew: Thanks... turns out the issue is deeper in the internals of Maven. GroovyEclipseCompiler passes "" as the inputFileEnding it wants to AbstractCompiler but that setting is never used, by anything.

        If you don't put a blank resource, etc. into src/test/java, the TestCompilerMojo never gets invoked so GroovyEclipseCompiler never gets called for target/test-classes.

        Unfortunately, I don't know enough Maven to try to debug this one.

        WORKAROUND

        touch src/test/java/i.am.blank

        Show
        The Alchemist added a comment - @Andrew: Thanks... turns out the issue is deeper in the internals of Maven. GroovyEclipseCompiler passes "" as the inputFileEnding it wants to AbstractCompiler but that setting is never used, by anything. If you don't put a blank resource, etc. into src/test/java , the TestCompilerMojo never gets invoked so GroovyEclipseCompiler never gets called for target/test-classes . Unfortunately, I don't know enough Maven to try to debug this one. WORKAROUND touch src/test/java/i.am.blank
        Hide
        Andrew Eisenberg added a comment -

        There is another workaround, to use the build-helper plugin and specify the extra test folder explicitly using the add-test-source goal. However, that is something that I tried to avoid when I created the compiler plugin. I didn't want any extra configuration.

        I don't know that much about maven plugins either, but it might be possible for the groovy-eclipse-compiler plugin to call the build-helper-plugin with the appropriate goal in order to add the test source folder.

        Show
        Andrew Eisenberg added a comment - There is another workaround, to use the build-helper plugin and specify the extra test folder explicitly using the add-test-source goal. However, that is something that I tried to avoid when I created the compiler plugin. I didn't want any extra configuration. I don't know that much about maven plugins either, but it might be possible for the groovy-eclipse-compiler plugin to call the build-helper-plugin with the appropriate goal in order to add the test source folder.
        Hide
        The Alchemist added a comment -

        @Andrew: I'm not sure if groovy-eclipse-compiler can call build-helper-plugin because it doesn't have any Mojo's. But it's definitely worth a try.

        Show
        The Alchemist added a comment - @Andrew: I'm not sure if groovy-eclipse-compiler can call build-helper-plugin because it doesn't have any Mojo's. But it's definitely worth a try.
        Hide
        Andrew Eisenberg added a comment -

        I've been trying to find a clean solution where these source folders are added automatically, but unfortunately, that doesn't seem to be the way that maven works.

        The best I could do is to create two simple mojos inside of the groovy-eclipse-compiler plugin that adds the extra source folders, but then this information needs to be explicitly added to the pom.

        So, this is what it will look like (but haven't pushed this to any repository yet):

        		<plugins>
        			<plugin>
        				<groupId>org.apache.maven.plugins</groupId>
        				<artifactId>maven-compiler-plugin</artifactId>
        				<version>2.3.2</version>
        				<configuration>
        					<compilerId>groovy-eclipse-compiler</compilerId>
        				</configuration>
        				<dependencies>
        					<dependency>
        						<groupId>org.codehaus.groovy</groupId>
        						<artifactId>groovy-eclipse-compiler</artifactId>
        						<version>2.6.0-01-SNAPSHOT</version>
        					</dependency>
        				</dependencies>
        			</plugin>
        			<plugin>
        				<groupId>org.codehaus.groovy</groupId>
        				<artifactId>groovy-eclipse-compiler</artifactId>
        				<version>2.6.0-01-SNAPSHOT</version>
        				<executions>
        					<execution>
        						<id>add-source</id>
        						<phase>generate-sources</phase>
        						<goals>
        							<goal>add-groovy-source</goal>
        						</goals>
        					</execution>
        					<execution>
        						<id>add-test-source</id>
        						<phase>generate-test-sources</phase>
        						<goals>
        							<goal>add-groovy-test-source</goal>
        						</goals>
        					</execution>
        				</executions>
        			</plugin>
        		</plugins>
        

        It works, but it is annoying and not much better than using the build-helper-maven-plugin. I'd like to not have to include this extra cruft in the pom and call the new mojos implicitly. @Alchemist, do you have any experience with this?

        Show
        Andrew Eisenberg added a comment - I've been trying to find a clean solution where these source folders are added automatically, but unfortunately, that doesn't seem to be the way that maven works. The best I could do is to create two simple mojos inside of the groovy-eclipse-compiler plugin that adds the extra source folders, but then this information needs to be explicitly added to the pom. So, this is what it will look like (but haven't pushed this to any repository yet): <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <version>2.3.2</version> <configuration> <compilerId>groovy-eclipse-compiler</compilerId> </configuration> <dependencies> <dependency> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.6.0-01-SNAPSHOT</version> </dependency> </dependencies> </plugin> <plugin> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.6.0-01-SNAPSHOT</version> <executions> <execution> <id>add-source</id> <phase>generate-sources</phase> <goals> <goal>add-groovy-source</goal> </goals> </execution> <execution> <id>add-test-source</id> <phase>generate-test-sources</phase> <goals> <goal>add-groovy-test-source</goal> </goals> </execution> </executions> </plugin> </plugins> It works, but it is annoying and not much better than using the build-helper-maven-plugin. I'd like to not have to include this extra cruft in the pom and call the new mojos implicitly. @Alchemist, do you have any experience with this?
        Andrew Eisenberg made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        The Alchemist added a comment -

        @Andrew:
        Sorry, don't have any experience with that. But at least now we have a Maven workaround.

        Show
        The Alchemist added a comment - @Andrew: Sorry, don't have any experience with that. But at least now we have a Maven workaround.
        Hide
        Andrew Eisenberg added a comment -

        So, there are 4 workarounds, but none of them make me happy. I have been chatting with the folks at the maven users mailing list, but still nothing great.

        1. Add an empty file to your java source folders
        2. Use the build-helper-maven-plugin
        3. Use groovy-eclipse-compiler as I describe two comments ago (this part is not committed yet, but it works for me locally). This solution uses less configuration than the previous one, but is still 21 lines of configuration (about 6 fewer lines than the other solution).
        4. Move your Groovy code to Java source folders

        I'm just a bit disappointed that maven requires explicit configuration for anything that deviates from the normal. I think I will close this bug and completely describe all workarounds on the wiki.

        Show
        Andrew Eisenberg added a comment - So, there are 4 workarounds, but none of them make me happy. I have been chatting with the folks at the maven users mailing list, but still nothing great. Add an empty file to your java source folders Use the build-helper-maven-plugin Use groovy-eclipse-compiler as I describe two comments ago (this part is not committed yet, but it works for me locally). This solution uses less configuration than the previous one, but is still 21 lines of configuration (about 6 fewer lines than the other solution). Move your Groovy code to Java source folders I'm just a bit disappointed that maven requires explicit configuration for anything that deviates from the normal. I think I will close this bug and completely describe all workarounds on the wiki.
        Hide
        The Alchemist added a comment -

        @Andrew: Thanks for doing the legwork. Yeah, that configuration stinks...

        Show
        The Alchemist added a comment - @Andrew: Thanks for doing the legwork. Yeah, that configuration stinks...
        Hide
        Andrew Eisenberg added a comment -

        After much work, and a question on stack overflow, I have made significant progress.

        I now have a mojo that works quite nicely to add the source folders to the build. It is a lot of configuration to do a very simple thing, but at least it is hidden from the downstream developer. I will push out a snapshot of this.

        Show
        Andrew Eisenberg added a comment - After much work, and a question on stack overflow , I have made significant progress. I now have a mojo that works quite nicely to add the source folders to the build. It is a lot of configuration to do a very simple thing, but at least it is hidden from the downstream developer. I will push out a snapshot of this.
        Hide
        The Alchemist added a comment -

        @Andrew: Don't hesitate to shout and I'll give the snapshot a try.

        Show
        The Alchemist added a comment - @Andrew: Don't hesitate to shout and I'll give the snapshot a try.
        Hide
        Andrew Eisenberg added a comment -

        Thanks. Just deployed 2.6.0-01-SNAPSHOT to http://nexus.codehaus.org/snapshots/. If you want to use it in projects that have nothing in the java source and test folders, then do this in the plugins section:

            <plugin>
                <groupId>org.codehaus.groovy</groupId>
                <artifactId>groovy-eclipse-compiler</artifactId>
                <version>2.6.0-01-SNAPSHOT</version>
                <extensions>true</extensions>
            </plugin>
        

        That last line <extensions>true</extensions> is important since it states that groovy-eclipse compiler will be augmenting the default lifecycle. You will know if it is working if you see something like:

        Adding /src/main/groovy to the list of source folders
        Adding /src/test/groovy to the list of source folders
        

        in the logs.

        So, here's what's going on behind the scenes. I have redefined the lifecycle mappings for the common lifecycles that have a compile phase (jar, war, ejb, maven-plugin) and added an init phase, which calls the simple mojo that I created that adds the extra source folders.

        Please let me know if you get a chance to try this out.

        Show
        Andrew Eisenberg added a comment - Thanks. Just deployed 2.6.0-01-SNAPSHOT to http://nexus.codehaus.org/snapshots/ . If you want to use it in projects that have nothing in the java source and test folders, then do this in the plugins section: <plugin> <groupId>org.codehaus.groovy</groupId> <artifactId>groovy-eclipse-compiler</artifactId> <version>2.6.0-01-SNAPSHOT</version> <extensions> true </extensions> </plugin> That last line <extensions>true</extensions> is important since it states that groovy-eclipse compiler will be augmenting the default lifecycle. You will know if it is working if you see something like: Adding /src/main/groovy to the list of source folders Adding /src/test/groovy to the list of source folders in the logs. So, here's what's going on behind the scenes. I have redefined the lifecycle mappings for the common lifecycles that have a compile phase (jar, war, ejb, maven-plugin) and added an init phase, which calls the simple mojo that I created that adds the extra source folders. Please let me know if you get a chance to try this out.
        Hide
        Marc von Renteln added a comment -

        Tested the SNAPSHOT. It adds the folders correctly and the sources are compiled. Seems to do the same thing that maven-buildhelper-plugin does.

        But both solutions seem to add the folder twice for the other maven plugins... I tried to create a maven plugin written in groovy. The source is compiled but the groovy source file is found twice and therefore the generation of the plugin descriptor fails with a "duplicate mojo definition" error message...

        I use the default maven-plugin-plugin to generate the descriptor but with a modified extractor:

        <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-plugin-plugin</artifactId>
        <version>2.4</version>
        <dependencies>
        <dependency>
        <groupId>org.codehaus.mojo.groovy</groupId>
        <artifactId>groovy-mojo-tools</artifactId>
        <version>1.0-beta-2</version>
        </dependency>
        </dependencies>
        </plugin>

        Don't know if the extractor is wrong here but I wanted to mention it if you would like to test it with this plugin...

        The complete code can be found in https://github.com/mvonrenteln/groovy-mojo-example

        Show
        Marc von Renteln added a comment - Tested the SNAPSHOT. It adds the folders correctly and the sources are compiled. Seems to do the same thing that maven-buildhelper-plugin does. But both solutions seem to add the folder twice for the other maven plugins... I tried to create a maven plugin written in groovy. The source is compiled but the groovy source file is found twice and therefore the generation of the plugin descriptor fails with a "duplicate mojo definition" error message... I use the default maven-plugin-plugin to generate the descriptor but with a modified extractor: <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-plugin-plugin</artifactId> <version>2.4</version> <dependencies> <dependency> <groupId>org.codehaus.mojo.groovy</groupId> <artifactId>groovy-mojo-tools</artifactId> <version>1.0-beta-2</version> </dependency> </dependencies> </plugin> Don't know if the extractor is wrong here but I wanted to mention it if you would like to test it with this plugin... The complete code can be found in https://github.com/mvonrenteln/groovy-mojo-example
        Hide
        Andrew Eisenberg added a comment -

        So, just to be sure...is the problem that you cannot correctly create this plugin or that you cannot correctly use this plugin?

        Show
        Andrew Eisenberg added a comment - So, just to be sure...is the problem that you cannot correctly create this plugin or that you cannot correctly use this plugin?
        Hide
        Andrew Eisenberg added a comment -

        Right...it is the former.

        I have not created or tested groovy-eclipse-compiler with plugins in mind.

        Show
        Andrew Eisenberg added a comment - Right...it is the former. I have not created or tested groovy-eclipse-compiler with plugins in mind.
        Hide
        Andrew Eisenberg added a comment -

        A workaround — rename src/main/groovy to src/main/java and things work fine.

        Show
        Andrew Eisenberg added a comment - A workaround — rename src/main/groovy to src/main/java and things work fine.
        Hide
        Marc von Renteln added a comment -

        Thanks for your fast reply. I will use the workaround. My intention was to show this problem with other plugins...

        Show
        Marc von Renteln added a comment - Thanks for your fast reply. I will use the workaround. My intention was to show this problem with other plugins...
        Andrew Eisenberg made changes -
        Fix Version/s 2.6.1.Release [ 18147 ]
        Fix Version/s 2.6.0.Release [ 17849 ]
        Hide
        Andrew Eisenberg added a comment -

        The problem is in groovy-mojo-tools. The class GroovyMojoDescriptorExtractor, line 71. It is adding src/main/groovy a second time even if it already exists. There is a section:

                //
                // FIXME: Shouldn't need to hard-code this...
                //
                sourceRoots.add("src/main/groovy");
        

        And the comment is correct. This shouldn't be hardcoded. At the very least, the check should see if src/main/groovy is already on the path and if so, not add it a second time.

        As you said, you don't know who maintains this plugin. I would recommend forking the plugin for now and seeing if you can get this to work. Anyway, this bug is different from the bug originally reported in this issue, so if you have any more problems, please raise a new issue.

        Show
        Andrew Eisenberg added a comment - The problem is in groovy-mojo-tools . The class GroovyMojoDescriptorExtractor, line 71. It is adding src/main/groovy a second time even if it already exists. There is a section: // // FIXME: Shouldn't need to hard-code this ... // sourceRoots.add( "src/main/groovy" ); And the comment is correct. This shouldn't be hardcoded. At the very least, the check should see if src/main/groovy is already on the path and if so, not add it a second time. As you said, you don't know who maintains this plugin. I would recommend forking the plugin for now and seeing if you can get this to work. Anyway, this bug is different from the bug originally reported in this issue, so if you have any more problems, please raise a new issue.
        Hide
        Marc von Renteln added a comment -

        OK, thanks! I will fork the plugin and see what I can do there.

        Show
        Marc von Renteln added a comment - OK, thanks! I will fork the plugin and see what I can do there.
        Hide
        Andrew Eisenberg added a comment -

        I've done just about all I can do here. I will update the documentation to describe the various ways of setting up your source folders.

        The 2.6.0-01 version has been released.

        Show
        Andrew Eisenberg added a comment - I've done just about all I can do here. I will update the documentation to describe the various ways of setting up your source folders. The 2.6.0-01 version has been released.
        Andrew Eisenberg made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Fix Version/s 2.6.0.Release [ 17849 ]
        Fix Version/s 2.6.1.Release [ 18147 ]
        Resolution Fixed [ 1 ]

          People

          • Assignee:
            Andrew Eisenberg
            Reporter:
            The Alchemist
          • Votes:
            1 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: