gpt4 book ai didi

java - 从 GMaven 运行脚本会导致 "No such property: project"异常

转载 作者:行者123 更新时间:2023-12-01 23:14:20 25 4
gpt4 key购买 nike

tl;dr: 使用 GMaven 从 Maven 中运行 Groovy 脚本时,如何解决“No such property: project”错误?我正在使用 GMaven 1.5、Groovy 2.2.1。以及 Java 1.7 和 Maven 3.1.0 。

<小时/>

我有一个 Groovy 脚本 -DeltaCodeGen(它没有包)- 可以生成 Java 代码(对于 Java 项目,这是项目中唯一的 Groovy)。过去,我们会让脚本生成 .java 文件,然后将这些文件 checkin ,但现在我们尝试在 generate-sources 期间的 Maven 构建过程中构建它们。阶段。

我可以从 IDE 成功运行该脚本,但是当我尝试将其作为构建的一部分运行时,我得到了

Caused by: org.codehaus.groovy.runtime.metaclass.MissingPropertyExceptionNoStack: No such property: project for class: DeltaCodeGen

尽管other answers ,我的脚本没有名为 project 的变量,也不包含字符串“project”。它不扩展任何其他脚本。它使用的唯一库是 Reflections (对 Servlet API 的需求仍然是 open question )。

运行构建时,我在 stderr 中注意到(通过运行 mvn -X 2>mvn_err.log)以下错误:

java.lang.NoSuchMethodError: org.codehaus.groovy.runtime.InvokerHelper.getVersion()Ljava/lang/String;
at org.codehaus.gmaven.runtime.v1_6.ProviderImpl.name(ProviderImpl.java:70)
at org.codehaus.gmaven.feature.support.ProviderSupport.asString(ProviderSupport.java:175)
at org.codehaus.gmaven.feature.support.ProviderSupport.toString(ProviderSupport.java:68)
at org.slf4j.helpers.MessageFormatter.safeObjectAppend(MessageFormatter.java:304)
at org.slf4j.helpers.MessageFormatter.deeplyAppendParameter(MessageFormatter.java:276)
at org.slf4j.helpers.MessageFormatter.arrayFormat(MessageFormatter.java:230)
at org.slf4j.helpers.MessageFormatter.format(MessageFormatter.java:152)
at org.slf4j.impl.SimpleLogger.formatAndLog(SimpleLogger.java:414)
at org.slf4j.impl.SimpleLogger.debug(SimpleLogger.java:512)
at org.codehaus.gmaven.runtime.loader.DefaultProviderSelector.register(DefaultProviderSelector.java:135)
at org.codehaus.gmaven.runtime.loader.DefaultProviderSelector.select(DefaultProviderSelector.java:72)
at org.codehaus.gmaven.runtime.loader.DefaultProviderManager.select(DefaultProviderManager.java:102)
at org.codehaus.gmaven.plugin.ProviderMojoSupport.provider(ProviderMojoSupport.java:120)
at org.codehaus.gmaven.plugin.ComponentMojoSupport.feature(ComponentMojoSupport.java:49)
at org.codehaus.gmaven.plugin.ComponentMojoSupport.feature(ComponentMojoSupport.java:42)
at org.codehaus.gmaven.plugin.ComponentMojoSupport.doExecute(ComponentMojoSupport.java:53)
at org.codehaus.gmaven.plugin.MojoSupport.execute(MojoSupport.java:71)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:106)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:84)
at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:59)
at org.apache.maven.lifecycle.internal.LifecycleStarter.singleThreadedBuild(LifecycleStarter.java:183)
at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:161)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:318)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:153)
at org.apache.maven.cli.MavenCli.execute(MavenCli.java:555)
at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:214)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:290)
at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:230)
at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:414)
at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:357)
<小时/>

我的 Maven 配置是:

<build>
<plugins>
<plugin>
<!-- see: http://docs.codehaus.org/display/GMAVEN/Executing+Groovy+Code#ExecutingGroovyCode-ExecuteaLocalGroovyScript -->
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${pom.basedir}/src/main/groovy/DeltaCodeGen.groovy</source>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.reflections</groupId>
<artifactId>reflections</artifactId>
<version>0.9.9-RC1</version>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.2.1</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

最佳答案

我最终开始工作的是替换 GMaven (已废弃)与 GMavenPlus (目前正在维护)。

由于运行本地脚本当前未指定为 example ,这就是我的 POM 中对我有用的内容:

<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<scripts>
<script>file:/${pom.basedir}/src/main/groovy/DeltaCodeGen.groovy</script>
</scripts>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.2.1</version>
</dependency>
</dependencies>
</plugin>

关于java - 从 GMaven 运行脚本会导致 "No such property: project"异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21462396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com