1

I have a hybrid application : Spring Boot and ReactJS. While running/building/generating WAR, I have set the pom.xml to copy the npm run build generated files from dist folder to template(spring) folder. But while running mvn clean install, file are copied before the npm run build command and then the npm run build and WAR is generated. That'swhy the frontend files are stale.

My pom.xml example is :

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <executions>
                    <execution>
                        <id>prepare-package</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/target/classes/public</outputDirectory>
                            <outputDirectory>${basedir}/src/main/resources/templates</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/dist</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>

                    <execution>
                        <id>prepare-package2</id>
                        <phase>prepare-package</phase>
                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${basedir}/src/main/resources/static</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/dist/static</directory>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.eirslett</groupId>
                <artifactId>frontend-maven-plugin</artifactId>
                <version>1.6</version>
                <executions>
                    <execution>
                        <id>install node and npm</id>
                        <goals>
                            <goal>install-node-and-npm</goal>
                        </goals>
                        <configuration>
                            <nodeVersion>v11.10.0</nodeVersion>
                            <npmVersion>6.7.0</npmVersion>                          
                        </configuration>
                    </execution>                    
                    <execution>
                        <id>npm install</id>
                        <goals>
                            <goal>npm</goal>
                        </goals>
                        <phase>prepare-package</phase>
                        <configuration>
                            <arguments>run build</arguments>
                        </configuration>
                    </execution>
                    <!-- <execution>
                        <id>test</id>
                        <goals>
                            <goal>yarn</goal>
                        </goals>
                        <phase>test</phase>
                        <configuration>
                            <arguments>test</arguments>
                            <environmentVariables>
                                <CI>true</CI>
                            </environmentVariables>
                        </configuration>
                    </execution> -->
                </executions>
            </plugin>
        </plugins>
    </build>

How do I configure so that the files are copied after npm run build ?

SudeepShakya
  • 571
  • 3
  • 14
  • 34

1 Answers1

-3

For similar task it makes sense to use Gradle instead of Maven. The tasks are much more flexible.

For example:

task buildFE(type: Exec) {
     workingDir '../../FrontEnd'
     commandLine 'buildFE.bat'
}

task CopyJava {
  copy{
    from '../OpenJDK'
    into '../../Release/OpenJDK'
  }
}
the Tin Man
  • 158,662
  • 42
  • 215
  • 303
Daniel Prosianikov
  • 100
  • 1
  • 1
  • 10
  • can u give it in Maven ? – SudeepShakya Mar 06 '19 at 10:17
  • Please read "[answer]" and "[Explaining entirely code-based answers](https://meta.stackoverflow.com/q/392712/128421)". It helps more if you supply an explanation why this is the preferred solution and explain how it works. We want to educate, not just provide code. – the Tin Man Jun 05 '23 at 23:07