首页 > 解决方案 > Appengine Maven 插件排除 node_modules

问题描述

在我的 GoogleAppEngine 项目中,我目前安装了许多节点模块,这些节点模块现在放置在我的项目中的src/main/webapp/node_modules 位置。现在,当我尝试使用appengine-maven-plugin( mvn appengine:run) 在本地测试该项目时,创建该项目最多需要 10 分钟。node_modules我发现,将所有文件从文件夹复制到目标文件夹需要很长时间。

由于我只需要这些文件进行开发,因此我在构建项目时尝试跳过此文件夹。但我不确定在哪里配置该行为。在我的appengine-web.xml我已经从静态文件和资源文件中排除了该文件夹:

<static-files>
        <include path="/build/build/favicon.ico" />
        <include path="/build/build/node_modules/**" />
        <include path="/build/build/images/**" />
        <include path="/build/build/src/**" />
        <include path="/build/build/robots.txt" />
        <include path="/build/build/sitemap.xml" />
        <exclude path="/node_modules/**/*" />
    </static-files>
    <resource-files>
        <include path="/build/build/index.html" />
        <exclude path="/node_modules/**/*" />
    </resource-files>

我可以在哪里将该文件夹排除在被复制到的位置target/backend-1.0-snapshot

在此处输入图像描述

我正在使用带有 appengine-maven-plugin (1.3.2) 的 appengine 标准环境 (1.9.63)

这是我的 pom.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>

    <groupId>com.xxx.xxx</groupId>
    <artifactId>backend</artifactId>

    <properties>
        <endpoints.framework.version>2.0.14</endpoints.framework.version>
        <endpoints.management.version>1.0.4</endpoints.management.version>
        <endpoints.project.id>XXX PROJECT XXX</endpoints.project.id>

        <appengine.maven.plugin.version>1.3.2</appengine.maven.plugin.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
    </properties>

    <prerequisites>
        <maven>3.5.0</maven>
    </prerequisites>

    <dependencies>
        <!-- Compile/runtime dependencies -->

        <dependency>
            <groupId>com.google.endpoints</groupId>
            <artifactId>endpoints-framework</artifactId>
            <version>${endpoints.framework.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.endpoints</groupId>
            <artifactId>endpoints-management-control-appengine-all</artifactId>
            <version>1.0.7</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>1.9.63</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.5</version>
        </dependency>
    </dependencies>

    <build>
        <!-- for hot reload of the web application -->
        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
        <plugins>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.maven.plugin.version}</version>
                <configuration>
                    <deploy.project>XXX PROJECT XXX</deploy.project>
                    <deploy.version>XXX VERSION XXX</deploy.version>
                    <deploy.stopPreviousVersion>false</deploy.stopPreviousVersion>
                    <deploy.promote>false</deploy.promote>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.cloud.tools</groupId>
                <artifactId>endpoints-framework-maven-plugin</artifactId>
                <version>1.0.3</version>
                <configuration>
                    <!-- plugin configuration -->
                    <hostname>${endpoints.project.id}.appspot.com</hostname>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>versions-maven-plugin</artifactId>
                <version>2.5</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>display-dependency-updates</goal>
                            <goal>display-plugin-updates</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

标签: mavengoogle-app-enginewar

解决方案


我刚刚发现我必须将maven-war-plugin-configurationwarSourceExcludes添加到pom.xml.

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.0</version>
            <configuration>
                <warSourceExcludes>node_modules/**</warSourceExcludes>
            </configuration>
        </plugin>

这样文件夹就不会被复制到爆炸的战争文件夹中。


推荐阅读