【问题标题】:Getting a source error building Groovy project with Maven使用 Maven 构建 Groovy 项目时出现源错误
【发布时间】:2015-07-23 05:17:52
【问题描述】:

我正在尝试使用 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>

【问题讨论】:

  • 您的 groovy 文件看起来不像可以执行的脚本。您是否尝试过简单地做一些println "Hello" 而不是上课?您是否尝试使用 1.4 版的 gmaven 插件?

标签: maven groovy gmaven-plugin


【解决方案1】:

您的第一条线索是错误: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

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

【讨论】:

  • 我已经更新了我的答案以反映您更新的错误。错误似乎仍然与代码不同步。请发布发生错误时存在的代码。
  • 我有同样的错误,我的脚本中没有名为 project 的变量或字符串 proj
【解决方案2】:

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

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

同样

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

Source - 寻找自定义属性

【讨论】:

  • 我面临与 OP 相同的错误。你能详细说明你的答案吗? “您必须定义项目并绑定到 mavenProject”是什么意思?
  • @AlexKravets 你找到解决方案了吗?
  • @ArtB 不,我没有解决这个问题,而是在 ANT 脚本中调用了我的 Groovy 类,这在当时对我所做的事情更有意义。
  • @AlexKravets 我被switching to GMavenPlus“解决”了。
  • @ArtB 很好,我会注意的。感谢您的回复。
猜你喜欢
  • 1970-01-01
  • 2019-01-27
  • 2018-07-10
  • 2020-07-06
  • 2015-04-14
  • 2011-11-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多