【问题标题】:Maven <executions> and npm buildMaven <executions> 和 npm build
【发布时间】:2019-03-06 09:08:48
【问题描述】:

我有一个hybrid applicationSpring Boot and ReactJS. 在 running/building/generating WAR 时,我已将 pom.xml 设置为将 npm run build 生成的文件从 dist 文件夹复制到 template(spring) 文件夹。 但是在运行mvn clean install 时,会在npm run build 命令之前复制文件,然后生成npm run build 和WAR。这就是前端文件过时的原因。

我的pom.xml 示例是:

<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>

如何配置以便在npm run build 之后复制文件?

【问题讨论】:

    标签: java reactjs maven spring-boot maven-resources-plugin


    【解决方案1】:

    对于类似的任务,使用 gradle 而不是 maven 是有意义的。任务更加灵活。 例如:

    task buildFE(type: Exec) {
         workingDir '../../FrontEnd'
         commandLine 'buildFE.bat'
    }
    
    task CopyJava {
      copy{
        from '../OpenJDK'
        into '../../Release/OpenJDK'
      }
    }
    

    【讨论】:

    • 你能在 Maven 中给它吗?
    猜你喜欢
    • 2017-07-01
    • 2023-01-09
    • 1970-01-01
    • 1970-01-01
    • 2020-02-25
    • 2021-03-10
    • 1970-01-01
    • 2023-04-03
    • 2021-03-03
    相关资源
    最近更新 更多