0

My Spring-boot project structure is below -Project - src - main - java - resources - webapp - test - frontend - src - static - config - package.json - (after "npm install") node_modules - (after "npm run build") dist

what I want to do is

  1. when a project is installed, run "npm install"

  2. when "spring-boot:run" runs, run "npm run build" and moves contents in front/dist to /main/webapp

here is my pom.xml

    <build>
    <pluginManagement>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <executions>
                <execution>
                    <id>exec-npm-install</id>
                    <phase>generate-sources</phase>
                    <configuration>
                        <executable>npm</executable>
                        <workingDirectory>./frontend</workingDirectory>
                        <arguments>
                            <argument>install</argument>
                        </arguments>
                    </configuration>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
    </pluginManagement>
</build>

I don't know how can I trigger exec-npm-install exection with Eclipse maven build, I tried generate-sources, spring-boot:run, install and compile, package but it didn't run.

and I want to know what command should I put, to move dist when "spring-boot:run"

  • You need to move that out of the pluginManagement area. In pluginManagement you can define the versions and parameters but you need to put it outside of pluginManagement. – khmarbaise Mar 12 '17 at 08:16
  • Thank you. in Eclipse, without pluginManagement, execution occurs error message, so I put them in it. now, as your comment, I removed pluginManagement and ignore execution error. it works! – burning web fuel Mar 12 '17 at 08:25
  • What kind of execution error do you get? – khmarbaise Mar 12 '17 at 09:20
  • [How to solve “Plugin execution not covered by lifecycle configuration” for Spring Data Maven Builds](http://stackoverflow.com/questions/6352208/how-to-solve-plugin-execution-not-covered-by-lifecycle-configuration-for-sprin) I referenced it. – burning web fuel Mar 12 '17 at 10:17

1 Answers1

0

Few things -

  • As pointed by @khmarbaise as well, you should move your <plugins> tree out of the <pluginManagement> and also use <version> for the plugins you are using.

  • I don't know how can I trigger exec-npm-install exection

Since the execution is tied to the generate-sources phase of the execution. If you try and execute mvn generate-sources from command line on the project directory, you shall get the execution triggered. Also executing mvn test, mvn install, mvn package should do the needful. Take a look at the Maven - Lifecycle Reference for this.

  • I want to know what command should I put, to move dist when "spring-boot:run"

If you want to copy the resources to the /webapp directory, you shall take a look at maven-resources-plugin and change its phase accordingly.

Naman
  • 27,789
  • 26
  • 218
  • 353