3

It is a maven project. To build and run groovy script "gmavenplus" plugin is used. When I run script in maven, even when I apply the -X option, the error looks like:

mvn -X clean install gplus:execute

[ERROR] Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.5:execute (default-cli) on project users_rest_updater: Error occurred while calling a method on a Groovy class from classpath. InvocationTargetException: No such property: args for class: Script1 -> [Help 1] org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.codehaus.gmavenplus:gmavenplus-plugin:1.5:execute (default-cli) on project users_rest_updater: Error occurred while calling a method on a Groovy class from classpath. at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:216) 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:116) at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80) at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51) at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:128) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:307) at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:193) at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:106) at org.apache.maven.cli.MavenCli.execute(MavenCli.java:862) at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:286) at org.apache.maven.cli.MavenCli.main(MavenCli.java:197) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289) at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229) at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415) at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356) Caused by: org.apache.maven.plugin.MojoExecutionException: Error occurred while calling a method on a Groovy class from classpath. at org.codehaus.gmavenplus.mojo.ExecuteMojo.doExecute(ExecuteMojo.java:128) at org.codehaus.gmavenplus.mojo.ExecuteMojo.execute(ExecuteMojo.java:83) at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134) at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208) ... 20 more Caused by: java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.codehaus.gmavenplus.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:118) at org.codehaus.gmavenplus.mojo.ExecuteMojo.executeScripts(ExecuteMojo.java:195) at org.codehaus.gmavenplus.mojo.ExecuteMojo.doExecute(ExecuteMojo.java:124) ... 23 more Caused by: groovy.lang.MissingPropertyException: No such property: args for class: Script1 at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:53) at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:52) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:307) at Script1.run(Script1.groovy:4) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:585) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:623) at groovy.lang.GroovyShell.evaluate(GroovyShell.java:594)

I run the same script from IDE (Intellij IDEA), but in the console it writes exact error, in my case it is:

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

current pom file:

<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>

How can I force maven to show exact error? Without it I cannot see a way to find what's going wrong. For java code, maven always works fine. You always can see the main cause of the problem. Probably it is a problem of gmavenplus maven plugin, I'm not sure.

Alexandr
  • 9,213
  • 12
  • 62
  • 102
  • Why are you running with `-X` isn't that `No such property: args for class: Script1` not enough? And `Script1.groovy:4`...can you show your pom file? – khmarbaise Mar 30 '16 at 09:16
  • @khmarbaise, I've attached my pom.xml file. Not the problem has been resolved by adding dependency to commons-cli, but the main problem for me, why I could not the error when run it via maven, at the same time, my IDE displays the reason why it fails – Alexandr Mar 30 '16 at 09:28

1 Answers1

2

If you just run the script as a Groovy script in IntelliJ, it won't know about any of your project dependencies. GMavenPlus includes your Maven dependencies in the classpath it uses to execute your scripts. To run as a standalone script, you'll have to add the dependencies needed with Grape. Note that using Grape inside scripts executed by GMavenPlus also works.

If you're trying to read arguments passed from commandline, the arguments will be consumed by Maven, GMavenPlus won't have an opportunity to read them. If you need the script to be invokable both as standalone and through Maven, you should set properties for Maven usage, and check in your script if they're set before parsing args.

If args is giving you trouble, you could try this.args, they're equivalent.

Keegan
  • 11,345
  • 1
  • 25
  • 38