我正在尝试使用maven构建我的第一个groovy项目但是我从maven得到以下错误..它的somettype源错误但是我不明白为什么我得到它。
[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>
答案 0 :(得分:0)
您的第一个线索是错误:No such property: project for class: org.jsmith.Example
抱歉重申您的错误作为答案,但让我解释一下。它说在你的源代码中你有一个变量project
的引用。 (在您无意中更改之前和发布之前,您可能在源代码中未发布或可能未在源中发布了吗?)
我想你可能在包名后输入了一个拼写错误或者在你的类定义之后有一些额外的测试代码?对于Eg。这样的事情可能会产生这样的错误:
package org.smith
/**
* Example Groovy class.
*/
class Example
{
def show() {
println 'Hello World'
}
}
println project.path
同样,您应该在错误时发布更新的代码以及与代码匹配的确切错误。很难根据你上面的问题确定问题所在。
答案 1 :(得分:-1)
如果您使用的是脚本而不是内联,则必须定义项目并绑定到mavenProject。
def project = ${project}; // this will bind to the Maven Project property.
同样
def session = ${session} //will bind to MavenSession
Source - 查找自定义属性