1

I am trying to build my first groovy project with maven but I am getting the following error from maven.. its somettype of source error but Idont understand why I am getting it.

[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.186s
[INFO] Finished at: Fri Jan 25 15:36:09 EST 2013
[INFO] Final Memory: 15M/163M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.codehaus.gmaven:gmaven-plugin:1.3:execute (default) on project groovyhello: org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No such property: project for class: org.smith.Example -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1

Below is my source code:

package org.smith

/**
 * Example Groovy class.
 */
class Example
{
    def show() {
        println 'Hello World'
    }
}

and here is my pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

<modelVersion>4.0.0</modelVersion>

<groupId>org.smith</groupId>
<artifactId>groovyhello</artifactId>
<name>Example Project</name>
<version>1.0-SNAPSHOT</version>

<dependencies>
    <dependency>
        <groupId>org.codehaus.groovy.maven.runtime</groupId>
        <artifactId>gmaven-runtime-1.6</artifactId>
        <version>1.0</version>
    </dependency>

    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>


        <plugin>
            <groupId>org.codehaus.gmaven</groupId>
            <artifactId>gmaven-plugin</artifactId>
            <version>1.3</version>
            <executions>
                <execution>
                    <phase>generate-resources</phase>
                    <goals>
                        <goal>execute</goal>
                    </goals>
                    <configuration>
                        <source>${pom.basedir}/src/main/groovy/org/smith/Example.groovy</source>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

Keegan
  • 11,345
  • 1
  • 25
  • 38
techsjs2013
  • 2,607
  • 5
  • 20
  • 25
  • Your groovy file does not look like a script that could be executed. Did you try simply doing some `println "Hello"` instead of the class? Did you try using version 1.4 of the `gmaven` plugin? – madth3 Jan 26 '13 at 01:36

2 Answers2

0

Your 1st clue is the error: No such property: project for class: org.jsmith.Example Apologies for restating your error as your answer but let me explain. It's saying that somewhere in your source you have a reference to a variable project. (possible in source you haven't posted or possibly in the source before you inadvertnly changed it and before you posted??)

I imagine you probably had a typo in the package name or some extra test code after your class definition? For Eg. something like this could generate such an error:

package org.smith

/**
 * Example Groovy class.
 */
class Example
{
    def show() {
        println 'Hello World'
    }
}
println project.path

Again, you should post both the updated code at the time of the error and the exact error matching the code. It's hard to determine based on what you have above where your problems lie.

Sled
  • 18,541
  • 27
  • 119
  • 168
Cliff
  • 10,586
  • 7
  • 61
  • 102
  • and I've updated my answer to reflect your updated error. It still seems like the error is out of sync with the code. please post the code as it exists at the time of the error. – Cliff Jan 27 '13 at 17:05
  • I have the same error and I have no variable named `project` or the string `proj` anywhere in my script. – Sled Jan 29 '14 at 22:06
-1

You will have to define project and bind to mavenProject if you are using script rather than inline.

def project = ${project}; // this will bind to the Maven Project property.

likewise

def session = ${session} //will bind to MavenSession

Source - Look for custom properties

avijendr
  • 3,958
  • 2
  • 31
  • 46
  • 1
    I am faced with the same error as OP. Can you elaborate on your answer? What do you mean by "You will have to define project and bind to mavenProject"? – positron Aug 15 '13 at 16:25
  • @ArtB No, I didn't resolve this issue and went with calling my Groovy class in ANT script which made more sense at the time with what I was doing. – positron Jan 30 '14 at 16:22
  • 1
    @AlexKravets I got it "resolved" by [switching to GMavenPlus](http://stackoverflow.com/q/21462396/254477). – Sled Jan 31 '14 at 15:01
  • @ArtB Very nice, I will take note. Thanks for replying. – positron Jan 31 '14 at 15:05