Eclipse和Maven-war-plugin爆炸

时间:2018-10-18 15:15:48

标签: java eclipse maven war maven-war-plugin

我正在用Eclipse对抗砖块。

我会尝试解释。我正在一个“滥用” maven覆盖并且有许多模块的web应用程序中包含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>

1 个答案:

答案 0 :(得分: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>