GMaven
  1. GMaven
  2. GMAVEN-80

Automatically add src/main/groovy as a compile source root

    Details

    • Type: Improvement Improvement
    • Status: Resolved Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.2
    • Fix Version/s: 1.5
    • Component/s: None
    • Labels:
      None
    • Number of attachments :
      1

      Description

      For plugins like maven-source-plugin to work correctly with Groovy, src/main/groovy needs to be defined as a compile source root, and src/test/groovy as a test compile source root. Here is how I currently achieve this (otherwise the sources Jar won't contain any Groovy sources):

      <plugin>
        <groupId>org.codehaus.gmaven</groupId>
        <artifactId>gmaven-plugin</artifactId>
        <version>1.2</version>
        ...
        <executions>
          ...
          <execution>
            <id>init-groovy</id>
            <phase>initialize</phase>
            <goals>
              <goal>execute</goal>
            </goals>
            <configuration>
              <source>
                project.addCompileSourceRoot("src/main/groovy")
                project.addTestCompileSourceRoot("src/test/groovy")
              </source>
            </configuration>
          </execution>
        </executions>
      </plugin>
      

      It would be nice if GMaven added those source roots automatically. Probably it's best to do this early in the lifecycle, e.g. with an "init" goal whose default phase is "initialize".

        Activity

        Hide
        Peter Niederwieser added a comment -

        Script needs to be changed as follows to work for multi-module builds:

        <source>
          project.addCompileSourceRoot("$project.basedir/src/main/groovy")
          project.addTestCompileSourceRoot("$project.basedir/src/test/groovy")
        </source>
        
        Show
        Peter Niederwieser added a comment - Script needs to be changed as follows to work for multi-module builds: <source> project.addCompileSourceRoot("$project.basedir/src/main/groovy") project.addTestCompileSourceRoot("$project.basedir/src/test/groovy") </source>
        Hide
        Keegan Witt added a comment -

        Could you clarify what you're suggesting be changed (if possible, attach a patch) and why it is needed?

        Show
        Keegan Witt added a comment - Could you clarify what you're suggesting be changed (if possible, attach a patch) and why it is needed?
        Hide
        Marc von Renteln added a comment -

        GMaven uses src/main/groovy as base folder for compilation but it does not register it as compile source root. This is needed if some other plugins have to work with the sources. At this time other plugins do not recognize src/main/groovy as source folder and only process files laying in src/main/java.

        This could also be archived with the maven-buildhelper-plugin (http://mojo.codehaus.org/build-helper-maven-plugin/add-source-mojo.html). But I agree that this should be done automatically by the GMaven-Plugin.

        Show
        Marc von Renteln added a comment - GMaven uses src/main/groovy as base folder for compilation but it does not register it as compile source root. This is needed if some other plugins have to work with the sources. At this time other plugins do not recognize src/main/groovy as source folder and only process files laying in src/main/java. This could also be archived with the maven-buildhelper-plugin ( http://mojo.codehaus.org/build-helper-maven-plugin/add-source-mojo.html ). But I agree that this should be done automatically by the GMaven-Plugin.
        Hide
        Keegan Witt added a comment -

        I tried to get Maven to always executing this during the initialize phase, but it doesn't seem to be working It does work when you add the new mojo to the list of goals. Another option would be to have this happen in the mojos bound to the compile and testCompile phases. Which option would work better for you? Or do you have another idea?

        Also, I think you probably want the directories GMaven was told to use for sources added to the project sources, and not just the default directories. As it is now, the source directories are in CompilerMojoSupport which the both compile mojos and both stub generation mojos inherit from. I restructured this (but haven't committed it yet) so we separate out the main sources from the test sources in the pom configuration. Without this, the new mojo wouldn't be able to tell whether to use addCompileSourceRoot() or addTestCompileSourceRoot() because the only parameter currently available to use is 'sources'. Jason, does that seem reasonable?

        I wanted to include this in 1.4, but since it isn't quite as simple as just throwing a couple of lines in (though it's not much more complicated) and I didn't want to delay the 1.4 release any further, so I pushed this issue until the next release.

        Show
        Keegan Witt added a comment - I tried to get Maven to always executing this during the initialize phase, but it doesn't seem to be working It does work when you add the new mojo to the list of goals. Another option would be to have this happen in the mojos bound to the compile and testCompile phases. Which option would work better for you? Or do you have another idea? Also, I think you probably want the directories GMaven was told to use for sources added to the project sources, and not just the default directories. As it is now, the source directories are in CompilerMojoSupport which the both compile mojos and both stub generation mojos inherit from. I restructured this (but haven't committed it yet) so we separate out the main sources from the test sources in the pom configuration. Without this, the new mojo wouldn't be able to tell whether to use addCompileSourceRoot() or addTestCompileSourceRoot() because the only parameter currently available to use is 'sources'. Jason, does that seem reasonable? I wanted to include this in 1.4, but since it isn't quite as simple as just throwing a couple of lines in (though it's not much more complicated) and I didn't want to delay the 1.4 release any further, so I pushed this issue until the next release.
        Hide
        Keegan Witt added a comment -

        Attached a patch showing what I've been playing with.

        Show
        Keegan Witt added a comment - Attached a patch showing what I've been playing with.

          People

          • Assignee:
            Keegan Witt
            Reporter:
            Peter Niederwieser
          • Votes:
            2 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: