Announcement Announcement Module
No announcement yet.
Building Groovy projects? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Building Groovy projects?

    I'm trying to build a simple groovy project in STS 2.5.2 with the groovy extension installed.

    I can run the project in the IDE, but I doesn't seem to do anything when I build it. If I build it with maven, I end up with an empty JAR.

    I have almost no experience with builds. I'm just trying to get a JAR that I can run from the crontab on a Linux server. (The project is being developed in Windows.)

  • #2

    If you truly just want a jar representing the built code you could either just jar up the output folders from the project (on the command line) or use the eclipse export-jar mechanism (File>Export menu).

    Maybe if you attach the pom here we can comment on what might be up with it.

    Andy Clement
    SpringSource Tool Suite Team


    • #3
      Thanks for the reply.

      The POM looks pretty much empty. I don't see anything that would tell it that the project is of Groovy nature.

      <project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
      I also get a the following warning in the IDE:
      Description Resource Path Location Type
      Build path specifies execution environment J2SE-1.4. There are no JREs installed in the workspace that are strictly compatible with this environment. Labyrinth Build path JRE System Library Problem
      Looks like I'm not set up to compile Groovy???

      I wasn't sure if STS should be able to build the project (with or without maven) or if I needed to add additional plugins. I'm new at this and I really appreciate the help.


      • #4
        I just created a valid pom for a groovy project, using the instructions here:

        mvn archetype:generate -DarchetypeGroupId=org.codehaus.groovy.maven.archet ypes -DarchetypeArtifactId=gmaven-archetype-basic
        Here is the pom, you should be able to copy the dependencies/build section into your pom.xml to introduce the gmaven dependency and build your project. Hopefully it'll pull down all the pre-reqs when you run it.

        <project xmlns="" xmlns:xsi="" xsi:schemaLocation="">
            <name>Example Project</name>
        As for being setup. If you have installed the groovy plugin from the extensions page, which I believe you have as you are OK to work on groovy code in your project, then you should be good to go.



        • #5
          We also have an alternative way to build groovy projects using our groovy-eclipse compiler rather than gmaven, if you want to try that there is an article here to help you:

          There is a demo project linked from there that ought to help (and make sure to read through the page comments that address some issues).



          • #6
            I get this when I try to export it as a JAR:

            Jar export finished with problems. See details for additional information.
            Could not find main method from given launch configuration.
            I'm only seeing Java options in the export menu. Is this right? I also have Grails project that I will need to deploy. I'm starting to wonder if that will build. Both projects run fine from the IDE.

            I'm not sure if I'm the problem (because I didn't set the project/IDE up correctly) or if I have a problem with an extension in the IDE. Are there any STS/Groovy tutorials out there that would help me?


            • #7
              Thanks Andy! I will start reading and see if I can get Gmaven working.

              I have the extension installed and I guess it's working since I can run my project. The Grails project also runs from the IDE without a hitch.

              So the extension doesn't handle the builds and I need alternative mesures to build straight Groovy projects. Is this correct?


              • #8
                Still not working.
                 Scanning for projects...
                [INFO] ------------------------------------------------------------------------
                [INFO] Building Unnamed - Labyrinth:Labyrinth:jar:0.0.1-SNAPSHOT
                [INFO]    task-segment: [package]
                [INFO] ------------------------------------------------------------------------
                [INFO] [groovy:generateStubs {execution: default}]
                [INFO]  No sources found for Java stub generation
                [INFO] [resources:resources {execution: default-resources}]
                [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
                [INFO] skip non existing resourceDirectory C:\Documents and Settings\Pathfinder\My Documents\workspace-sts-2.5.2.RELEASE\Labyrinth\src\main\resources
                [INFO] [compiler:compile {execution: default-compile}]
                [INFO] No sources to compile
                [INFO] [groovy:compile {execution: default}]
                [INFO]  No sources found to compile
                [INFO] [groovy:generateTestStubs {execution: default}]
                [INFO]  No sources found for Java stub generation
                [INFO] [resources:testResources {execution: default-testResources}]
                [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
                [INFO] skip non existing resourceDirectory C:\Documents and Settings\Pathfinder\My Documents\workspace-sts-2.5.2.RELEASE\Labyrinth\src\test\resources
                [INFO] [compiler:testCompile {execution: default-testCompile}]
                [INFO] No sources to compile
                [INFO] [groovy:testCompile {execution: default}]
                [INFO]  No sources found to compile
                [INFO] [surefire:test {execution: default-test}]
                [INFO] Surefire report directory: C:\Documents and Settings\Pathfinder\My Documents\workspace-sts-2.5.2.RELEASE\Labyrinth\target\surefire-reports
                 T E S T S
                There are no tests to run.
                Results :
                Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
                [INFO] [jar:jar {execution: default-jar}]
                [INFO] Building jar: C:\Documents and Settings\Pathfinder\My Documents\workspace-sts-2.5.2.RELEASE\Labyrinth\target\Labyrinth-0.0.1-SNAPSHOT.jar
                [INFO] ------------------------------------------------------------------------
                [INFO] BUILD SUCCESSFUL
                [INFO] ------------------------------------------------------------------------
                [INFO] Total time: 4 seconds
                [INFO] Finished at: Mon Feb 14 14:31:32 EST 2011
                [INFO] Final Memory: 16M/39M
                [INFO] ------------------------------------------------------------------------
                I copied the portions of the POM as advised but my jar is still coming up empty. Maven can't find the sources, but it is now looking Groovy code.

                A couple of other notes:

                Do I need to install the Gmavin plugin? I'm not finding any downloads or instructions.

                My class no longer runs in the IDE. I get an error stating that the "editor dose not contain a main type."

                Do I need to run the "mvn archetype:generate" command? If so, how do I do that in Windows? I don't have anything set up at the moment.

                Last thought. This Groovy project is only 100 lines of code in a single class. It started out as a groovy script, but we need it to run on 180 servers. None have groovy installed so we decided to compile it into a JAR. Seems like this is becoming more difficult than I expected and I am thinking it might make more sense to convert it to a Java class. (I would like to be able to use Groovy though.)

                Any other ideas or thoughts would be appreciated.


                • #9
                  You also should be using the Groovy-Eclipse m2eclipse integration in order to ensure that your project is properly configured when it is imported into Eclipse. You can get the plugin here:

                  This should allow you to configure your groovy project from within Eclipse/STS (assuming that you are also using m2eclipse). And you will need this regardless of whether you are using GMaven, or the Groovy-Eclipse compiler plugin for maven.

                  I don't know enough about how your project is structured to know exactly what your problem is, but when using gmaven, you must make sure that your groovy files are contained in src/main/groovy, not src/main/java.

                  I am less familiar with GMaven than I am the Groovy-Eclipse compiler plugin for maven. I do know that it is more flexible (eg- you can choose which version of Groovy you want to use as a compiler), but the Groovy-Eclipse compiler plugin for maven is easier to configure (since you don't have to worry about stub generation or putting any files in src/main/groovy).

                  In your situation since you are only working with a single Groovy file, these distinctions are less meaningful. You do not need to worry about stub generation and I'd guess that you only need to compile against the latest version of Groovy.


                  • #10
                    After many unsuccessful attempts with maven, I ended up taking the easy way out and using the export method mentioned above. It will get the job done for now.

                    Thanks for all of the help.