2012-07-15 30 views
17

私は今このプラグインをmaven-war-pluginで2時間プレイするのに苦労しており、助けを求める時間だと思っていました。私は次のように定義されたプラグインを持っている:私は本当のnosuffix =を削除した場合yuicompressor maven pluginとmaven-war-plugin

<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.0</version> 
    <executions> 
     <execution> 
      <id>compressyui</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
      <configuration> 
       <nosuffix>true</nosuffix> 
       <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
       <jswarn>false</jswarn> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 

を、私は期待通りに圧縮/縮小さ-min.jsファイルが戦争に見ることができますが、彼らにこのフラグで上書きされていますwarファイルをビルドするときは、maven-war-plugin(私は仮定しています)によって実行されます。私は本当に同じ名前を残すためにファイル名が必要です...誰かが同じファイル名を使用するために変更する必要があるもののアイデアを持っていて、最後の戦争に縮小バージョンを取得しますか?

答えて

26

OK。私はついにこのことを考え出した。 yuicompressorプラグインに<webappDirectory>を定義する必要があります。このプラグインは、maven-war-pluginの<resource>として参照できます。例では、私は<directory>${project.build.directory}/min</directory>

<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.0</version> 
    <executions> 
     <execution> 
      <id>compressyui</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
      <configuration> 
       <nosuffix>true</nosuffix> 
       <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
       <webappDirectory>${project.build.directory}/min</webappDirectory> 
       <jswarn>false</jswarn> 
      </configuration> 
     </execution> 
    </executions> 
</plugin> 
<plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <executions> 
     <execution> 
      <id>default-war</id> 
      <phase>package</phase> 
      <goals> 
       <goal>war</goal> 
      </goals> 
      <configuration> 
       <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
       <encoding>UTF-8</encoding> 
      </configuration> 
     </execution> 
    </executions> 
    <configuration> 
     <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
     <encoding>UTF-8</encoding> 
     <webResources> 
      <resource> 
       <directory>${project.build.directory}/min</directory> 
      </resource> 
     </webResources> 
    </configuration> 
</plugin> 
+2

ありがとう、ありがとう、ありがとう!私は同じ問題を抱えていて、今までは賢明な解決策を見つけることができませんでした。 YUIのプラグインボキャブラリーは非常に混乱しています。/ – Rolf

+0

ここに同じ:)とても感謝しています! –

+0

私のためには機能しません。戦争のプラグインは、戦争のソースディレクトリの内容を上書きする、Webリソース(ミニファイル)を最初にコピーします。 –

2

を使用しています下にこれは私の構成であり、それは私のMavenのWebプロジェクトで正常に動作します:

<!-- js/css compress --> 
<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.2</version> 
    <configuration> 
     <excludes> 
      <exclude>**/*-min.js</exclude> 
      <exclude>**/*.min.js</exclude> 
      <exclude>**/*-min.css</exclude> 
      <exclude>**/*.min.css</exclude> 
     </excludes> 
     <jswarn>false</jswarn> 
     <nosuffix>true</nosuffix> 
    </configuration> 
    <executions> 
     <execution> 
      <id>compress_js_css</id> 
      <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
<!-- war --> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.3</version> 
    <configuration> 
     <webResources> 
      <resource> 
       <directory>${project.build.directory}/${project.build.finalName}/resources</directory> 
       <targetPath>/resources</targetPath> 
       <filtering>false</filtering> 
      </resource> 
     </webResources> 
     <webXml>src/main/webapp/WEB-INF/web.xml</webXml> 
    </configuration> 
</plugin> 
8

ちょうどWARプラグインの 'warSourceExcludes' を設定します。

<plugin> 
    <artifactId>maven-war-plugin</artifactId> 
    <version>2.4</version> 
    <configuration> 
     <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes> 
    </configuration> 
</plugin> 
+0

働く簡単な解決策 –

+0

ありがとう。私のプロジェクトの上でうまく動作します。 – Pavlo

3

私は私のために働いていた設定を追加したいと思います:

まず、「ライフサイクルでカバーされていないプラグインの実行」文句のM2eを修正するために、私はthis postから取られた親のポンポンで、次を追加しました:私は入れ戦争のポンポンで次に

<pluginManagement> 
    <plugins> 
     <!--This plugin's configuration is used to store Eclipse 
      m2e settings only. It has no influence on the Maven build itself. --> 
     <plugin> 
      <groupId>org.eclipse.m2e</groupId> 
      <artifactId>lifecycle-mapping</artifactId> 
      <version>1.0.0</version> 
      <configuration> 
       <lifecycleMappingMetadata> 
        <pluginExecutions> 
         <pluginExecution> 
          <pluginExecutionFilter> 
           <groupId>net.alchim31.maven</groupId>        
           <artifactId>yuicompressor-maven-plugin</artifactId> 
           <versionRange>[1.0.0,)</versionRange> 
           <goals> 
            <goal>compress</goal> 
           </goals> 
          </pluginExecutionFilter> 
          <action> 
           <execute /> 
          </action> 
         </pluginExecution> 
        </pluginExecutions> 
       </lifecycleMappingMetadata> 
      </configuration> 
     </plugin> 
    </plugins> 
</pluginManagement> 

<build> 
    <plugins> 
     <plugin> 
     <groupId>net.alchim31.maven</groupId> 
     <artifactId>yuicompressor-maven-plugin</artifactId> 
     <version>1.4.0</version> 
     <executions> 
     <execution> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
      <configuration> 
       <linebreakpos>300</linebreakpos> 
       <excludes> 
       <exclude>**/*-min.js</exclude> 
       <exclude>**/*.min.js</exclude> 
       <exclude>**/*-min.css</exclude> 
       <exclude>**/*.min.css</exclude> 
       </excludes>    
       <nosuffix>true</nosuffix> 
      </configuration> 
     </execution> 
     </executions> 
     </plugin> 
     <plugin> 
      <artifactId>maven-war-plugin</artifactId> 
      <version>2.4</version> 
      <configuration> 
       <warSourceExcludes>**/*.css,**/*.js</warSourceExcludes> 
      </configuration> 
     </plugin> 
    </plugins> 
</build> 

これは、元のファイルを除外しながら、プロジェクトビルドのターゲットディレクトリに縮小されたcssファイルとjsファイルを生成します。

私はこれが誰かの時間を節約したいと思っています。

0

私が使用するアプローチは少し異なります。

まずコンパイル/パッケージの前にmvn process-resourcesを実行するようにIDEを設定しました。このようにして、戦争が組み立てられる前にファイルが作成されます。

それはあなたのオリジナルのソースファイルを交換することなく、<nosuffix>false</nosuffix>ので、ファイルが同じディレクトリに作成することができ<outputDirectory>${basedir}/src/main/resources/</outputDirectory>を設定するための非常に重要なです。

<plugin> 
    <groupId>net.alchim31.maven</groupId> 
    <artifactId>yuicompressor-maven-plugin</artifactId> 
    <version>1.3.2</version> 
    <configuration> 
     <preProcessAggregates>false</preProcessAggregates> 
     <excludes> 
      <exclude>**/*-min.js</exclude> 
      <exclude>**/*.min.js</exclude> 
      <exclude>**/*-min.css</exclude> 
      <exclude>**/*.min.css</exclude> 
     </excludes> 
     <jswarn>false</jswarn> 
     <nosuffix>false</nosuffix> <!-- VERY IMPORTANT WILL REPLACE YOUR FILES IF YOU SET nosuffix TO TRUE OR DONT SET IT AT ALL --> 
     <outputDirectory>${basedir}/src/main/resources/</outputDirectory> <!-- by default the plugin will copy the minimized version to target directory --> 
     <failOnWarning>false</failOnWarning> 
    </configuration> 

    <executions> 
     <execution> 
      <id>compress_js_css</id> 
       <phase>process-resources</phase> 
      <goals> 
       <goal>compress</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
0

ヤコブ・クルーゼは私の構成は以下の通りですので、[]%の正規表現の使用に気付いてください、あなたは* .jsファイルに対処しなければならない、と言うが、ない* .min.js通り:

\t \t \t <plugin> 
 
\t \t \t  <groupId>net.alchim31.maven</groupId> 
 
\t \t \t  <artifactId>yuicompressor-maven-plugin</artifactId> 
 
\t \t \t  <version>1.4.0</version> 
 
\t \t \t  <executions> 
 
\t \t \t   <execution> 
 
\t \t \t    <id>compressyui</id> 
 
\t \t \t    <phase>process-resources</phase> 
 
\t \t \t    <goals> 
 
\t \t \t     <goal>compress</goal> 
 
\t \t \t    </goals> 
 
\t \t \t    <configuration> 
 
\t \t \t     <nosuffix>true</nosuffix> 
 
\t \t \t     <warSourceDirectory>${basedir}/WebContent</warSourceDirectory> 
 
\t \t \t     <webappDirectory>${project.build.directory}/min</webappDirectory> 
 
\t \t \t     <jswarn>false</jswarn> \t \t 
 
\t \t \t \t   <excludes> 
 
\t \t \t \t    <exclude>**/*-min.js</exclude> 
 
\t \t \t \t    <exclude>**/*.min.js</exclude> 
 
\t \t \t \t    <exclude>**/*-min.css</exclude> 
 
\t \t \t \t    <exclude>**/*.min.css</exclude> 
 

 
\t \t \t \t    <exclude>**/jquery.window.js</exclude> 
 
\t \t \t \t    ...... 
 
\t \t \t \t    <exclude>**/compile.js</exclude> 
 
\t \t \t \t   </excludes> 
 
\t \t \t    </configuration> 
 
\t \t \t   </execution> 
 
\t \t \t  </executions> 
 
\t \t \t </plugin> 
 

 
\t \t \t <plugin> 
 
\t \t \t \t <groupId>org.apache.maven.plugins</groupId> 
 
\t \t \t \t <artifactId>maven-war-plugin</artifactId> 
 
\t \t \t \t <version>2.4</version> 
 
\t \t \t \t <configuration> 
 
\t \t \t \t \t <warSourceDirectory>WebContent</warSourceDirectory> \t \t \t \t \t 
 
\t \t \t \t \t <packagingExcludes>servlet-api*.jar,target/test-classes/*</packagingExcludes> 
 
\t \t \t \t \t <warSourceExcludes>test/**,%regex[.*(!min).js],%regex[.*(!min).css]</warSourceExcludes> 
 
\t \t \t \t 
 
\t \t \t \t \t <webResources> 
 
    \t \t \t \t \t    <resource> 
 
\t \t \t \t \t     <directory>${project.build.directory}/min</directory> 
 
\t \t \t \t \t    </resource> 
 
\t \t \t \t \t </webResources> 
 
\t \t \t \t 
 
\t \t \t \t </configuration> 
 
\t \t \t </plugin>