【问题标题】:How to exclude node_modules from maven build如何从 Maven 构建中排除 node_modules
【发布时间】:2018-12-10 23:53:57
【问题描述】:

我在我的项目中使用 Gulp 和 Node.js。我在src/main/resources 中有一个node_modules 文件夹,每次运行mvn install 时,它都会将9000 多个文件复制到目标文件夹。

我不要这个!如何排除 node_modules 文件夹?

我试过了:

<excludes>
    <exclude>**/src/main/resources/node_modules/*</exclude>
</excludes>

还有这个

<excludes>
    <exclude>node_modules/**</exclude>
</excludes>

maven-compiler-plugin 的内部配置标签。但这不起作用。

有人有解决办法吗?

这是我的 pom 的构建部分

<build>
    <plugins>
        <plugin>
            <groupId>com.atlassian.maven.plugins</groupId>
            <artifactId>maven-jira-plugin</artifactId>
            <version>${amps.version}</version>
            <extensions>true</extensions>
            <configuration>
                <productVersion>${jira.version}</productVersion>
                <productDataVersion>${jira.version}</productDataVersion>
                <applications>
                    <application>
                        <applicationKey>jira-software</applicationKey>
                        <version>${jira.software.application.version}</version>
                    </application>
                </applications>
                <!-- Uncomment to install TestKit backdoor in JIRA. -->
                <!--
                <pluginArtifacts>
                    <pluginArtifact>
                        <groupId>com.atlassian.jira.tests</groupId>
                        <artifactId>jira-testkit-plugin</artifactId>
                        <version>${testkit.version}</version>
                    </pluginArtifact>
                </pluginArtifacts>
                -->
                <pluginArtifacts>
                    <pluginArtifact>
                        <groupId>com.atlassian.labs.plugins</groupId>
                        <artifactId>quickreload</artifactId>
                        <version>1.30.5</version>
                    </pluginArtifact>
                </pluginArtifacts>
                <compressResources>false</compressResources>
                <enableQuickReload>true</enableQuickReload>
                <enableFastdev>false</enableFastdev>
                <allowGoogleTracking>false</allowGoogleTracking>
                <productDataPath>./generated-test-resources.zip
                </productDataPath>
                <!-- See here for an explanation of default instructions: -->
                <!-- https://developer.atlassian.com/docs/advanced-topics/configuration-of-instructions-in-atlassian-plugins -->
                <instructions>
                    <Atlassian-Plugin-Key>${atlassian.plugin.key}</Atlassian-Plugin-Key>

                    <!-- Add package to export here -->
                    <Export-Package>
                        de.cschulc.jira.plugin.api,
                    </Export-Package>

                    <!-- Add package import here -->
                    <Import-Package>
                        org.springframework.osgi.*;resolution:="optional",
                        org.eclipse.gemini.blueprint.*;resolution:="optional",
                        *;version="0";resolution:=optional,
                        *
                    </Import-Package>

                    <!-- Ensure plugin is spring powered -->
                    <Spring-Context>*</Spring-Context>
                </instructions>

            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.7.0</version>
            <configuration>
                <source>${maven.compiler.source}</source>
                <target>${maven.compiler.target}</target>
                <excludes>
                    <exclude>**/src/main/resources/node_modules/*</exclude>
                </excludes>
            </configuration>

        </plugin>

        <plugin>
            <groupId>com.atlassian.plugin</groupId>
            <artifactId>atlassian-spring-scanner-maven-plugin</artifactId>
            <version>${atlassian.spring.scanner.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>atlassian-spring-scanner</goal>
                    </goals>
                    <phase>process-classes</phase>
                </execution>
            </executions>
            <configuration>
                <scannedDependencies>
                    <dependency>
                        <groupId>com.atlassian.plugin</groupId>
                        <artifactId>atlassian-spring-scanner-external-jar</artifactId>
                    </dependency>
                </scannedDependencies>
                <verbose>false</verbose>
            </configuration>
        </plugin>
    </plugins>
</build>

【问题讨论】:

标签: java maven


【解决方案1】:

我有这个问题,已修复

<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-war-plugin</artifactId>
     <version>3.2.3</version>
     <configuration>
         <warSourceExcludes>node_modules/**,build/**,config/**,src/**</warSourceExcludes>
     </configuration>
</plugin>

【讨论】:

    【解决方案2】:

    我建议您采用一种适合我的不同方法。

    1. 将 node_modules 从 myproject/src/main/resources 移动到 myproject:当我想在本地安装模块时,我更自然地从项目的根文件夹运行 npm,因为它是我的工作目录,请参阅 global vs local
    2. 在你的 pom 中使用这个插件:frontend maven plugin,它与 node 和 npm 配合得很好,让你可以使用许多 javascript 自动化工具。它有一个很好的文档来使它工作。
    3. 使用 gulp 或 grunt 仅将类路径中所需的 javascript 资源从 myproject/node_modules 移动到 myproject/target/...

    【讨论】:

    • 是的,我做了这个解决方案,因为我没有心情搜索排除 node_modules 文件夹的解决方案。
    【解决方案3】:

    改为尝试:

    <exclude>node_modules/**</exclude>
    

    那就试试吧

     mvn clean process-resources -X
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-01-20
      • 2012-08-20
      • 1970-01-01
      • 2014-10-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-31
      相关资源
      最近更新 更多