这是一个 Maven 项目。要构建和运行 groovy 脚本,使用“gmavenplus”插件。当我在 Maven 中运行脚本时,即使我应用了 -X 选项,错误看起来像:
mvn -X clean install gplus:execute
[错误] 无法在项目 users_rest_updater 上执行目标 org.codehaus.gmavenplus:gmavenplus-plugin:1.5:execute (default-cli):从类路径调用 Groovy 类的方法时出错。InvocationTargetException:没有这样的属性:类的参数:Script1 -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException:无法执行目标 org.codehaus.gmavenplus:gmavenplus-plugin:1.5:execute (default-cli) on项目 users_rest_updater:从类路径调用 Groovy 类的方法时发生错误。在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216) 在 org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153) 在 org.apache.maven.lifecycle .internal.MojoExecutor.execute(MojoExecutor.java:145) 在 org.apache.maven.lifecycle。在 sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 在 java.lang.reflect.Method.invoke(Method.java: 43) 的 invoke0(Native Method) 498) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) 在 org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) 在 org.codehaus.plexus .classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) 引起:org.apache.maven.plugin.MojoExecutionException:错误从类路径调用 Groovy 类的方法时发生。在 org.codehaus.gmavenplus.mojo.ExecuteMojo.doExecute(ExecuteMojo.java:128)。
我从 IDE (Intellij IDEA) 运行相同的脚本,但在控制台中它会写入确切的错误,在我的情况下是:
Caught: java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException java.lang.NoClassDefFoundError: org/apache/commons/cli/ParseException at MainApp.run(MainApp.groovy:3) Caused by: java.lang.ClassNotFoundException: org.apache.commons.cli.ParseException ... 1 more
当前 pom 文件:
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>...</groupId>
<artifactId>...</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.6</version>
<!--<scope>runtime</scope>-->
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxrs</artifactId>
<version>3.0.16.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-client</artifactId>
<version>3.0.16.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jaxb-provider</artifactId>
<version>3.0.16.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-jackson2-provider</artifactId>
<version>3.0.16.Final</version>
</dependency>
</dependencies>
<build>
<finalName>test</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>compile</goal>
<goal>testGenerateStubs</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<scripts>
<script>file:///${project.basedir}/src/main/groovy/MainApp.groovy</script>
</scripts>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.6</version>
<scope>runtime</scope>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>MainApp</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
如何强制 maven 显示确切的错误?没有它,我无法找到找出问题所在的方法。对于 java 代码,maven 总是可以正常工作。您总是可以看到问题的主要原因。可能是gmavenplus
maven插件的问题,我不确定。