Eclipse和maven-war-plugin爆炸

Zar*_*z89 7 java eclipse war maven maven-war-plugin

我正在用Eclipse运行.

我会尽力解释.我正在开发一个"滥用"maven叠加层的项目,并且有许多模块在webapp中包含Javascript和LESS文件.

我们设法配置maven来爆炸maven-frontend-plugin将处理的目录(使用nodejs)生成最终编译的JS和CSS文件的依赖项.

当我使用纯maven时,这非常有效.但是,在Eclipse上,这并不能正常工作.主要原因是Eclipse简单地忽略了maven-war-plugin的执行配置,它会破坏依赖关系.相反,它简单地执行默认的maven-war-plugin:explode.

我需要修复它,这是获得现代前端开发环境的最大障碍(使用nodejs,npm和gulp来转换JS和LESS).

从我们的主要pom.xml中提取

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-antrun-plugin</artifactId>
    <version>1.8</version>
    <executions>
        <execution>
            <id>make-webapp-compress</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>run</goal>
            </goals>
            <configuration>
                <tasks>
                    <mkdir dir="${project.build.directory}/webapp-exploded" />
                    <mkdir dir="${project.build.directory}/webapp-compress" />
                </tasks>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <executions>
        <execution>
            <id>parent-resources-less</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>exploded</goal>
            </goals>
            <configuration>
                <failOnMissingWebXml>false</failOnMissingWebXml>
                <warSourceExcludes>**/*.ftl,**/*.vm,**/*.xml,WEB-INF/,META-INF/</warSourceExcludes>
                <warSourceIncludes>**/*.css,**/*.less,**/*.js</warSourceIncludes>
                <webappDirectory>${project.build.directory}/webapp-exploded</webappDirectory>
                <webResources>
                    <resource>
                        <directory>src/main/webapp</directory>
                    </resource>
                </webResources>
            </configuration>
        </execution>
    </executions>
</plugin>
<plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
        <lifecycleMappingMetadata>
            <pluginExecutions>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-antrun-plugin</artifactId>
                        <versionRange>[1.8,]</versionRange>
                        <goals>
                            <goal>run</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <execute />
                    </action>
                </pluginExecution>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <versionRange>[3.0.0,]</versionRange>
                        <goals>
                            <goal>exploded</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <execute />
                    </action>
                </pluginExecution>
            </pluginExecutions>
        </lifecycleMappingMetadata>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

小智 2

您可以尝试使用插件“maven-dependency-plugin”。我在项目中使用它来将依赖项复制到所需的特定输出目的地。我附上了示例配置,请根据您的要求进行更新。

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>prepare-package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/pipeline/lib</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)