如何从Maven构建中排除node_modules

时间:2018-07-02 18:00:09

标签: java maven

我使用Gulp,因此在我的项目中使用了Node.js。我在node_modules内有一个src/main/resources文件夹,每次运行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>

3 个答案:

答案 0 :(得分:1)

我建议您采用一种对我来说很好的方法。

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

答案 1 :(得分:0)

代替尝试:

<exclude>node_modules/**</exclude>

然后尝试

 mvn clean process-resources -X

答案 2 :(得分:0)

我有此问题,已解决

<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>
相关问题