使用Maven构建Groovy项目时出现源错误 [英] Getting a source error building Groovy project with Maven

查看:375
本文介绍了使用Maven构建Groovy项目时出现源错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用maven构建我的第一个groovy项目,但是我从maven得到以下错误。它的源错误somettype,但是Idont明白为什么我得到它。

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

以下是我的源代码:

package org.smith

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

以下是我的pom.xml文件:

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>


推荐答案

你的第一个线索是错误:没有这样的属性:类的项目:org.jsmith.Example
道歉重申您的错误作为您的答案,但让我解释。这就是说你的源代码中有一个对变量项目的引用。 (可能在你没有发布的源代码中,或者在你无意中改变它并且发布之前可能在源代码中)。

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.

这篇关于使用Maven构建Groovy项目时出现源错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆