缩小maven插件,不会将缩小的文件添加到maven本地存储库

时间:2016-03-11 06:30:39

标签: maven maven-plugin minify

我正在使用minify maven插件,在POM中使用以下配置 -

    <plugin>
            <groupId>com.samaxes.maven</groupId>
            <artifactId>minify-maven-plugin</artifactId>
            <version>1.7.4</version>
             <configuration>
                 <verbose>true</verbose>
                <fork>true</fork>
                <executable>${JAVA_HOME_1_7}/bin/javac</executable>
                <compilerVersion>1.7</compilerVersion>
            </configuration>
         <executions>
                <execution>
                    <id>crf</id>
                    <phase>package</phase>
                    <configuration>
                      <jsSourceDir>crf/js</jsSourceDir>
                      <jsSourceIncludes>
                            <jsSourceInclude>*.js</jsSourceInclude>
                        </jsSourceIncludes>
                        <jsTargetDir>crf/js</jsTargetDir>
                       <skipMerge>true</skipMerge>
                        <jsEngine>CLOSURE</jsEngine>
                        <nosuffix>true</nosuffix>
                        <closureCreateSourceMap>false</closureCreateSourceMap>
                    </configuration>
                    <goals>
                        <goal>minify</goal>
                    </goals>
                </execution>
                 <execution>
                    <id>bundle-configuration-minify</id>
                    <configuration>
                      <jsEngine>CLOSURE</jsEngine>
                      <closureCreateSourceMap>false</closureCreateSourceMap>
                    </configuration>
                    <goals>
                        <goal>minify</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

当我构建组件时(使用 mvn clean install 说'component-war'),我看到目标(component-war)有一个缩小的JavaScript.But Maven local repo不包含缩小文件。 因此,当我打包项目时(Say'project-ear')目标不包含缩小的文件。

我在POM中也有以下配置 -

<plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1.1</version>
            <configuration>
                <packagingIncludes>WEB-INF/lib/urlrewritefilter-*.jar,WEB-INF/lib/xercesImpl-*.jar,WEB-INF/lib/io-*.jar,WEB-INF/lib/xtags-*.jar,**/*.xml,**/*.xsd,**/*.pdf,**/*.txt,**/*px,**/*dummyfile,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,**/*.jsp,**/*.jspf,**/*.xsl,**/*.html,**/*.htm,**/*.vm,**/*.tld,**/*.gif,**/readme,**/*.zip,**/*.jpg,**/*.zul,**/*.zs,**/*.eot,**/*.svg,**/*.ttf,**/*.woff,**/*.swf
                </packagingIncludes>
                <archive>
                    <manifest>
                        <addClasspath>true</addClasspath>
                        <classpathPrefix>lib/</classpathPrefix>
                    </manifest>
                </archive>
            </configuration>
        </plugin>

1 个答案:

答案 0 :(得分:0)

首先你必须删除:

&LT;执行&GT;
&LT; ID&GT; CRF&LT; / ID&GT;
<德尔>&LT;阶段&gt;&包LT; /阶段&gt;

因为对于阶段的WAR项目,maven-war-plugin优先于其他插件(http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html#Plugins) - WAR在缩小之前构建。

顺便说一下,它解释了为什么Maven有阶段准备包而且没有后包装;包中定义的所有内容都是有效的后包

这还不够,因为maven-war-plugin会覆盖缩小的文件。您必须将其配置为忽略原始JS文件,因为它们的缩小版本已由minify插件准备(Exclude source files from WAR package

<plugin>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.1.1</version>
   <configuration>
       <packagingIncludes>WEB-INF/lib/urlrewritefilter-*.jar,WEB-INF/lib/xercesImpl-*.jar,WEB-INF/lib/io-*.jar,WEB-INF/lib/xtags-*.jar,**/*.xml,**/*.xsd,**/*.pdf,**/*.txt,**/*px,**/*dummyfile,**/*.properties,**/*.class,**/*.png,**/*.css,**/*.js,**/*.jsp,**/*.jspf,**/*.xsl,**/*.html,**/*.htm,**/*.vm,**/*.tld,**/*.gif,**/readme,**/*.zip,**/*.jpg,**/*.zul,**/*.zs,**/*.eot,**/*.svg,**/*.ttf,**/*.woff,**/*.swf
      </packagingIncludes>

<!--HERE **************** -->
      <warSourceExcludes>crf/js/*.js</warSourceExcludes>
<!--HERE **************** -->

     <archive>
         <manifest>
             <addClasspath>true</addClasspath>
             <classpathPrefix>lib/</classpathPrefix>
         </manifest>
       </archive>
   </configuration>
</plugin>

BTW,您的maven war插件配置(packagingIncludes)表明您的项目很乱。您应该考虑清理它,因为我的提议扩展了配置,任何进一步不必要的扩展导致整个配置难以理解