繁体   English   中英

如何运行gulp任务和spring-boot:与maven一起运行?

[英]How to run gulp task and spring-boot:run together with maven?

我有两个项目, 框架是Spring启动应用程序,另一个是框架web ,包含html布局和web ui。

我用这个目标运行maven, clean install将框架安装到本地存储库中。 然后我想用目标clean spring-boot:run运行maven clean spring-boot:run和这个配置文件prod, dev在framework-web上启动Spring启动应用程序并在framework-web上运行gulp任务。 但它只运行gulp任务,并且不启动spring boot应用程序。

这是framework-web的pom.xml:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.rgh</groupId>
    <artifactId>framework-web</artifactId>
    <version>0.0.1-releases</version>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.2.RELEASE</version>
    </parent>

    <properties>
        <start-class>com.rgh.framework.Application</start-class>
    </properties>

    <dependencies>
        <dependency>
            <groupId>com.rgh</groupId>
            <artifactId>framework</artifactId>
            <version>0.0.1-releases</version>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>prod</id>
            <build>
                <finalName>framework-web</finalName>
                <plugins>
                    <plugin>
                        <groupId>org.springframework.boot</groupId>
                        <artifactId>spring-boot-maven-plugin</artifactId>
                    </plugin>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-compiler-plugin</artifactId>
                        <configuration>
                            <source>1.8</source>
                            <target>1.8</target>
                            <fork>true</fork>
                            <encoding>UTF-8</encoding>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
        <profile>
            <id>dev</id>
            <build>
                <finalName>framework-web</finalName>
                <plugins>
                    <plugin>
                        <groupId>com.github.eirslett</groupId>
                        <artifactId>frontend-maven-plugin</artifactId>
                        <version>1.0</version>
                        <executions>
                            <execution>
                                <id>install node and npm</id>
                                <goals>
                                    <goal>install-node-and-npm</goal>
                                </goals>
                                <configuration>
                                    <nodeVersion>v4.4.7</nodeVersion>
                                    <npmVersion>3.10.5</npmVersion>
                                </configuration>
                            </execution>
                            <execution>
                                <id>npm install</id>
                                <goals>
                                    <goal>npm</goal>
                                </goals>
                                <configuration>
                                    <arguments>install</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>bower install</id>
                                <goals>
                                    <goal>bower</goal>
                                </goals>
                                <configuration>
                                    <arguments>install --no-color</arguments>
                                </configuration>
                            </execution>
                            <execution>
                                <id>gulp build</id>
                                <goals>
                                    <goal>gulp</goal>
                                </goals>
                                <configuration>
                                    <arguments>serve</arguments>
                                </configuration>
                            </execution>
                        </executions>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

这是在eclipse中运行配置:

在此输入图像描述

你没有正确使用frontend-maven-plugin。 此插件旨在在Maven构建期间构建您的代码(transpile / compile / minify / ...)。 但是,它不适用于“服务”或“监视”等任务,这将使进程永远运行,因为这也意味着您的Maven构建将永远运行。

此外,您并不需要“服务”任务。 当您想要在单独的Web容器中运行前端代码时,“服务”任务非常有用。 但是因为你在Spring引导项目中使用Gulp,它已经拥有自己的web容器,所以你不应该创建自己的。

解决方案:

  1. 使用frontend-maven-plugin仅用于构建,而不是用于诸如serve / watch / ...之类的连续任务
  2. 如果要进行开发的serve / watch / ...任务,则应手动运行Gulp任务。 它不需要Maven构建。 由于您使用的是Eclipse,因此您可能需要查看此插件 (我自己没有使用过它)。
  3. Spring引导能够提供静态webcontent,因此如果你在Spring引导/ JavaScript项目中使用Gulp,那么你并不需要Gulp的服务任务。
  4. 如果要在单独的Web容器(而不是Spring启动项目)中运行静态内容,则应将两个项目分开,在这种情况下,您不必将Maven用于前端项目。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM