【问题标题】:Appengine maven plugin exclude node_modulesAppengine Maven 插件排除 node_modules
【发布时间】:2018-05-23 11:33:06
【问题描述】:

在我的 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>

【问题讨论】:

    标签: maven google-app-engine war


    【解决方案1】:

    我刚刚发现我必须将带有warSourceExcludes 配置的maven-war-plugin 添加到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>
    

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

    【讨论】:

    • 不适合我,因为我在 webapp 中有 node_modules 目录。
    • 虽然,assets/node_modules/** 对我有用,其中 assets 是 src/main/webapp 目录中的一个文件夹。
    【解决方案2】:
    <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>3.2.0</version>
                <configuration>
                    <packagingExcludes>assets/node_modules/**</packagingExcludes> 
                </configuration>
            </plugin>
    

    assetssrc/main/webapp 目录中的一个文件夹。当您运行 mvn install 时,它会在您的 target 文件夹中创建一个 warsource 目录。虽然 node_modules 将在目标内部的源目录中可见,但是当您提取 war 文件时,这些将被排除。你可以通过提取war文件来查看。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-10
      • 2019-02-19
      • 1970-01-01
      • 1970-01-01
      • 2018-11-04
      • 2015-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多