我现在就说:我从来没有使用过Maven/Groovy,然而,最近我得到了一份工作,要编写一个脚本,从.properties文件中自动创建一个枚举。
为此,我使用了GMavenPlus插件。我已经根据this问题的答案编写了脚本。我不能使用答案中相同的pom的原因是因为它使用的是GMaven,它已经停止使用了。
现在,当我试图在cmd上运行它时,我得到了错误
Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.5:execute <create-enum> on project gui: Error occurred while calling a method on a Groovy class
from classpath. InvocationTargetException: No such property: pom for class: Script1 -> [Help 1]下面是我的pom.xml的重要部分:
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>create-enum</id>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script><![CDATA[
import java.io.File
import com.cclsd.gdg.client.EnumGenerator
File dir = new File( pom.basedir,
"src/main/resources/com/cclsd/gdg/client")
new EnumGenerator(
new File( pom.build.directory,
"generated-sources/enums"),
new File(dir,
"properties/config.properties"),
new File(dir,
"EnumTemplate.txt"),
"com.cclsd.gdg.client.data",
"PropertyEnum"
)
]]></script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<!-- any version of Groovy \>= 1.5.0 should work here -->
<version>2.4.7</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.gmavenplus
</groupId>
<artifactId>
gmavenplus-plugin
</artifactId>
<versionRange>
[1.0.0,)
</versionRange>
<goals>
<goal>execute</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
注意:插件管理标签下的所有内容都是我从the official m2e site获得的,应该会导致脚本在generate-sources阶段执行
我真的需要有人在这里帮助我,我在谷歌上几乎找不到关于这个错误的任何东西。另外,一个全面的关于在maven中执行脚本的教程也会很好。
祝你今天愉快~克劳利
编辑:它还显示警告,POM无效,传递趋势(如果有)将不可用,请启用调试日志以了解更多详细信息
https://stackoverflow.com/questions/38377845
复制相似问题