使用Maven的节点版本管理策略

时间:2016-05-18 16:51:37

标签: maven jenkins nvm

我正在使用NVM来管理我的NodeJS版本。我正试图在詹金斯的工作中将它与Maven集成。在Maven运行之前执行以下脚本。我不认为有一种方法可以将NodeJS安装目录作为选项参数传递给Maven。我相信nvm use会将NodeJS安装目录导出到PATH,但我可能错了。

#!/bin/sh -e
source /mounts/dev/jenkins/.nvm/nvm.sh
nvm alias default node
nvm use --delete-prefix v4.2.0 --silent

Maven需要NodeJS的原因是yeoman-maven-plugin,默认情况下,它使用全局安装的NodeJS版本。我知道有一个适用于Jenkins的NodeJS插件,但我不认为使用它是最佳的。

我认为将NVM整合到Jenkins Maven工作中是可能的,但我可能会以错误的方式解决这个问题。有没有人对不同的NVM方法有任何想法?

1 个答案:

答案 0 :(得分:1)

我们决定放弃yeoman-maven-plugin,而不是尝试将NVM与Maven集成,而是选择frontend-maven-pluginfrontend-maven-plugin允许本地节点和NPM安装,以及Gulp和Grunt等其他构建工具。唯一需要做的改变是pom.xml。此外,Jenkins不再需要额外的脚本。

安装Node和NPM的使用示例

<plugin>
  ...
  <execution>
      <!-- optional: you don't really need execution ids,
      but it looks nice in your build log. -->
      <id>install node and npm</id>
      <goals>
          <goal>install-node-and-npm</goal>
      </goals>
      <!-- optional: default phase is "generate-resources" -->
      <phase>generate-resources</phase>
  </execution>
  <configuration>
      <nodeVersion>v0.10.18</nodeVersion>
      <npmVersion>1.3.8</npmVersion>
      <!-- optional: where to download node and npm from. Defaults to https://nodejs.org/dist/ -->
      <downloadRoot>http://myproxy.example.org/nodejs/dist/</downloadRoot>
      <!-- optional: where to install node and npm. Defaults to the working directory -->
      <installDirectory>target</installDirectory>
   </configuration>
</plugin>

有关该插件的更多信息,请访问here

相关问题