2016-07-14 183 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

那麼,這是羞辱。無論如何,謝謝你的快速回應:) –

相關問題