2015-01-15 50 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> 
相关问题