Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 2.5.2.Release
-
Fix Version/s: 2.6.0.Release
-
Component/s: Maven integration
-
Labels:
-
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.)
-
Hide
- groovy.tests.ignored.zip
- 20/Oct/11 7:20 AM
- 7 kB
- The Alchemist
-
- svn.mvn.test/.springBeans 0.5 kB
- svn.mvn.test/pom.xml 3 kB
- svn.mvn.test/src/.../bcc.properties 0.4 kB
- svn.mvn.test/src/main/.../kp/BuildInfo.java 2 kB
- svn.mvn.test/src/test/.DS_Store 6 kB
- __MACOSX/svn.mvn.test/.../test/._.DS_Store 0.1 kB
- svn.mvn.test/src/.../kp/BuildInfoTest.groovy 0.9 kB
Activity
@Andrew: Thank you!
If you point me in the right direction, I'll send over a patch!
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.
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!
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:
@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
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.
@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.
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:
Sorry, don't have any experience with that. But at least now we have a Maven workaround.
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.
@Andrew: Thanks for doing the legwork. Yeah, that configuration stinks...
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.
@Andrew: Don't hesitate to shout and I'll give the snapshot a try.
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.
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
So, just to be sure...is the problem that you cannot correctly create this plugin or that you cannot correctly use this plugin?
Right...it is the former.
I have not created or tested groovy-eclipse-compiler with plugins in mind.
A workaround — rename src/main/groovy to src/main/java and things work fine.
Thanks for your fast reply. I will use the workaround. My intention was to show this problem with other plugins...
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.
OK, thanks! I will fork the plugin and see what I can do there.
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.
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.