Using Maven to install Bower components with Bower installed globally

大憨熊 提交于 2019-12-23 15:06:24

问题


I have bower installed globally using NPM. In my Maven project I have a bower.json file, I am using the exec-maven-plugin to install the bower components on build, however it failed because it "cannot run the program 'bower' in directory" which makes sense because Bower is not locally installed in the project directory.

However I want to use the global version of Bower so I don't have separate Bower programs in all my projects, it works if I go to the directory in terminal and manual run 'bower install'.

Question: I want Maven to use my global Bower version to avoid me having duplicate copies of Bower in each project, how do I do this?

This is the code from my POM file that runs the plugin and execution:

 <plugin>

  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>1.3.2</version>

  <executions>

    <execution>
      <id>exec-bower-install</id>

      <phase>generate-sources</phase>
      <configuration>

        <executable>bower</executable>

        <arguments>
          <argument>install</argument>
        </arguments>

      </configuration>
      <goals>
        <goal>exec</goal>
      </goals>
    </execution>

  </executions>
</plugin>

回答1:


don't forget the workingDirectory and put your bower.json inside root folder

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>exec-maven-plugin</artifactId>
   <executions>
     <execution>
     <phase>generate-sources</phase>
     <goals>
      <goal>exec</goal>
     </goals>
     </execution>
   </executions>
   <configuration>
     <executable>bower</executable>
     <arguments>
      <argument>install</argument>
     </arguments>
     <workingDirectory>${basedir}/src/main/webapp</workingDirectory>
   </configuration>
</plugin>



回答2:


After a lot of testing, I've figured out it was a problem with my IDE, for some reason Netbeans gives me an error when it tries to build the project during the plugin execution, however when I run the Maven project straight from command line, it builds!




回答3:


Configure the executable property to point to the full directory of the bower executable, for example:

 <executable>c:/bower_directory/bower</executable>


来源:https://stackoverflow.com/questions/27822050/using-maven-to-install-bower-components-with-bower-installed-globally

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!