2015-01-15 48 views
4

我有一個項目使用Maven和前端maven插件(com.github.eirslett)。如何僅將maven執行目標定位到構建文件夾?

當我運行mvn install一切從插件運行的執行,以及他們創造的src/main/webapp根,其中實際前端代碼是node_modulesbower_componentsnode文件夾。

事情是,我想mvn install只執行和創建那些在build目錄中生成的包,而不是在版本化的應用程序代碼中生成,就像它在Java庫中一樣。

有沒有辦法做到這一點?

這是我pom.xml相關部分:

<build> 
    <directory>build</directory> 
    <outputDirectory>build/classes</outputDirectory> 
    <plugins> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.3</version> 
      <configuration> 
       <source>${java.version}</source> 
       <target>${java.version}</target> 
       <encoding>UTF-8</encoding> 
       <webResources> 
        <resource> 
         <filtering>true</filtering> 
         <directory>src/main/webapp</directory> 
         <includes> 
          <include>WEB-INF/weblogic.xml</include> 
         </includes> 
        </resource> 
       </webResources> 
      </configuration> 
     </plugin> 
     ... 
     <plugin> 
      <groupId>com.github.eirslett</groupId> 
      <artifactId>frontend-maven-plugin</artifactId> 
      <version>0.0.20</version> 

      <configuration> 
       <workingDirectory>src/main/webapp</workingDirectory> 
      </configuration> 

      <executions> 
       <execution> 
        <id>install node and npm</id> 
        <goals> 
         <goal>install-node-and-npm</goal> 
        </goals> 
        <configuration> 
         <nodeVersion>v0.10.34</nodeVersion> 
         <npmVersion>2.1.11</npmVersion> 
        </configuration> 
       </execution> 

       <execution> 
        <id>npm install</id> 
        <goals> 
         <goal>npm</goal> 
        </goals> 
        <configuration> 
         <arguments>install</arguments> 
        </configuration> 
       </execution> 

       <execution> 
        <id>bower install</id> 
        <goals> 
         <goal>bower</goal> 
        </goals> 
        <configuration> 
         <arguments>install</arguments> 
        </configuration> 
       </execution> 

       <execution> 
        <id>grunt build</id> 
        <goals> 
         <goal>grunt</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     ... 
    </plugins> 
</build> 
+1

你並不孤單與此有關。有一個公開的問題https://github.com/eirslett/frontend-maven-plugin/issues/18,有一個等待被接受的拉取請求。 https://github.com/cfmobile/frontend-maven-plugin/commit/52b7b28d1b8fd449f63ced3d0ed792fde22c041b – xverges

+0

Ticket is [closed](https://github.com/eirslett/frontend-maven-plugin/issues/18#ref-commit- c6a01c1)witn [配置參數](https://github.com/eirslett/frontend-maven-plugin/pull/234) – chivorotkiv

回答

5

它可以使用< installDirectory>配置參數來選擇安裝的NodeJS。

frontend-maven-plugin將安裝node_modules在它創建的地方package.json。這就是爲什麼你需要提供您的網絡資源package.json的副本到一些target/<sub-path>

然後frontend-maven-plugin可以通過這種方式來配置:

 <plugin> 
      <groupId>com.github.eirslett</groupId> 
      <artifactId>frontend-maven-plugin</artifactId> 
      <version>0.0.24</version> 

      <configuration> 
       <nodeVersion>v0.11.14</nodeVersion> 
       <npmVersion>2.13.4</npmVersion> 
       <installDirectory>target/<sub-path></installDirectory> 
       <workingDirectory>target/<sub-path></workingDirectory> 
      </configuration> 
      ... 
1

插件(前端 - Maven的插件)大多支持這一點。 「workingDirectory」參數告訴插件從哪裏開始工作(即npm install)。這需要構建文件(即package.json,gruntFile.js)位於workingDirectory中。爲了適應這一點,我添加了antrun執行,以便在構建的其餘部分之前通過(使用篩選)複製這些文件。我的grunt文件然後在適當的時候從源文件引用文件,並且任何輸出進入我的target-grunt文件夾。

這裏是我的配置:

 <plugin> 
      <groupId>com.github.eirslett</groupId> 
      <artifactId>frontend-maven-plugin</artifactId> 
      <version>0.0.20</version> 
      <configuration> 
       <workingDirectory>target-grunt</workingDirectory> 
      </configuration> 
      <executions> 
       ... 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <id>prepare-grunt</id> 
        <phase>generate-resources</phase> 
        <goals> 
         <goal>run</goal> 
        </goals> 
        <configuration> 
         <target> 
          <!-- copy, filter, rename --> 
          <filter token="moduleName" value="${moduleName}" /> 
          <filter token="project.version" value="${project.version}" /> 
          <filter token="project.artifactId" value="${project.artifactId}" /> 
          <copy file="${basedir}/target-grunt/imported-js/main/js/com/verisk/underwriting/config/grunt/npm-package-module/0.0.1/npm-package-module-0.0.1.js" tofile="${basedir}/target-grunt/package.json" filtering="true" failonerror="true" verbose="true" /> 
          <copy file="${basedir}/Gruntfile.js" tofile="${basedir}/target-grunt/Gruntfile.js" failonerror="true" verbose="true" /> 
         </target> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 
相關問題