1

我正在尝试使用 maven 构建我的第一个 groovy 项目,但我从 maven 收到以下错误。它是某种类型的源错误,但我不明白我为什么会得到它。

[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 文件:

<?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>

4

2 回答 2

0

你的第一个线索是错误:很No such property: project for class: org.jsmith.Example 抱歉重申你的错误作为你的答案,但让我解释一下。意思是在您的源代码的某个地方,您有一个对变量的引用project。(可能在您未发布的源中,或者在您无意更改之前和发布之前可能在源中??)

我想你可能在你的类定义之后的包名中有错字或一些额外的测试代码?例如。这样的事情可能会产生这样的错误:

package org.smith

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

同样,您应该在错误发生时发布更新的代码以及与代码匹配的确切错误。很难根据上面的内容来确定问题所在。

于 2013-01-25T18:12:23.147 回答
-1

如果您使用脚本而不是内联,则必须定义项目并绑定到 mavenProject。

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

同样地

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

来源- 寻找自定义属性

于 2013-05-16T16:43:15.287 回答