2016-07-14 177 views
1

我会马上说:我从来没有使用过Maven/Groovy,但是最近我得到了一份写脚本的工作,该脚本自动创建一个.properties文件的枚举。没有这样的属性:pom for class:Script1

我为此使用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获得的插件管理标记下的所有内容,并且应该使脚本在生成源代码阶段执行

我真的需要有人来帮助我,我从字面上找不到有关这个错误的一件事。关于在maven中执行脚本的综合教程也很好。

有一个美好的一天〜克劳利

编辑:这也显示是无效的,传递的倾向警告的POM(如有)将无法使用,使更多细节

回答

1

您的调试日志记录访问脚本中的pom属性,这些属性不是由gmaven插件提供的。在这种脚本中,您可以使用project属性,该属性是MavenProject的一个实例。

例如:

File dir = new File(project.basedir, "src/main/resources/com/cclsd/gdg/client") 
+0

那么,这是羞辱。无论如何,谢谢你的快速回应:) –

相关问题