如何只将maven执行目标定位到构build文件夹?

我有一个项目使用Maven和前端Maven的插件(com.github.eirslett)。

当我运行mvn install从插件运行mvn install所有的执行,并且他们在src/main/webapp根目录下创build一个node_modulesbower_componentsnode文件夹,其中实际的前端代码是。

问题是,我想只mvn install执行,并在build目录中创build包,而不是在版本化的应用程序代码中创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> 

可以使用< installDirectory >configuration参数来select安装NodeJS的位置。

frontend-maven-plugin将在其中创buildpackage.json的地方安装node_modules 。 这就是为什么你需要提供你的web资源 package.json副本到一些target/<sub-path>

那么frontend-maven-plugin可以这样configuration:

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

插件(前端 – 主插件)主要支持这一点。 “workingDirectory”参数告诉插件在哪里做的工作(即npm安装)。 这需要虽然构build文件(即package.json,gruntFile.js)在该工作目录。 为了适应这个,我添加了一个antrun执行,在构build的其余部分之前复制这些文件(通过筛选)。 我的grunt文件然后在适当的时候从源文件引用文件,并且任何输出进入我的target-grunt文件夹。

这是我的configuration:

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