1

I'll say it right away: I never worked with Maven/Groovy, however, recently I got the job to write a script that automatically creates an enum out of a .properties file.

I use the GMavenPlus plugin for this. I already wrote the script modelled after the answer to this question. The reason why I can't use the same pom as in the answer is because it uses GMaven, which was discontinued.

Now, when I am trying to run it over cmd I get the Error

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]

And here are the important parts of my 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>

Note: everything under the pluginmanagement tag I got from the official m2e site and should cause the script to be executed at the generate-sources phase

I really need someone to help me here, I literally couldn't find a single thing on Google about this error. Also a comprehensive tutorial about executing scripts in maven over all would be nice.

Have a nice day ~Crowley

Edit: it also displays the warning The POM for is invalid, transitive tendencies (if any) will not be available, enable debug logging for more details

Community
  • 1
  • 1
Crowley Astray
  • 172
  • 1
  • 14

1 Answers1

1

You are accessing a pom property in your script, which are not provided by the gmaven plugin. In this kind of script, you can use a project properties, which is an instance of MavenProject.

For example :

File dir = new File(project.basedir, "src/main/resources/com/cclsd/gdg/client")
Jérémie B
  • 10,611
  • 1
  • 26
  • 43