2016-01-20 7 views
0

Я использую Eclipse m2e, buildnumber-maven-plugin и templating-maven-plugin для создания фильтрованного java-файла с $ {buildNumber}.Eclipse m2e перезаписывает buildNumber из buildnumber-maven-plugin

Вот пример из SRC/основной/Java-шаблоны/build.java файла:

public static final String BUILDNUMBER = "${buildNumber}"; 

Если я бегу «МВН-генерирующие источники» в командной строке, мой фильтруется файл Java содержит генерируемое значение buildNumber. Если я бегу «Сформировать-источники» внутри Eclipse, используя m2e отфильтрованный файл ява кратко содержит фактические BuildNumber но быстро заменяется на исходную строку «$ {BuildNumber}»

Структура проекта

CmbProduct/pom.xml 
+-- Model/pom.xml 
+-- other modules 

Строка buildnumber-maven запускается в родительском pom.xml, потому что я использую buildNumber для установки общего значения <finalName> для всех подмодулей.

Я пробовал его с и без привязки к жизненному циклу для org.eclipse.m2e. Я не заметил никаких изменений.

У меня есть несколько задач «эхо» в обоих файлах pom.xml для целей отладки. Они показывают правильный/фактический номер сборки при запуске.

Вот сокращенный CmbProduct/pom.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<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>com.magnicomp</groupId> 
    <artifactId>Product</artifactId> 
    <!-- Do not change version EVER. This is used by MagniCompCommon and all other sub modules. --> 
    <version>1.0</version> 
    <packaging>pom</packaging> 

    <name>CMB Product</name> 

    <modules> 

     <module>Model</module> 
     <module>Common</module> 

    </modules> 

    <scm> 
     <!-- SCM used by buildnumber-maven-plugin and others --> 
     <connection>scm:git:git://sol:/vol/git/cmb.git</connection> 
    </scm> 

    <properties> 
     <!-- 
      The canonical Product Version is defined below. This value is 
      automatically propagated to Java via plugin in the Modelproject. 

      The ${buildNumber} is automatically generated on-the-fly by 
      buildnumber-maven-plugin 
     --> 
     <!-- 
      Product version defined primary version of product. 
      This is used instead of project.version because the later must 
      remain the same. 
     --> 
     <product.version.base>1.0.0</product.version.base> 
     <product.version.status>alpha1</product.version.status> 
     <product.version>${product.version.base}.${buildNumber}-${product.version.status}</product.version> 
     <!-- Version in 4 dot (digits + dot) format suitable for Windows file Version --> 
     <product.version.4dot>${product.version.base}.${buildNumber}</product.version.4dot> 

     <!-- Java version --> 
     <project.source.version>1.8</project.source.version> 
     <project.target.version>1.8</project.target.version> 

     <!-- MagniComp common --> 
     <failOnMissingWebXml>false</failOnMissingWebXml> 
     <hibernate.version>4.3.11.Final</hibernate.version> <!-- was 4.3.10.Final --> 
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
     <texo.version>0.9.0-v201501182340</texo.version> 
     <emf.version>2.11.0-v20150123-0347</emf.version> 

     <!-- Vaadin --> 
     <vaadin.version>7.5.7</vaadin.version> 
     <vaadin.plugin.version>${vaadin.version}</vaadin.plugin.version> 
     <vaadin.icons.version>1.0.1</vaadin.icons.version> 

     <!-- Product specific --> 
     <javax.servlet.version>3.1</javax.servlet.version> 
     <jersey.glassfish.version>2.21</jersey.glassfish.version> 
     <bouncy.version>1.51</bouncy.version> 
     <build.helper.maven.plugin.version>1.9.1</build.helper.maven.plugin.version> 
     <maven.shade.plugin.version>2.4.1</maven.shade.plugin.version> 
     <jna.version>4.1.0</jna.version> 
    </properties> 

    <build> 
     <finalName>${project.artifactId}-${product.version}</finalName> 

     <pluginManagement> 
      <plugins> 
       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-resources-plugin</artifactId> 
        <version>2.7</version> 
        <configuration> 
         <encoding>${project.encoding}</encoding> 
        </configuration> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-war-plugin</artifactId> 
        <version>2.6</version> 
       </plugin> 

       <plugin> 
        <groupId>org.apache.maven.plugins</groupId> 
        <artifactId>maven-jar-plugin</artifactId> 
        <version>2.6</version> 
       </plugin> 

       <plugin> 
        <artifactId>maven-assembly-plugin</artifactId> 
        <version>2.6</version> 
        <!-- We do not need a default assembly.xml 
        <configuration> 
        <descriptors> 
         <descriptor>src/main/assembly/bin.xml</descriptor> 
        </descriptors> 
        </configuration> 
        --> 
       </plugin> 

       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>exec-maven-plugin</artifactId> 
        <version>1.4.0</version> 
       </plugin> 

       <plugin> 
        <groupId>org.codehaus.mojo</groupId> 
        <artifactId>templating-maven-plugin</artifactId> 
        <version>1.0.0</version> 
       </plugin> 

       <plugin> 
        <groupId>org.eclipse.m2e</groupId> 
        <artifactId>lifecycle-mapping</artifactId> 
        <version>1.0.0</version> 
        <configuration> 
         <lifecycleMappingMetadata> 
          <pluginExecutions> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId>org.codehaus.mojo</groupId> 
             <artifactId>buildnumber-maven-plugin</artifactId> 
             <versionRange>[1.4,)</versionRange> 
             <goals> 
              <goal>create</goal> 
              <goal>create-metadata</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <execute> 
              <runOnIncremental>true</runOnIncremental> 
             </execute> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 

      </plugins> 
     </pluginManagement> 

     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <version>3.0</version> 
       <configuration> 
        <encoding>${project.encoding}</encoding> 
        <source>${project.source.version}</source> 
        <target>${project.target.version}</target> 
       </configuration> 
      </plugin> 

      <plugin> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>buildnumber-maven-plugin</artifactId> 
       <version>1.4</version> <!-- Keep in sync with pluginsManagement --> 
       <inherited>false</inherited> <!-- Run only for this level project --> 
       <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
          <goal>create</goal> <!-- Create buildNumber --> 
          <goal>create-metadata</goal> <!-- Create build.properties --> 
         </goals> 
        </execution> 
       </executions> 
       <configuration> 
        <!-- 
        Auto update incremental integer as build number. 
        Without this it uses git revision. 
        --> 
        <format>{0,number,integer}</format> 
        <items> 
         <item>buildNumber</item> 
        </items> 
        <!-- Store buildNumber in given file. Use product.version so it resets each time version changes --> 
        <buildNumberPropertiesFileLocation>${basedir}/buildinfo/buildNumber-${product.version.base}-${product.version.status}.properties</buildNumberPropertiesFileLocation> 
        <!-- WORKAROUND: Make ${buildNumber} available to child modules --> 
        <getRevisionOnlyOnce>true</getRevisionOnlyOnce> 
       </configuration> 
      </plugin>  

      <plugin> <!-- Help identify buildNumber --> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <inherited>false</inherited> <!-- Run only for this level project --> 
       <executions> 
        <execution> 
         <phase>validate</phase> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <tasks> 
           <echo>Build Number (buildNumber) is ${buildNumber}</echo> 
          </tasks> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <!-- This plugin allows us to add "src-gen" as another source dir --> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>build-helper-maven-plugin</artifactId> 
       <version>${build.helper.maven.plugin.version}</version> 
       <executions> 
        <execution> 
         <id>add-source</id> 
         <phase>generate-sources</phase> 
         <goals><goal>add-source</goal></goals> 
         <configuration> 
          <sources> 
           <source>src-gen</source> 
          </sources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.18.1</version> 
       <configuration> 
        <suiteXmlFiles> 
        <suiteXmlFile>src/test/resources/testng-unit.xml</suiteXmlFile> 
        </suiteXmlFiles> 
       </configuration> 
      </plugin> 

     </plugins> 
    </build> 
    ... snip .... 

Вот модель/pom.xml:

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

    <parent> 
     <groupId>com.magnicomp</groupId> 
     <artifactId>Product</artifactId> 
     <version>1.0</version> 
    </parent> 

    <artifactId>Model</artifactId> 
    <packaging>jar</packaging> 

    <build> 
     <resources> <!-- XXX ARE WE GOING TO USE THIS? --> 
      <resource> 
       <directory>src/main/resources</directory> 
       <includes> 
        <include>version.properties</include> 
       </includes> 
       <filtering>true</filtering> 
      </resource> 
     </resources> 

     <pluginManagement> 
      <plugins> 
       <!--This plugin's configuration is used to store Eclipse m2e settings only. It has no influence on the Maven build itself.--> 
       <!-- Override eclipse error about "create-metadata" goal from above plugin --> 
       <plugin> 
        <groupId>org.eclipse.m2e</groupId> 
        <artifactId>lifecycle-mapping</artifactId> 
        <version>1.0.0</version> 
        <configuration> 
         <lifecycleMappingMetadata> 
          <pluginExecutions> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId>org.codehaus.mojo</groupId> 
             <artifactId>templating-maven-plugin</artifactId> 
             <versionRange>[1.0.0,)</versionRange> 
             <goals> 
              <goal>filter-sources</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <execute> 
              <runOnIncremental>true</runOnIncremental> 
             </execute> 
            </action> 
           </pluginExecution> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId>org.codehaus.mojo</groupId> 
             <artifactId>buildnumber-maven-plugin</artifactId> 
             <versionRange>[1.4,)</versionRange> 
             <goals> 
              <goal>create</goal> 
              <goal>create-metadata</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <execute> 
              <runOnIncremental>true</runOnIncremental> 
             </execute> 
            </action> 
           </pluginExecution> 
           <pluginExecution> 
            <pluginExecutionFilter> 
             <groupId>org.apache.maven.plugins</groupId> 
             <artifactId>maven-antrun-plugin</artifactId> 
             <versionRange>[1.3,)</versionRange> 
             <goals> 
              <goal>run</goal> 
             </goals> 
            </pluginExecutionFilter> 
            <action> 
             <ignore></ignore> 
            </action> 
           </pluginExecution> 
          </pluginExecutions> 
         </lifecycleMappingMetadata> 
        </configuration> 
       </plugin> 
      </plugins> 
     </pluginManagement> 

     <plugins> 

      <plugin> <!-- Aid with making sure buildNumber is available --> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <executions> 
        <execution> 
         <id>echo-buildnumber-1</id> 
         <phase>validate</phase> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <tasks> 
           <echo>Build number during validate is ${buildNumber}</echo> 
          </tasks> 
         </configuration> 
        </execution> 
        <execution> 
         <id>echo-buildnumber-2</id> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>run</goal> 
         </goals> 
         <configuration> 
          <tasks> 
           <echo>Build number during generate-sources is ${buildNumber}</echo> 
          </tasks> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> <!-- Must be after buildnumber-maven-plugin due to ${buildNumber} --> 
       <groupId>org.codehaus.mojo</groupId> 
       <artifactId>templating-maven-plugin</artifactId> 
       <executions> 
        <!-- Take files in sourceDirectory and filter them to outputDirectory --> 
        <execution> 
         <id>filter-src</id> 
         <phase>generate-sources</phase> 
         <goals> 
          <goal>filter-sources</goal> 
         </goals> 
         <configuration> 
          <sourceDirectory>${basedir}/src/main/java-templates</sourceDirectory> 
          <outputDirectory>${basedir}/src-generated</outputDirectory> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

      <plugin> 
       <artifactId>maven-resources-plugin</artifactId> 
       <executions> 
        <execution> 
         <!-- Copy the build.properties created by buildnumber-maven-plugin --> 
         <id>copy-build-properties</id> 
         <phase>validate</phase> 
         <goals> <goal>copy-resources</goal> </goals> 
         <configuration> 
          <outputDirectory>${basedir}/src/main/resources</outputDirectory> 
          <resources> 
           <resource> 
            <directory>${project.parent.basedir}/target/generated/build-metadata</directory> 
            <filtering>true</filtering> 
           </resource> 
          </resources> 
         </configuration> 
        </execution> 
       </executions> 
      </plugin> 

     </plugins> 


    </build> 
    ... snip ... 

ответ

0

Ее было время, но я получил эту работу с Создать- timestamp с параметрами timestampFormat и timestampPropertyName, а также добавлением runOnConfiguration true в отображение жизненного цикла Eclipse m2e.

Номер сборки плагина:

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>buildnumber-maven-plugin</artifactId> 
    <version>1.4</version> 
    <configuration> 
     <revisionOnScmFailure>just.say.no.scm.config.in.pom</revisionOnScmFailure> 
    </configuration> 
    <executions> 
     <execution> 
      <phase>validate</phase> 
      <goals> 
       <goal>create-timestamp</goal> 
      </goals> 
      <configuration> 
       <timestampFormat>yyyyMMddHHmmssS</timestampFormat> 
       <timestampPropertyName>myBuildNumberVariable</timestampPropertyName> 
       <!-- formats the timestamp all together like 20160404141705123 and puts 
        it in the ${myBuildNumberVariable} buildProperty --> 
      </configuration> 
     </execution> 
    </executions> 
</plugin>