2012-01-13 36 views
1

這是我們正在努力與谷歌應用程序引擎,谷歌Web工具包(平臺,gwtp)和Eclipse Maven的第一次。我們把這個和我們在這裏和那裏找到的代碼放在一起。我們不知道這是否POM文件可以改進及如何改進,因爲我們可以肯定它可以改善,特別是構建部分:我們如何讓這個maven POM.xml更專業?

<!-- POM file generated with GWT webAppCreator --> 
<modelVersion>4.0.0</modelVersion> 
<groupId>com.feeling</groupId> 
<artifactId>order2012</artifactId> 
<packaging>war</packaging> 
<version>1.0-SNAPSHOT</version> 
<name>com.feeling.order2012</name> 
<properties> 
    <!-- Convenience property to set the GWT version --> 
    <gwt.version>2.4.0</gwt.version> 
    <!-- GWT needs at least java 1.6 --> 
    <maven.compiler.source>1.6</maven.compiler.source> 
    <maven.compiler.target>1.6</maven.compiler.target> 
    <gwtp.version>0.6</gwtp.version> 
    <gae.version>1.6.0</gae.version> 
    <gae.home>${user.home}/.m2/repository/com/google/appengine/appengine-java-sdk/${gae.version}/appengine-java-sdk-${gae.version}</gae.home> 
    <persistence-api.version>1.0</persistence-api.version> 
    <jsr107cache.version>1.1</jsr107cache.version> 
    <gin.version>1.5.0</gin.version> 
    <guice.version>3.0-rc3</guice.version> 
    <aopalliance.version>1.0</aopalliance.version> 
    <gwt-maven-plugin.version>2.4.0</gwt-maven-plugin.version> 
    <maven-gae-plugin.version>0.9.2</maven-gae-plugin.version> 
    <maven-clean-plugin.version>2.3</maven-clean-plugin.version> 
    <maven-compiler-plugin.version>2.3.2</maven-compiler-plugin.version> 
    <maven-deploy-plugin.version>2.5</maven-deploy-plugin.version> 
    <maven-eclipse-plugin.version>2.8</maven-eclipse-plugin.version> 
    <maven-javadoc-plugin.version>2.7</maven-javadoc-plugin.version> 
    <maven-resources-plugin.version>2.5</maven-resources-plugin.version> 
    <slf4f.version>1.6.1</slf4f.version> 
    <maven-source-plugin.version>2.1.2</maven-source-plugin.version> 
    <maven-checkstyle-plugin.version>2.6</maven-checkstyle-plugin.version> 
    <localJarDirectory>/Users/healuser/Documents/myGAE10/lib</localJarDirectory> 
</properties> 
<dependencies>….</dependencies> 
<repositories>….</repositories> 
<build> 
    <!-- Generate compiled stuff in the folder used for developing mode --> 
    <outputDirectory>target/www/WEB-INF/classes</outputDirectory> 
    <plugins> 
     <!-- Add source folders to test classpath in order to run gwt-tests as 
     normal junit-tests <plugin> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.5</version> 
      <configuration> 
       <additionalClasspathElements> 
        <additionalClasspathElement>${project.build.sourceDirectory}</additionalClasspathElement> 
        <additionalClasspathElement>${project.build.testSourceDirectory}</additionalClasspathElement> 
       </additionalClasspathElements> 
       <useManifestOnlyJar>false</useManifestOnlyJar> 
       <forkMode>always</forkMode> 

       ! - - Folder for generated testing stuff - - 
       <systemProperties> 
        <property> 
         <name>gwt.args</name> 
         <value>-out target/www</value> 
        </property> 
       </systemProperties> 
      </configuration> 
     </plugin> --> 
     <!-- Copy static web files before executing gwt:run --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>${maven-resources-plugin.version}</version> 
      <configuration> 
       <encoding>${project.encoding}</encoding> 
      </configuration> 
      <executions> 
       <execution> 
        <phase>compile</phase> 
        <goals> 
         <goal>copy-resources</goal> 
        </goals> 
        <configuration> 
         <outputDirectory>target/www</outputDirectory> 
         <resources> 
          <resource> 
           <directory>src/main/webapp</directory> 
          </resource> 
         </resources> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
     <!-- Eclipse configuration --> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-eclipse-plugin</artifactId> 
      <version>${maven-eclipse-plugin.version}</version> 
      <configuration> 
       <downloadSources>true</downloadSources> 
       <downloadJavadocs>true</downloadJavadocs> 
       <wtpversion>2.0</wtpversion> 
       <additionalBuildcommands> 
        <buildCommand> 
         <name>com.google.gwt.eclipse.core.gwtProjectValidator</name> 
        </buildCommand> 
        <buildCommand> 
         <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 
        </buildCommand> 
       </additionalBuildcommands> 
       <additionalProjectnatures> 
        <projectnature>com.google.gwt.eclipse.core.gwtNature</projectnature> 
        <projectnature>com.google.appengine.eclipse.core.gaeNature</projectnature> 
        <projectnature>net.sf.eclipsecs.core.CheckstyleNature</projectnature> 
       </additionalProjectnatures> 
       <additionalConfig> 
        <file> 
         <name>.checkstyle</name> 
         <location>/checkstyle/eclipse-checkstyle.xml</location> 
        </file> 
       </additionalConfig> 
       <sourceIncludes> 
        <sourceInclude>*.ui.xml</sourceInclude> 
       </sourceIncludes> 
      </configuration> 
     </plugin> 
     <!-- GWT configuration --> 
     <plugin> 
      <groupId>org.codehaus.mojo</groupId> 
      <artifactId>gwt-maven-plugin</artifactId> 
      <version>${gwt-maven-plugin.version}</version> 
      <configuration> 
       <appEngineVersion>${gae.version}</appEngineVersion> 
       <appEngineHome>${gae.home}</appEngineHome> 
       <logLevel>INFO</logLevel> 
       <style> 
        $ { 
         gwt.style 
        } 
       </style> 
       <hostedWebapp>target/www</hostedWebapp> 
       <server>com.google.appengine.tools.development.gwt.AppEngineLauncher</server> 
       <copyWebapp>true</copyWebapp> 
       <runTarget>order2012.html</runTarget> 
      </configuration> 
      <executions> 
       <execution> 
        <id>gwtcompile</id> 
        <phase>prepare-package</phase> 
        <goals> 
         <goal>compile</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <!-- AppEngine configuration --> 
     <plugin> 
      <groupId>net.kindleit</groupId> 
      <artifactId>maven-gae-plugin</artifactId> 
      <version>${maven-gae-plugin.version}</version> 
      <configuration> 
       <sdkDir>${gae.home}</sdkDir> 
      </configuration> 
      <executions> 
       <execution> 
        <id>install-server-jar</id> 
        <phase>validate</phase> 
        <goals> 
         <goal>unpack</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>deploy</id> 
        <goals> 
         <goal>deploy</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-clean-plugin</artifactId> 
      <version>${maven-clean-plugin.version}</version> 
      <executions> 
       <execution> 
        <id>default-clean</id> 
        <phase>clean</phase> 
        <goals> 
         <goal>clean</goal> 
        </goals> 
       </execution> 
       <execution> 
        <id>remove-gwt-user-jar</id> 
        <phase>post-installation-test</phase> 
        <goals> 
         <goal>clean</goal> 
        </goals> 
        <configuration> 
         <excludeDefaultDirectories>true</excludeDefaultDirectories> 
         <filesets> 
          <fileset> 
           <directory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</directory> 
           <includes> 
            <include>gwt-user*.jar</include> 
           </includes> 
          </fileset> 
         </filesets> 
        </configuration> 
       </execution> 
      </executions> 
      <configuration> 
       <filesets> 
        <fileset> 
         <directory>src/main/webapp/order2012</directory> 
        </fileset> 
        <fileset> 
         <directory>src/main/webapp/WEB-INF/classes</directory> 
        </fileset> 
       </filesets> 
      </configuration> 
     </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>net.kindleit</groupId> 
            <artifactId>maven-gae-plugin</artifactId> 
            <versionRange>[0.8.1,)</versionRange> 
            <goals> 
             <goal>unpack</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <ignore></ignore> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 
</project> 

謝謝!

回答

3

自定義屬性是偉大的,但僅僅是因爲他們的存在不使用它們。使用它們來消除冗餘和/或將管理延遲到父POM。除此之外,我不認爲你的問題的範圍有什麼問題。

+0

@Tom:是的。只是擺脫所有使用過的屬性。 – 2012-01-13 07:43:07

1

你的大部分配置的是常見於任何GAE-GWT-Eclipse的Maven項目。所以,你可以創建一個項目進行標準化配置(比如gae-gwt-eclipse-base,與<packaging>pom</packaging>)包含所有這一切,那麼你的項目將來自POM繼承和放棄你所列出的所有樣板本身。實際上,除標識符和<parent>部分之外,它可能完全是空的,這將相當於聲明「這是一個標準的GAE-GWT-Eclipse項目」。

如果你只得到了一個GAE-GWT-Eclipse項目,這是很難確定什麼是共同的,什麼是具體的,但我認爲這可能是值得做的事情都一樣。

另一項改進是把配置到pluginManagement部分,而不是plugins

pluginManagement說:「如果我要使用這些插件,這是我將要配置的(除非我選擇覆蓋它)。但我不是說我使用它們。」 plugins部分表示,「我希望您在構建此項目時執行這些插件」,也可能是「並使用此配置,而不是您繼承的任何內容」。