2016-06-28 50 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

謝謝你的回答,正是我正在尋找解決我的具體問題。 –

相關問題