2016-06-28 56 views
0

我需要一个帮助。只安装一次节点而不是每次都使用Maven构建

我使用咕噜编译CSS/JS

我有我的节点包,在每次构建所造成的问题,并正在采取了大量的空间在詹金斯。我正在使用maven前端插件。

我希望节点包只能在初始时创建一次,而不要在每个maven构建中再次创建。

<id>grunt</id> 
      <build> 
       <plugins> 
        <plugin> 
         <groupId>com.github.eirslett</groupId> 
         <artifactId>frontend-maven-plugin</artifactId> 
         <version>0.0.26</version> 
         <!-- optional --> 
         <configuration> 
          <workingDirectory>DIR 
          </workingDirectory> 
          <nodeVersion>v4.2.1</nodeVersion> 
          <npmVersion>3.5.1</npmVersion> 
          <installDirectory>node</installDirectory> 
         </configuration> 
         <executions> 
          <execution> 
           <id>node and npm install</id> 
           <goals> 
            <goal>install-node-and-npm</goal> 
           </goals> 
           <configuration> 
            <arguments>install</arguments> 
            <installDirectory>node</installDirectory> 
           </configuration> 
          </execution> 
          <execution> 
           <id>npm install</id> 
           <goals> 
            <goal>npm</goal> 
           </goals> 
           <configuration> 
            <arguments>install</arguments> 
            <installDirectory>node</installDirectory> 
           </configuration> 
          </execution> 
          <execution> 
           <id>grunt build</id> 
           <goals> 
            <goal>grunt</goal> 
           </goals> 
           <configuration> 
            <arguments>build</arguments> 
           </configuration> 
          </execution> 
         </executions> 
        </plugin> 
       </plugins> 
      </build> 

我们正在用maven -P grunt进行构建。它使用每个maven构建创建和安装节点。

对于具有全局节点,我正在尝试maven -P grunt -g,但它不起作用。

在GitHub小组中,我看到有人提到我们无法使用maven前端插件,所以我尝试了maven exec插件。

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>prepare-dist-npm-runtime-dependency</id> 
     <phase>prepare-package</phase> 
     <goals> 
      <goal>exec</goal> 
     </goals> 
     <configuration> 
      <executable>node/node</executable> 
      <workingDirectory>dist</workingDirectory> 
      <arguments> 
      <argument>../node/npm/cli.js</argument> 
      <argument>install</argument> 
      <argument>--production</argument> 
      </arguments> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

但我无法看到它的工作。任何人都可以帮助如何运行maven让它为全局节点安装工作,而不是每个构建安装节点?

如果有任何其他建议让节点只安装一次而不是全局安装,将不胜感激。

+0

我认为,因为您始终使用配置文件运行maven构建,所以它会随着构建时间生成节点。我认为你应该配置你的jenkins配置项只有在脚本发生某些变化时才触发构建。默认情况下,jenkins应该运行默认的maven构建,而不是由profile来运行。 –

回答

2

您不能通过Frontend maven plugin全局安装节点或NPM。如果我们看看documentation,我们会看到该插件的全部目的是能够将Node和NPM安装在独立的环境中,仅用于构建,并且不会影响机器的其余部分。

Node/npm只会在本地“安装”到您的项目中。它不会 在全球范围内安装整个系统上(它不会干扰 任何节点/ NPM设施已经存在。)

并不是要取代节点的开发者版本 - 前端 开发商仍将上安装节点他们的笔记本电脑,但后端 开发人员可以运行一个干净的版本,甚至没有安装在他们的 计算机上的节点。

不打算为生产用途安装节点。节点使用意味着 作为前端构建的一部分,跑常见的JavaScript任务 如微小,模糊处理,压缩,封装,测试等

你可以尝试用两种不同的配置文件运行插件,一个用于安装,一个用于安装后的日常使用。在下面的例子中,你应该能够运行安装节点,NPM:

mvn clean install -PinstallNode 

然后以后每建:

mvn clean install -PnormalBuild 

还是因为normalBuild被默认设置为有效,只是:

mvn clean install 

通知安装目标并不在一天到一天的个人资料:

<profiles> 
    <profile> 
     <id>installNode</id> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>com.github.eirslett</groupId> 
        <artifactId>frontend-maven-plugin</artifactId> 
        <version>0.0.26</version> 
        <!-- optional --> 
        <configuration> 
         <workingDirectory>DIR</workingDirectory> 
         <nodeVersion>v4.2.1</nodeVersion> 
         <npmVersion>3.5.1</npmVersion> 
         <installDirectory>node</installDirectory> 
        </configuration> 
        <executions> 
         <execution> 
          <id>node and npm install</id> 
          <goals> 
           <goal>install-node-and-npm</goal> 
          </goals> 
          <configuration> 
           <arguments>install</arguments> 
           <installDirectory>node</installDirectory> 
          </configuration> 
         </execution> 
         <execution> 
          <id>npm install</id> 
          <goals> 
           <goal>npm</goal> 
          </goals> 
          <configuration> 
           <arguments>install</arguments> 
           <installDirectory>node</installDirectory> 
          </configuration> 
         </execution> 
         <execution> 
          <id>grunt build</id> 
          <goals> 
           <goal>grunt</goal> 
          </goals> 
          <configuration> 
           <arguments>build</arguments> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
    <profile> 
     <id>normalBuild</id> 
     <activation> 
      <activeByDefault>true</activeByDefault> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>com.github.eirslett</groupId> 
        <artifactId>frontend-maven-plugin</artifactId> 
        <version>0.0.26</version> 
        <!-- optional --> 
        <configuration> 
         <workingDirectory>DIR</workingDirectory> 
         <nodeVersion>v4.2.1</nodeVersion> 
         <npmVersion>3.5.1</npmVersion> 
         <installDirectory>node</installDirectory> 
        </configuration> 
        <executions> 
         <execution> 
          <id>grunt build</id> 
          <goals> 
           <goal>grunt</goal> 
          </goals> 
          <configuration> 
           <arguments>build</arguments> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 
+0

例如,在一个项目中,我有三个主要配置文件:一个完全构建,可以获得所有NPM和Bower依赖项,构建我们的客户端AMD和SASS,并构建罐;另一个只是建立客户端资产和罐子而没有获得依赖;最后只是构建Java捆绑包。在日常的Java开发中,我不需要连续运行Bower或Grunt。当我更新JS或CSS时,我可以运行将运行Bower和Grunt的配置文件。只有当我需要引入依赖关系时,才能运行完整版本,否则就不会放慢速度。 – nateyolles

+0

谢谢你的回答,正是我正在寻找解决我的具体问题。 –

相关问题