2012-01-29 125 views
0

我試圖通過配置文件設置條件插件執行。這個想法是有一個壓縮/無壓縮HTML文件:Maven配置文件未激活,雖然屬性的值正確

<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>net</groupId> 
    <artifactId>mavenconditionalexecution</artifactId> 
    <version>1.0.0</version> 
    <packaging>jar</packaging> 

    <name>Maven Conditional Execution</name> 

    <properties> 
     <DoCompress>true</DoCompress> 
    </properties> 

    <build> 
     <plugins> 

      <!-- Clean-up --> 
      <plugin> 
       <artifactId>maven-antrun-plugin</artifactId> 
       <version>1.6</version> 
       <executions> 
        <execution> 
         <phase>clean</phase> 
         <configuration> 
          <target> 
           <echo message="DoCompress: ${DoCompress}"/> 
           <delete includeemptydirs="true"> 
            <fileset dir="${basedir}/src/main/webapp/result/" includes="**/*"/> 
           </delete> 
          </target> 
         </configuration> 
         <goals> 
          <goal>run</goal> 
         </goals> 
        </execution> 
       </executions> 
      </plugin> 
     </plugins> 

     <resources> 
      <resource> 
      <directory>${basedir}/src/main/webapp/html</directory> 
      </resource> 
     </resources> 

    </build> 

    <profiles> 

     <profile> 
      <id>With Compression</id> 
      <activation> 
       <property> 
        <name>DoCompress</name> 
        <value>true</value> 
       </property> 
      </activation> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>com.tunyk.mvn.plugins.htmlcompressor</groupId> 
         <artifactId>htmlcompressor-maven-plugin</artifactId> 
         <version>1.2</version> 
         <executions> 
          <execution> 
           <phase>process-resources</phase> 
           <goals> 
            <goal>html</goal> 
           </goals> 
          </execution> 
         </executions> 
         <configuration> 
          <goalPrefix>htmlcompressor</goalPrefix> 
          <srcFolder>${basedir}/src/main/webapp/html</srcFolder> 
          <targetFolder>${basedir}/src/main/webapp/result/html</targetFolder> 
          <removeIntertagSpaces>true</removeIntertagSpaces> 
         </configuration> 
        </plugin> 
       </plugins> 
      </build> 
     </profile> 

     <profile> 
      <id>Without Compression</id> 
      <activation> 
       <property> 
        <name>DoCompress</name> 
        <value>false</value> 
       </property> 
      </activation> 
      <build> 
       <plugins> 
        <plugin> 
         <artifactId>maven-antrun-plugin</artifactId> 
         <version>1.6</version> 
         <executions> 
          <execution> 
           <phase>process-resources</phase> 
           <configuration> 
            <target> 
             <echo message="Copying file"/> 
             <copy todir="${basedir}/src/main/webapp/result/"> 
              <fileset dir="${basedir}/src/main/webapp/html/" > 
               <include name="angle.html"/> 
              </fileset> 
             </copy> 
            </target> 
           </configuration> 
           <goals> 
            <goal>run</goal> 
           </goals> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 

     </profile> 

    </profiles> 

    <dependencies> 
     <dependency> 
      <groupId>com.tunyk.mvn.plugins.htmlcompressor</groupId> 
      <artifactId>htmlcompressor-maven-plugin</artifactId> 
      <version>1.2</version> 
     </dependency> 
    </dependencies> 

</project> 

不要緊,我分配到DoCompress財產什麼樣的價值,相應的配置文件不被執行。我用echo檢查房產的價值。爲什麼?我究竟做錯了什麼?

是否允許使用屬性值激活pom.xml中的多個配置文件?

UPDATE

我已經創建了一個事件:我已經創建了一個事件:https://jira.codehaus.org/browse/MNG-5235

如果任何人有一個操作示例的maven配置文件激活屬性,我感興趣。此外,有沒有人知道是否可以通過屬性在同一運行中激活多個配置文件?文件不清楚。

+0

您是否嘗試過使用-X運行maven進行調試?你是否也可以描述如何從命令行運行maven? – Jeroen 2012-01-29 11:40:11

+0

避免在個人資料的ID中使用空格。嘗試用'mvn -P WithoutCompression'或'mvn -P DoCompress'來執行Maven。 – 2012-01-29 13:40:53

+0

[通過屬性激活Maven多項目配置文件]的副本(http://stackoverflow.com/a/8985198/267197),[如何通過maven屬性激活配置文件](http://stackoverflow.com/a/5676534/267197)和[MNG-5055](http://jira.codehaus.org/browse/MNG-5055)(請爲此錯誤投票)。 – 2012-01-29 18:24:46

回答

2

打開issue後,事實證明這不是一個錯誤,因爲該部分中的屬性只能是系統屬性,而不是pom.xml本身中定義的屬性。

相關問題